Exemplo n.º 1
0
        public void ChildWaiter_Started_Wait_BlockThreadUntilChildrenAreResolved()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut           = CreateChildWaiter();
                int expectedChildrenCount = TestUtils.RandomBetween(1, 5);
                int resolvedChildrenCount = 0;
                sut.Start(this, expectedChildrenCount);
                Task.Run(() =>
                {
                    this.Sleep(50);
                    Parallel.For(0, expectedChildrenCount, i =>
                    {
                        resolvedChildrenCount++;
                        sut.ResolvedChild();
                    });
                });

                //act
                sut.Wait();

                //assert
                resolvedChildrenCount.Should().Be(expectedChildrenCount);
            });
        }
Exemplo n.º 2
0
        public void ChildWaiter_Started_Start_ShouldUnblockThreadWhenFirstStartsChildrenAreResolved()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut           = CreateChildWaiter();
                int expectedChildrenCount = TestUtils.RandomBetween(0, 5);
                bool isSecondStartRan     = false;
                sut.Start(this, expectedChildrenCount);

                Task.Run(() =>
                {
                    //act
                    sut.Start(this, TestUtils.RandomBetween(0, 5));
                    isSecondStartRan = true;
                });
                this.Sleep(50); //ensures second start is called before continuing

                //assert
                Task.Run(() =>
                {
                    Parallel.For(0, expectedChildrenCount, i =>
                    {
                        sut.ResolvedChild();
                    });
                });
                sut.Wait();
                AwaitAssert(() => isSecondStartRan.Should().BeTrue());
            });
        }
Exemplo n.º 3
0
        public void ChildWaiter_NotStarted_ResolveChild_DoesNotThrowAnyExceptions()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            //act
            Action act = () => sut.ResolvedChild();

            //assert
            act.ShouldNotThrow();
        }
Exemplo n.º 4
0
        public void ChildWaiter_Started_ResolveChild_DoesNotThrowAnyExceptions()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            sut.Start(this, TestUtils.Create <int>());

            //act
            Action act = () => sut.ResolvedChild();

            //assert
            act.ShouldNotThrow();
        }
Exemplo n.º 5
0
        public void ChildWaiter_StartedWithNoExpectedChildren_Wait_DoesNotBlockThread()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            sut.Start(this, 0);

            //act
            Action act = () => sut.Wait();

            //assert
            Within(TestKitSettings.DefaultTimeout, act);
        }
Exemplo n.º 6
0
        public void ChildWaiter_StartedWithNoExpectedChildren_Wait_DoesNotBlockThread()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            sut.Start(this, 0);

            //act
            Action act = () => sut.Wait();

            //assert
            this.WithinTimeout(act);
        }
Exemplo n.º 7
0
        public void ChildWaiter_StartedWithNegativeExpectedChildren_Wait_DoesNotBlockThread()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            sut.Start(this, TestUtils.RandomBetween(int.MinValue, -1));

            //act
            Action act = () => sut.Wait();

            //assert
            this.WithinTimeout(act);
        }
Exemplo n.º 8
0
        public void ChildWaiter_NotStarted_Wait_DoesNotThrowAnyExceptions()
        {
            Within(TimeSpan.FromSeconds(2), () =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();

                //act
                Action act = () => sut.Wait();

                //assert
                act.ShouldNotThrow();
            });
        }
Exemplo n.º 9
0
        public void ChildWaiter_Start_DoesNotThrowAnyExceptions()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();

                //act
                Action act = () => sut.Start(this, TestUtils.Create <int>());

                //assert
                act.ShouldNotThrow();
            });
        }
Exemplo n.º 10
0
        public void ChildWaiter_StartWithNullTestKitBase_ThrowsArgumentNullException()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();

                //act
                Action act = () => sut.Start(null, TestUtils.Create <int>());

                //assert
                act.ShouldThrow <ArgumentNullException>();
            });
        }
Exemplo n.º 11
0
        public void ChildWaiter_NotStarted_Wait_DoesNotThrowAnyExceptions()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();

                //act
                Action act = () => sut.Wait();

                //assert
                act.ShouldNotThrow();
            });
        }
        public void ChildWaiter_Start_DoesNotThrowAnyExceptions()
        {
            Within(TimeSpan.FromSeconds(2), () =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();

                //act
                Action act = () => sut.Start(this, TestUtils.Create <int>());

                //assert
                act.ShouldNotThrow();
            });
        }
Exemplo n.º 13
0
        public void ChildWaiter_Started_Wait_ThrowsTimeoutExceptionWhenChildrenAreNotResolved()
        {
            Within(TimeSpan.FromSeconds(2), () =>
            {
                //arrange
                ChildWaiter sut           = CreateChildWaiter();
                int expectedChildrenCount = TestUtils.RandomBetween(2, 5);
                sut.Start(this, expectedChildrenCount);
                Task.Run(() =>
                {
                    this.Sleep(new TimeSpan(TestKitSettings.DefaultTimeout.Ticks / 2));
                    Parallel.For(0, expectedChildrenCount - 1, i => sut.ResolvedChild());
                });

                //act
                Action act = () => sut.Wait();

                //assert
                act.ShouldThrow <TimeoutException>();
            });
        }
Exemplo n.º 14
0
        public void ChildWaiter_Started_Wait_ThrowsTimeoutExceptionWhenNotAllChildrenAreResolved()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut           = CreateChildWaiter();
                int expectedChildrenCount = TestUtils.RandomBetween(2, 5);
                sut.Start(this, expectedChildrenCount);
                Task.Run(() =>
                {
                    this.Sleep(50);
                    Parallel.For(0, expectedChildrenCount - 1, i => sut.ResolvedChild());
                });

                //act
                Action act = () => sut.Wait();

                //assert
                act.ShouldThrow <TimeoutException>();
            });
        }
