예제 #1
0
        public void duplicated_runs_dont_accidentally_accumulate_afterEach_calls()
        {
            AFixture fixture = new AFixture();

            var fakeGlobalSetupManager = new FakeGlobalSetupManager();

            TestPosition testPosition = TestPosition.At(1, 3, 2);

            var traceMessages = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = testPosition
            }, traceMessages);

            fixture.ResetObservations();

            var traceMessages1 = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = testPosition
            }, traceMessages1);

            expect_observation_matches(fixture.Observations, 1, 2, 3, 4, 5, 6, -2, -3, -4, 7, 8);
        }
예제 #2
0
        public void test_IsAncestorOf()
        {
            var position = TestPosition.At(1, 2, 3);

            expect(() => position.IsAncestorOf(TestPosition.At(1, 2, 3, 4)));
            expect(() => position.IsAncestorOf(TestPosition.At(1, 2, 3, 4, 0, 1, 2)));
            expect(() => !position.IsAncestorOf(TestPosition.At(1, 2)));
            expect(() => !position.IsAncestorOf(TestPosition.At(3, 2, 1, 4)));
        }
예제 #3
0
        public void FinishCleanup()
        {
            _setupResultAccumulator.UnwindAll(e =>
            {
                ReportError(TestPosition.At(0), e);
            });

            _traceTracker.UnwindAll();

            _currentTestPosition = TestPosition.At();
        }
 public void can_run_tests_c()
 {
     expect_test_to_observe(TestPosition.At(4), new List <string>()
     {
         "1",
         "a1",
         "a2",
         "a3",
         "2",
         "5",
         "c"
     });
 }
예제 #5
0
 public void RunFixture(SpecificationFixture fixture)
 {
     fixture.CurrentPosition = TestPosition.At(0);
     fixture.Visitor         = this;
     try
     {
         fixture.Run();
     }
     catch (Exception e)
     {
         ReportError(TestPosition.At(0), e);
     }
 }
예제 #6
0
        public void can_be_ran()
        {
            AFixture fixture = new AFixture();

            var fakeGlobalSetupManager = new FakeGlobalSetupManager();

            var traceMessages = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = TestPosition.At(1, 3, 2)
            }, traceMessages);

            expect_observation_matches(fixture.Observations, 1, 2, 3, 4, 5, 6, 7, -2, -3, -4, 8);
        }
예제 #7
0
        public void visitTest(TestElement element, TestPosition position)
        {
            CheckNotAlreadyPastDiscovery(element);

            _currentTestPosition = position;

            while (position.Equals(_targetPosition))
            {
                _runningLock.PassAndWaitForTurn();
            }

            _setupResultAccumulator.UnwindForPosition(_targetPosition, e => {
                ReportError(TestPosition.At(0), e);
            });

            _traceTracker.UnwindToPosition(_targetPosition);
        }
예제 #8
0
        public void can_be_used_with_dictionaries()
        {
            var position1 = TestPosition.At(1, 2, 3);
            var position2 = TestPosition.At(4, 5, 6);
            var position3 = TestPosition.At(7, 8, 9);

            expect(() => position1.Equals(TestPosition.At(1, 2, 3)));

            Dictionary <TestPosition, int> dictionary = new Dictionary <TestPosition, int>();

            dictionary[position1] = 1;
            dictionary[position2] = 2;
            dictionary[position3] = 3;

            expect(() => dictionary[TestPosition.At(1, 2, 3)] == 1);
            expect(() => dictionary[TestPosition.At(4, 5, 6)] == 2);
            expect(() => dictionary[TestPosition.At(7, 8, 9)] == 3);
        }
 public void can_run_tests_b3()
 {
     expect_test_to_observe(TestPosition.At(3, 2), new List <string>()
     {
         "1",
         "a1",
         "a2",
         "a3",
         "2",
         "3",
         "b1",
         "b2",
         "b3",
         "bi3",
         "4",
         "5"
     });
 }
        public void can_load_tests()
        {
            Type type = typeof(has_test_in_loop);

            var nativeTestFactory = new TrackingTestFactory();

            using (var globalSetupOwner = new GlobalSetupOwner())
            {
                SpecificationBuilder.BuildTestFixture(type, nativeTestFactory, globalSetupOwner);

                expect(() => nativeTestFactory.Results[TestPosition.At(0)] == "a1");
                expect(() => nativeTestFactory.Results[TestPosition.At(1)] == "a2");
                expect(() => nativeTestFactory.Results[TestPosition.At(2)] == "a3");
                expect(() => nativeTestFactory.Results[TestPosition.At(3)] == "nested");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 0)] == "b1");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 1)] == "b2");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 2)] == "b3");
            }
        }
예제 #11
0
        public void IsInScopeFor()
        {
            expect(() => !TestPosition.At(0).IsOnPathTo(TestPosition.At()));

            expect(() => TestPosition.At(0).IsOnPathTo(TestPosition.At(0, 1)));
            expect(() => TestPosition.At(0).IsOnPathTo(TestPosition.At(1, 2)));
            expect(() => TestPosition.At(0).IsOnPathTo(TestPosition.At(5)));
            expect(() => TestPosition.At(0).IsOnPathTo(TestPosition.At(5, 123)));

            expect(() => !TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 2)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 5)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 5, 0)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 5, 3)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 7)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 7, 0)));
            expect(() => TestPosition.At(0, 5).IsOnPathTo(TestPosition.At(0, 7, 3)));

            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(0)));
            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(0, 2, 3)));
            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(2, 2, 3)));
            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(1, 0, 3)));
            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(1, 3, 3)));
            expect(() => !TestPosition.At(1, 2, 3).IsOnPathTo(TestPosition.At(2, 2, 2, 10)));
        }
