-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExample7_Delayer.cs
53 lines (47 loc) · 1.6 KB
/
Example7_Delayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.TestKit.Xunit2;
using Moq;
using Xunit;
namespace ConnelHooley.AkkaTestingHelpers.MediumTests.UnitTestFrameworkTests.Examples
{
public class Example7_Delayer : TestKit
{
public Example7_Delayer() : base(ConfigurationFactory
.ParseString("akka.test.timefactor = 2")
.WithFallback(AkkaConfig.Config)) { }
public interface IRepository
{
void Save(string value);
}
public class SutActor : ReceiveActor
{
public SutActor(IRepository repository)
{
ReceiveAsync<string>(async message => {
await Task.Delay(1800).ConfigureAwait(false);
repository.Save(message);
});
}
}
[Fact]
public void ParentActor_ReceiveStringMessage_CallsRepoAfterDuration()
{
//arrange
Mock<IRepository> repoMock = new Mock<IRepository>();
string message = Guid.NewGuid().ToString();
UnitTestFramework<SutActor> framework = UnitTestFrameworkSettings
.Empty
.CreateFramework<SutActor>(this, Props.Create(() => new SutActor(repoMock.Object)));
//act
framework.Sut.Tell(message);
//assert
framework.Delay(TimeSpan.FromSeconds(1)); // 1 second is multipled by timefactor to make 2 seconds
repoMock.Verify(
repo => repo.Save(message),
Times.Once);
}
}
}