Exemplo n.º 15
0
        public void ChildWaiter_Started_Start_ShouldBlockThread()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut       = CreateChildWaiter();
                bool isSecondStartRan = false;
                sut.Start(this, TestUtils.RandomBetween(0, 5));

                Task.Run(() =>
                {
                    //act
                    sut.Start(this, TestUtils.RandomBetween(0, 5));
                    isSecondStartRan = true;
                });

                //assert
                this.Sleep(this.GetTimeoutHalved());
                isSecondStartRan.Should().BeFalse();
            });
        }
        public void ChildWaiter_Started_Start_ShouldBlockThread()
        {
            Within(TimeSpan.FromSeconds(2), () =>
            {
                //arrange
                ChildWaiter sut           = CreateChildWaiter();
                int expectedChildrenCount = TestUtils.RandomBetween(0, 5);
                bool isSecondStartRan     = false;
                sut.Start(this, expectedChildrenCount);

                Task.Run(() =>
                {
                    //act
                    sut.Start(this, TestUtils.RandomBetween(0, 5));
                    isSecondStartRan = true;
                });

                //assert
                this.Sleep(TestKitSettings.DefaultTimeout);
                isSecondStartRan.Should().BeFalse();
            });
        }
Exemplo n.º 17
0
        public TestBase() : base(AkkaConfig.Config)
        {
            // Create values passed into sut
            TestKitPassedIntoSut  = this;
            HandlersPassedIntoSut = ImmutableDictionary <(Type, Type), Func <object, object> >
                                    .Empty
                                    .Add((typeof(DummyActor1), typeof(Message1)), message1 => new Reply1())
                                    .Add((typeof(DummyActor1), typeof(Message2)), message1 => new Reply2())
                                    .Add((typeof(DummyActor2), typeof(Message1)), message1 => new Reply1());

            PropsPassedIntoSut      = Props.Create <DummyActor1>();
            NumberOfChildrenIntoSut = TestUtils.Create <int>();

            // Create shims
            _shimContext = ShimsContext.Create();

            // Set up shims
            ShimSutCreator.Constructor = @this =>
            {
                SutCreatorConstructorCount++;
                ConstructedSutCreator = @this;
            };

            ShimTellChildWaiter.Constructor = @this =>
            {
                TellChildWaiterConstructorCount++;
                ConstructedTellChildWaiter = @this;
            };

            ShimChildWaiter.Constructor = @this =>
            {
                ChildWaiterConstructorCount++;
                ConstructedChildWaiter = @this;
            };

            ShimDependencyResolverAdder.Constructor = @this =>
            {
                DependencyResolverAdderConstructorCount++;
                ConstructedDependencyResolverAdder = @this;
            };

            ShimTestProbeDependencyResolverAdder.Constructor = @this =>
            {
                TestProbeDependencyResolverAdderConstructorCount++;
                ConstructedTestProbeDependencyResolverAdder = @this;
            };

            ShimTestProbeCreator.Constructor = @this =>
            {
                TestProbeCreatorConstructorCount++;
                ConstructedTestProbeCreator = @this;
            };

            ShimResolvedTestProbeStore.Constructor = @this =>
            {
                ResolvedTestProbeStoreConstructorCount++;
                ConstructedResolvedTestProbeStore = @this;
            };

            ShimTestProbeActorCreator.Constructor = @this =>
            {
                TestProbeActorCreatorConstructorCount++;
                ConstructedTestProbeActorCreator = @this;
            };

            ShimTestProbeHandlersMapper.Constructor = @this =>
            {
                TestProbeHandlersMapperConstructorCount++;
                ConstructedTestProbeHandlersMapper = @this;
            };

            ShimSutSupervisorStrategyGetter.Constructor = @this =>
            {
                SutSupervisorStrategyGetterConstructorCount++;
                ConstructedSutSupervisorStrategyGetter = @this;
            };

            ShimUnitTestFramework <DummyActor1> .ConstructorISutCreatorITellChildWaiterIChildWaiterIDependencyResolverAdderITestProbeDependencyResolverAdderITestProbeCreatorIResolvedTestProbeStoreITestProbeActorCreatorITestProbeHandlersMapperISutSupervisorStrategyGetterImmutableDictionaryOfValueTupleOfTy =
                (@this, sutCreator, tellChildWaiter, childWaiter, dependencyResolverAdder, testProbeDependencyResolverAdder, testProbeCreator, resolvedTestProbeStore, testProbeActorCreator, testProbeHandlersMapper, sutSupervisorStrategyGetter, handlers, testKit, props, numberOfChildren) =>
            {
                UnitTestFrameworkConstructorCount++;
                ConstructedUnitTestFramework                   = @this;
                SutCreatorPassedIntoShim                       = sutCreator;
                TellChildWaiterPassedIntoShim                  = tellChildWaiter;
                ChildWaiterPassedIntoShim                      = childWaiter;
                DependencyResolverAdderPassedIntoShim          = dependencyResolverAdder;
                TestProbeDependencyResolverAdderPassedIntoShim = testProbeDependencyResolverAdder;
                TestProbeCreatorPassedIntoShim                 = testProbeCreator;
                ResolvedTestProbeStorePassedIntoShim           = resolvedTestProbeStore;
                TestProbeActorCreatorPassedIntoShim            = testProbeActorCreator;
                TestProbeHandlersMapperPassedIntoShim          = testProbeHandlersMapper;
                SutSupervisorStrategyGetterIntoShim            = sutSupervisorStrategyGetter;
                HandlersPassedIntoShim   = handlers;
                TestKitPassedIntoShim    = testKit;
                PropsPassedIntoShim      = props;
                NumberOfChildrenIntoShim = numberOfChildren;
            };
        }