Exemple #1
0
        public void ConcreteResolver_TellMessageNoSenderWithNullRecipientAndMessageAndSender_ThrowsArgumentNullException()
        {
            //arrange
            ConcreteResolver sut = CreateConcreteResolver(ImmutableDictionary <Type, Func <ActorBase> > .Empty);

            //act
            Action act = () => sut.TellMessage <object>(null, null, null, ExpectedChildrenCount);

            //assert
            act.ShouldThrow <ArgumentNullException>();
        }
        public void ConcreteResolver_CreateSutWithNoProps_ReturnsCreatedActor()
        {
            //arrange
            ConcreteResolver sut = CreateConcreteResolver(ImmutableDictionary <Type, Func <ActorBase> > .Empty);

            //act
            TestActorRef <BlackHoleActor> result = sut.CreateSut <BlackHoleActor>(ExpectedChildrenCount);

            //assert
            result.Should().BeSameAs(CreatedActorNoProps);
        }
        public void ConcreteResolver_CreateSutWithNullProps_ThrowsArgumentNullException()
        {
            //arrange
            ConcreteResolver sut = CreateConcreteResolver(ImmutableDictionary <Type, Func <ActorBase> > .Empty);

            //act
            Action act = () => sut.CreateSut <BlackHoleActor>(null, ExpectedChildrenCount);

            //assert
            act.ShouldThrow <ArgumentNullException>();
        }
Exemple #4
0
        public void ConcreteResolver_TellMessageSender_TellsChild()
        {
            //arrange
            ConcreteResolver sut = CreateConcreteResolver(ImmutableDictionary <Type, Func <ActorBase> > .Empty);

            //act
            sut.TellMessage(Recipient, Message, Sender, ExpectedChildrenCount);

            //assert
            ChildTellerMock.Verify(
                teller => teller.TellMessage(ChildWaiterMock.Object, this, Recipient, Message, ExpectedChildrenCount, Sender),
                Times.Once);
        }
        public void ConcreteResolver_TimesOutWhenChildrenCountIsTooHigh()
        {
            //arrange
            const int        childCount = 5;
            ConcreteResolver sut        = ConcreteResolverSettings
                                          .Empty
                                          .Register <EmptyChildActor>()
                                          .CreateResolver(this);

            //act
            Action act = () => sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childCount)), childCount + 1);

            //assert
            act.ShouldThrow <TimeoutException>();
        }
        public void ConcreteResolver_TimesOutWithChildThatIsNotRegistered()
        {
            //arrange
            const int        childCount = 5;
            ConcreteResolver sut        = ConcreteResolverSettings
                                          .Empty
                                          .Register <EmptyChildActor>()
                                          .CreateResolver(this);

            //act
            Action act = () => sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childCount)), childCount);

            //assert
            act.ShouldThrow <TimeoutException>(); //Invalid operation exception is swallowed by Akka
        }
        public void ConcreteResolver_CreatesChildrenWithoutDependancies()
        {
            //arrange
            const int        childCount = 5;
            ConcreteResolver sut        = ConcreteResolverSettings
                                          .Empty
                                          .Register <EmptyChildActor>()
                                          .Register <ChildActor>()
                                          .CreateResolver(this);

            //act
            TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childCount)), childCount);

            //assert
            actor.Tell(new object());
            ExpectMsgAllOf(Enumerable.Repeat(ChildActor.Token, childCount).ToArray());
        }
Exemple #8
0
        public void ConcreteResolver_TimesoutWhenWaitingForChildrenWithAnExpectedChildCountThatIsTooHigh()
        {
            //arrange
            const int        initialChildCount = 2;
            const int        moreChildCount    = 5;
            ConcreteResolver sut = ConcreteResolverSettings
                                   .Empty
                                   .Register <EmptyChildActor>()
                                   .Register <ChildActor>()
                                   .CreateResolver(this);
            TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(initialChildCount)), initialChildCount);

            //act
            Action act = () => sut.TellMessage(actor, moreChildCount, moreChildCount + 1);

            //assert
            act.ShouldThrow <TimeoutException>();
        }
Exemple #9
0
        public void ConcreteResolver_WaitsForChildrenCreatedWhenProcessingMessages()
        {
            //arrange
            const int        initialChildCount = 2;
            const int        moreChildCount    = 5;
            ConcreteResolver sut = ConcreteResolverSettings
                                   .Empty
                                   .Register <EmptyChildActor>()
                                   .Register <ChildActor>()
                                   .CreateResolver(this);
            TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(initialChildCount)), initialChildCount);

            //act
            sut.TellMessage(actor, moreChildCount, moreChildCount);

            //assert
            actor.Tell(new object());
            ExpectMsgAllOf(Enumerable.Repeat(ChildActor.Token, initialChildCount + moreChildCount).ToArray());
        }
        public void ConcreteResolver_CreatesChildrenWithDependancies()
        {
            //arrange
            const int          childCount             = 5;
            Mock <IDependancy> dependancyMock         = new Mock <IDependancy>();
            IDependancy        dependancyMockInstance = dependancyMock.Object;
            ConcreteResolver   sut = ConcreteResolverSettings
                                     .Empty
                                     .Register <EmptyChildActor>()
                                     .Register(() => new ChildActor(dependancyMockInstance))
                                     .CreateResolver(this);

            //act
            TestActorRef <ParentActor> actor = sut.CreateSut <ParentActor>(Props.Create(() => new ParentActor(childCount)), childCount);

            //assert
            actor.Tell(new object());
            AwaitAssert(() =>
                        dependancyMock.Verify(
                            dependancy => dependancy.SetResut(ChildActor.Token),
                            Times.Exactly(childCount)));
        }