public override void Specify()
        {
            describe("thatsInconclusive()", delegate
            {
                it("allows results that are inconclusive", delegate
                {
                    var xmlOutput = NUnitSampleData.GetSampleXmlResult(aSuiteName: "fooSuite", aSuiteResult: "Inconclusive");

                    var sut = new NUnitFixtureResult("ignored", xmlOutput).hasSuite("fooSuite");

                    sut.thatsInconclusive();
                });

                it("gives an error indicating the actual result when not inconclusive", delegate
                {
                    var xmlOutput = NUnitSampleData.GetSampleXmlResult(aSuiteName: "fooSuite", aSuiteResult: "OtherResult");

                    var sut = new NUnitFixtureResult("ignored", xmlOutput).hasSuite("fooSuite");

                    var exception = Assert.Throws(NUnitFixtureResultTest.ExpectedAssertionType, delegate
                    {
                        sut.thatsInconclusive();
                    });

                    expect(() => exception.Message.Contains("fooSuite"));
                    expect(() => exception.Message.Contains("OtherResult"));
                });
            });

            describe("thatHasNoResults()", delegate
            {
                it("fails if the suite has results", delegate
                {
                    var sut = new NUnitFixtureResult("ignored",
                                                     NUnitSampleData.GetSampleXmlResult(aSuiteName: "someSuiteHello"))
                              .hasSuite("someSuiteHello");

                    var exception = Assert.Throws(NUnitFixtureResultTest.ExpectedAssertionType, delegate
                    {
                        sut.thatHasNoResults();
                    });

                    expect(() => exception.Message.Contains("someSuiteHello"));
                });
            });
        }
Пример #2
0
        public override void Specify()
        {
            describe("succeeds()", delegate
            {
                it("allows a passing test result", delegate
                {
                    new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(1)).succeeds();
                });

                var cases = new Dictionary <string, TestDelegate>();

                cases.Add("running against error", delegate
                {
                    var sut = new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(1, 1));
                    sut.succeeds();
                });

                cases.Add("running against failure", delegate
                {
                    var sut = new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(1, 0, 1));
                    sut.succeeds();
                });

                cases.Add("running against no tests", delegate
                {
                    var sut = new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(0));
                    sut.succeeds();
                });

                CheckScenariosCauseErrorWithMessageContaining(cases, _expectedFixtureName);
            });

            describe("failed()", delegate
            {
                it("allows test results with errors or failures", delegate
                {
                    new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(1, 1)).failed();
                    new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(1, 0, 1)).failed();
                });

                CheckScenario("running against no tests", delegate
                {
                    var sut = new NUnitFixtureResult(_expectedFixtureName, NUnitSampleData.GetSampleXmlResult(0), "");
                    sut.failed();
                }, _expectedFixtureName);
            });

            describe("hasTrace", delegate
            {
                var originalXml = "<xml></xml>";

                string originalConsole = @"
NUnit version 2.5.9.10348
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  CLR Version: 2.0.50727.5446 ( Net 2.0 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: Default
<<{{test started, before include of a}}>>
<<{{after include of a}}>>
<<{{first describe, before include of b}}>>
<<{{after include of b}}>>
<<{{before include of c}}>>
<<{{after include of c}}>>
Selected test(s): NJasmineTests.Specs.beforeAll.beforeAll_and_afterAll_are_applied_to_the_correct_scope
.{{<<RESET>>}}
<<{{BEFORE ALL}}>>
<<{{first test}}>>
.<<{{SECOND BEFORE ALL}}>>
<<{{INNER BEFORE ALL}}>>
<<{{second test}}>>
.<<{{third test}}>>
<<{{INNER AFTER ALL}}>>
<<{{DISPOSING INNER BEFORE ALL}}>>
<<{{SECOND AFTER ALL}}>>
<<{{DISPOSING SECOND BEFORE ALL}}>>
<<{{AFTER ALL}}>>
<<{{DISPOSING BEFORE ALL}}>>

Tests run: 3, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0820047 seconds
";

                it("allows tests with the expected trace", delegate
                {
                    new NUnitFixtureResult(_expectedFixtureName, originalXml, originalConsole).hasTrace(@"
BEFORE ALL
first test
SECOND BEFORE ALL
INNER BEFORE ALL
second test
third test
INNER AFTER ALL
DISPOSING INNER BEFORE ALL
SECOND AFTER ALL
DISPOSING SECOND BEFORE ALL
AFTER ALL
DISPOSING BEFORE ALL
");
                });

                it("fails tests without the expected trace", delegate
                {
                    var sut = new NUnitFixtureResult(_expectedFixtureName, originalXml, originalConsole);

                    var exception = Assert.Throws(ExpectedAssertionType, delegate
                    {
                        sut.hasTrace(@"
ONE
TWO
THREE
");
                    });

                    var message = exception.Message;

                    expect(() => message.IndexOf("ONE") < message.IndexOf("TWO"));
                    expect(() => message.IndexOf("TWO") < message.IndexOf("THREE"));

                    expect(() => message.IndexOf("BEFORE ALL") < message.IndexOf("INNER AFTER ALL"));
                    expect(() => message.IndexOf("INNER AFTER ALL") < message.IndexOf("DISPOSING BEFORE ALL"));

                    expect(() => message.Contains(_expectedFixtureName));
                });
            });

            describe("hasTest", delegate
            {
                var expectedTestName = "one_two_test";

                var xmlOutput = NUnitSampleData.GetSampleXmlResult(aTestName: _expectedFixtureName + ", " + expectedTestName);

                var sut = arrange(() => new NUnitFixtureResult(_expectedFixtureName, xmlOutput));

                it("returns a test by name", delegate
                {
                    expect(() => sut.hasTest(expectedTestName) != null);
                });

                it("gives a useful error message if the test is not found", delegate
                {
                    string wrongTestName = "fsadf325m";

                    var exception = Assert.Throws(ExpectedAssertionType, delegate
                    {
                        sut.hasTestWithFullName(wrongTestName);
                    });

                    expect(() => exception.Message.Contains("Expected test not found, expected test named " + wrongTestName));
                });
            });

            describe("hasSuite", delegate
            {
                var expectedSuiteName = "one_two_test";

                var xmlOutput = NUnitSampleData.GetSampleXmlResult(aSuiteName: expectedSuiteName);

                var sut = arrange(() => new NUnitFixtureResult(_expectedFixtureName, xmlOutput));

                it("returns a test suite by name", delegate
                {
                    expect(() => sut.hasSuite(expectedSuiteName) != null);
                });

                it("gives a useful error message if the test suite is not found", delegate
                {
                    string wrongSuiteName = "9vasjf9d";

                    var exception = Assert.Throws(ExpectedAssertionType, delegate
                    {
                        sut.hasSuite(wrongSuiteName);
                    });

                    expect(() => exception.Message.Contains("Expected test suite not found, expected suite named '" + wrongSuiteName));
                });
            });

            describe("withStackTraces()", delegate
            {
                string fullTrace = "foo bar baz";

                it("it returns the stacktraces in a fixture result", delegate
                {
                    var sut = arrange(() => new NUnitFixtureResult(_expectedFixtureName,
                                                                   NUnitSampleData.GetSampleXmlResult(aStackTrace: fullTrace)));

                    expect(() => sut.withStackTraces().Single() == fullTrace);
                });
            });
        }