Пример #1
0
        public void ChildWaiter_Waited_Wait_BlockThreadUntilChildrenAreResolved()
        {
            this.WithinTimeout(() =>
            {
                //arrange
                ChildWaiter sut = CreateChildWaiter();
                sut.Start(this, 0);
                sut.Wait();
                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);
            });
        }
Пример #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());
            });
        }
Пример #3
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();
            });
        }
Пример #4
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);
        }
Пример #5
0
        public void ChildWaiter_StartedWithNoExpectedChildren_Wait_DoesNotBlockThread()
        {
            //arrange
            ChildWaiter sut = CreateChildWaiter();

            sut.Start(this, 0);

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

            //assert
            this.WithinTimeout(act);
        }
Пример #6
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();
        }
Пример #7
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);
        }
        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();
            });
        }
Пример #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();
            });
        }
Пример #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>();
            });
        }
        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();
            });
        }
Пример #12
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>();
            });
        }
Пример #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>();
            });
        }