public void TestProbeResolver_CreateSutWithNoProps_ReturnsCreatedActor() { //arrange TestProbeResolver sut = CreateTestProbeResolver(); //act TestActorRef <BlackHoleActor> result = sut.CreateSut <BlackHoleActor>(ExpectedChildrenCount); //assert result.Should().BeSameAs(CreatedActorNoProps); }
public void TestProbeResolver_CreateSutWithNullProps_ThrowsArgumentNullException() { //arrange TestProbeResolver sut = CreateTestProbeResolver(); //act Action act = () => sut.CreateSut <BlackHoleActor>(null, ExpectedChildrenCount); //assert act.ShouldThrow <ArgumentNullException>(); }
public void DummyActor_ReceiveStringMessage_SendsUppercaseStringMessageToSupervisor() { //arrange TestProbeResolver resolver = TestProbeResolverSettings .Empty .CreateResolver(this); TestActorRef <DummmyActor> sut = resolver.CreateSut <DummmyActor>(0); //act sut.Tell("hello world"); //assert resolver.Supervisor.ExpectMsg("HELLO WORLD"); }
public void ParentActor_Constructor_SendsChildCorrectMessage() { //arrange TestProbeResolver resolver = TestProbeResolverSettings .Empty .CreateResolver(this); //act TestActorRef <ParentActor> sut = resolver.CreateSut <ParentActor>(2); //assert resolver .ResolvedTestProbe(sut, "child-actor-1") .ExpectMsg("hello actor 1"); }
public void ParentActor_Constructor_CreatesChildWithCorrectTypeAndName() { //arrange TestProbeResolver resolver = TestProbeResolverSettings .Empty .CreateResolver(this); //act TestActorRef <ParentActor> sut = resolver.CreateSut <ParentActor>(2); //assert resolver .ResolvedType(sut, "child-actor-1") .Should().Be <ChildActor>(); }
public void TestProbeResolver_TimesOutWhenChildrenCountIsTooHigh() { //arrange const int childCount = 5; Type childType = typeof(ReplyChildActor1); TestProbeResolver sut = TestProbeResolverSettings .Empty .CreateResolver(this); //act Action act = () => sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childType, childCount)), childCount + 1); //assert act.ShouldThrow <TimeoutException>(); }
public void TestProbeResolver_ThrownsWhenChildHasNotBeenResolved() { //arrange TestProbeResolver sut = TestProbeResolverSettings .Empty .CreateResolver(this); //act TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor()), 0); sut.TellMessage(actor, new CreateChild(Guid.NewGuid().ToString(), typeof(EchoActor)), 1); Action act = () => sut.ResolvedTestProbe(actor, Guid.NewGuid().ToString()); //assert act.ShouldThrow <ActorNotFoundException>(); }
public void TestProbeResolver_SupervisorTestProbeReceivesMessagesSentToParent() { //arrange const int initialChildCount = 0; Guid message = Guid.NewGuid(); TestProbeResolver sut = TestProbeResolverSettings .Empty .CreateResolver(this); TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor()), initialChildCount); //act actor.Tell(new TellParent(message)); //assert sut.Supervisor.ExpectMsg(message); }
public void TestProbeResolver_TimesoutWhenWaitingForChildrenWithAnExpectedChildCountThatIsTooHigh() { //arrange const int initialChildCount = 2; const int moreChildCount = 5; Type childType = typeof(ReplyChildActor1); TestProbeResolver sut = TestProbeResolverSettings .Empty .CreateResolver(this); TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childType, initialChildCount)), initialChildCount); //act Action act = () => sut.TellMessage(actor, new CreateChildren(childType, moreChildCount), moreChildCount + 1); //assert act.ShouldThrow <TimeoutException>(); }
public void TestProbeResolver_CreatesChildrenWithNoReplies() { //arrange const int childCount = 5; Type childType = typeof(ReplyChildActor1); TestProbeResolver sut = TestProbeResolverSettings .Empty .RegisterHandler <ReplyChildActor2, Guid>(guid => Guid.Empty) .CreateResolver(this); //act TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childType, childCount)), childCount); //assert actor.Tell(new TellAllChildren(Guid.NewGuid())); ExpectNoMsg(); }
public void TestProbeResolver_ResolvedTypesAreStored() { //arrange Type childType = typeof(BlackHoleActor); string childName = Guid.NewGuid().ToString(); TestProbeResolver sut = TestProbeResolverSettings .Empty .CreateResolver(this); //act TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor()), 0); sut.TellMessage(actor, new CreateChild(childName, childType), 1); //assert sut.ResolvedType(actor, childName).Should().Be(childType); }
public void ParentActor_ReceiveSaveMessage_StoresModifiedSaveMessageFromChildInRepo() { //arrange TestProbeResolver resolver = TestProbeResolverSettings .Empty .RegisterHandler <ChildActor, ParentActor.Save>(s => new ChildActor.ModifiedSave(s.Value.ToUpper())) .CreateResolver(this); Mock <IRepository> repoMock = new Mock <IRepository>(); Props props = Props.Create(() => new ParentActor(repoMock.Object)); TestActorRef <ParentActor> sut = resolver.CreateSut <ParentActor>(props, 1); //act sut.Tell(new ParentActor.Save("hello world")); //assert AwaitAssert(() => repoMock.Verify(repo => repo.Save("HELLO WORLD"), Times.Once)); }
public void TestProbeResolver_WaitsForChildrenCreatedWhenProcessingMessages() { //arrange const int initialChildCount = 2; const int additionalChildCount = 5; Type childType = typeof(ReplyChildActor1); Guid message = Guid.NewGuid(); TestProbeResolver sut = TestProbeResolverSettings .Empty .RegisterHandler <ReplyChildActor1, Guid>(guid => guid) .CreateResolver(this); TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childType, initialChildCount)), initialChildCount); //act sut.TellMessage(actor, new CreateChildren(childType, additionalChildCount), additionalChildCount); //assert actor.Tell(new TellAllChildren(message)); ExpectMsgAllOf(Enumerable .Repeat(message, initialChildCount + additionalChildCount) .ToArray()); }
public void TestProbeResolver_UsesLatestHandler() { //arrange const int childCount = 5; Type childType = typeof(ReplyChildActor1); Guid message = Guid.NewGuid(); int replyCount = 0; TestProbeResolver sut = TestProbeResolverSettings .Empty .RegisterHandler <ReplyChildActor1, Guid>(guid => (default(Guid), default(int))) .RegisterHandler <ReplyChildActor1, Guid>(guid => (guid, ++replyCount)) .CreateResolver(this); //act TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childType, childCount)), childCount); //assert actor.Tell(new TellAllChildren(message)); ExpectMsgAllOf(Enumerable .Range(1, childCount) .Select(i => (message, i)) .ToArray() ); }