예제 #12
0
 public void GetFirstChildPosition()
 {
     expect(() => TestPosition.At(0).GetFirstChildPosition().Equals(TestPosition.At(0, 0)));
     expect(() => TestPosition.At(3, 1, 0, 10, 93).GetFirstChildPosition().Equals(TestPosition.At(3, 1, 0, 10, 93, 0)));
 }
        public override void Specify()
        {
            List <string> recording = new List <string>();
            int           tracer    = 0;

            given("a fixture with global setup", delegate
            {
                var fixture = new LambdaFixture()
                {
                    LambdaSpecify = f =>
                    {
                        var firstSetup = f.beforeAll(delegate
                        {
                            recording.Add("beforeAll " + tracer++);
                            return("beforeAll result " + tracer++);
                        });

                        f.afterAll(delegate
                        {
                            recording.Add("first setup was: " + firstSetup);
                        });

                        f.it("tests something", delegate
                        {
                        });

                        f.describe("some nested tests", delegate
                        {
                            f.beforeAll(() => recording.Add("nested beforeAll " + tracer++));
                            f.afterAll(delegate
                            {
                                recording.Add("nested afterAll " + tracer++);
                            });

                            f.it("a nested test", delegate
                            {
                                int i = 0;
                            });
                        });

                        f.describe("more nested tests", delegate
                        {
                            f.it("has a test", delegate
                            {
                            });
                        });
                    }
                };

                var sut = arrange(() => new GlobalSetupManager(() => fixture));
                cleanup(() => sut.Close());

                when("a test is going to be run", delegate
                {
                    beforeEach(() => sut.PrepareForTestPosition(TestPosition.At(2)));

                    then("the global setup has ran", delegate
                    {
                        Assert.That(recording, Is.EquivalentTo(new[] { "beforeAll 0" }));
                    });

                    then("the global setup result is available", delegate
                    {
                        expect(() => "beforeAll result 1" == sut.GetSetupResultAt <string>(TestPosition.At(0)));
                    });

                    when("a later nested test is going to be ran", delegate
                    {
                        beforeEach(() => sut.PrepareForTestPosition(TestPosition.At(3, 2)));

                        then("the global setup has ran", delegate
                        {
                            Assert.That(recording, Is.EquivalentTo(new[]
                            {
                                "beforeAll 0",
                                "nested beforeAll 2",
                            }));
                        });

                        when("a later test nested in another block is going to be ran", delegate
                        {
                            beforeEach(() => sut.PrepareForTestPosition(TestPosition.At(4, 0)));

                            then("the global setup has ran", delegate
                            {
                                Assert.That(recording, Is.EquivalentTo(new[]
                                {
                                    "beforeAll 0",
                                    "nested beforeAll 2",
                                    "nested afterAll 3"
                                }));
                            });
                        });

                        when("we're done running tests", delegate
                        {
                            beforeEach(() => sut.Cleanup(TestPosition.At()));

                            then("expected cleanup runs", delegate
                            {
                                Assert.That(recording, Is.EquivalentTo(new[]
                                {
                                    "beforeAll 0",
                                    "nested beforeAll 2",
                                    "nested afterAll 3",
                                    "first setup was: beforeAll result 1"
                                }));
                            });

                            then("the setup thread finishes", delegate
                            {
                                expect(() => !sut.HasThread());
                            });
                        });
                    });
                });
            });

            given("a fixture with an error at its outer scope", delegate
            {
                var fixture = new LambdaFixture()
                {
                    LambdaSpecify = f =>
                    {
                        int i = 0;
                        int j = 100 / i;

                        it("has a test", delegate
                        {
                        });
                    }
                };

                var sut = arrange(() => new GlobalSetupManager(() => fixture));
                cleanup(() => sut.Close());

                when("a test is to be ran", delegate
                {
                    Exception exception = beforeEach(() => sut.PrepareForTestPosition(TestPosition.At(0)));

                    then("the exception is reported", delegate
                    {
                        expect(() => exception != null);
                    });

                    when("we're done running tests", delegate
                    {
                        expect(() => sut.HasThread());
                        beforeEach(() => sut.Cleanup(TestPosition.At()));

                        then("the setup thread finishes", delegate
                        {
                            expect(() => !sut.HasThread());
                        });
                    });
                });
            });
        }
예제 #14
0
 public void GetNextSiblingPosition()
 {
     expect(() => TestPosition.At(0).GetNextSiblingPosition().Equals(TestPosition.At(1)));
     expect(() => TestPosition.At(3, 1, 0, 10, 93).GetNextSiblingPosition().Equals(TestPosition.At(3, 1, 0, 10, 94)));
 }
예제 #15
0
 public void Close()
 {
     Cleanup(TestPosition.At());
 }
예제 #16
0
        public void test_Parent()
        {
            var position = TestPosition.At(1, 2, 3);

            expect(() => position.Parent.Equals(TestPosition.At(1, 2)));
        }
예제 #17
0
        public void visitFork(ForkElement element, TestPosition position)
        {
            if (position.IsAncestorOf(_targetPosition))
            {
                try
                {
                    element.Action();
                }
                catch (Exception e)
                {
                    ReportError(position, e);
                }
            }

            while (position.Equals(_targetPosition))
            {
                _currentTestPosition = position;

                _runningLock.PassAndWaitForTurn();
            }

            _setupResultAccumulator.UnwindForPosition(_targetPosition, e => ReportError(TestPosition.At(0), e));
            _traceTracker.UnwindToPosition(_targetPosition);
        }