示例#1
0
        /// <summary>
        /// Create the test filter for this run - public for testing
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static TestFilter CreateTestFilter(NUnitLiteOptions options)
        {
            var filter = TestFilter.Empty;

            if (options.TestList.Count > 0)
            {
                var testFilters = new List <TestFilter>();
                foreach (var test in options.TestList)
                {
                    testFilters.Add(new FullNameFilter(test));
                }

                filter = testFilters.Count > 1
                    ? new OrFilter(testFilters.ToArray())
                    : testFilters[0];
            }


            if (options.WhereClauseSpecified)
            {
                string xmlText     = new TestSelectionParser().Parse(options.WhereClause);
                var    whereFilter = TestFilter.FromXml(TNode.FromXml(xmlText));
                filter = filter.IsEmpty
                    ? whereFilter
                    : new AndFilter(filter, whereFilter);
            }

            return(filter);
        }
示例#2
0
        /// <summary>
        /// Create a TestFilter instance from an xml representation.
        /// </summary>
        public static TestFilter FromXml(string xmlText)
        {
            if (string.IsNullOrEmpty(xmlText))
            {
                xmlText = "<filter />";
            }

            TNode topNode = TNode.FromXml(xmlText);

            if (topNode.Name != "filter")
            {
                throw new Exception("Expected filter element at top level");
            }

            int count = topNode.ChildNodes.Count;

            TestFilter filter = count == 0
                ? TestFilter.Empty
                : count == 1
                    ? FromXml(topNode.FirstChild)
                    : FromXml(topNode);

            filter.TopLevel = true;

            return(filter);
        }
示例#3
0
 internal TestResultAdaptor(RemoteTestResultData result, RemoteTestResultDataWithTestData allData)
 {
     Test              = new TestAdaptor(allData.tests.First(t => t.id == result.testId));
     Name              = result.name;
     FullName          = result.fullName;
     ResultState       = result.resultState;
     TestStatus        = ParseTestStatus(result.testStatus);
     Duration          = result.duration;
     StartTime         = result.startTime;
     EndTime           = result.endTime;
     Message           = result.message;
     StackTrace        = result.stackTrace;
     AssertCount       = result.assertCount;
     FailCount         = result.failCount;
     PassCount         = result.passCount;
     SkipCount         = result.skipCount;
     InconclusiveCount = result.inconclusiveCount;
     HasChildren       = result.hasChildren;
     Output            = result.output;
     Children          = result.childrenIds.Select(childId => new TestResultAdaptor(allData.results.First(r => r.testId == childId), allData)).ToArray();
     if (!string.IsNullOrEmpty(result.xml))
     {
         m_Node = TNode.FromXml(result.xml);
     }
 }
示例#4
0
        public void LoadTestsAction_BadFile_ReturnsNonRunnableSuite()
        {
            new FrameworkController.LoadTestsAction(new FrameworkController(BAD_FILE, "ID", _settings), _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            // Minimal check here to allow for platform differences
            Assert.That(GetSkipReason(result), Contains.Substring(BAD_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
示例#5
0
        public void LoadTestsAction_GoodFile_ReturnsRunnableSuite()
        {
            new FrameworkController.LoadTestsAction(_controller, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
示例#6
0
        public void ExploreTestsAction_AfterLoad_ReturnsSameCount(string filter)
        {
            new FrameworkController.LoadTestsAction(_controller, _handler);
            new FrameworkController.ExploreTestsAction(_controller, filter, _handler);
            var exploreResult = TNode.FromXml(_handler.GetCallbackResult());

            var exploreTestCount = exploreResult.Attributes["testcasecount"];

            new FrameworkController.CountTestsAction(_controller, filter, _handler);
            var countResult = _handler.GetCallbackResult();

            Assert.That(exploreTestCount, Is.EqualTo(countResult));
        }
示例#7
0
        public void ExploreTestsAction_FilterCategory_ReturnsTests()
        {
            new FrameworkController.LoadTestsAction(_controller, _handler);
            new FrameworkController.ExploreTestsAction(_controller, FIXTURE_CAT_FILTER, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockTestFixture.Tests.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.GreaterThan(0), "Explore result should have child tests");
        }
示例#8
0
        public void ExploreTestsAction_FileNotFound_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(MISSING_FILE, "ID", _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.ExploreTestsAction(controller, EMPTY_FILTER, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo("0"));
            // Minimal check here to allow for platform differences
            Assert.That(GetSkipReason(result), Contains.Substring(MISSING_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Result should not have child tests");
        }
示例#9
0
        public void LoadTestsAction_FileNotFound_ReturnsNonRunnableSuite()
        {
            new FrameworkController.LoadTestsAction(new FrameworkController(MISSING_FILE, "ID", _settings), _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo("0"));
            // Minimal check here to allow for platform differences
#if NETCOREAPP1_1
            Assert.That(GetSkipReason(result), Contains.Substring("The system cannot find the file specified."));
#else
            Assert.That(GetSkipReason(result), Contains.Substring(MISSING_NAME));
#endif
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
示例#10
0
        public void LoadTestsAction_Assembly_ReturnsRunnableSuite()
        {
            _controller = new FrameworkController(typeof(MockAssembly).GetTypeInfo().Assembly, "ID", _settings);
            new FrameworkController.LoadTestsAction(_controller, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
#if SILVERLIGHT
            Assert.That(result.Attributes["name"], Is.EqualTo("mock-nunit-assembly"));
#else
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME).IgnoreCase);
#endif
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
示例#11
0
        public void RunTestsAction_AfterLoad_ReturnsRunnableSuite()
        {
            new FrameworkController.LoadTestsAction(_controller, _handler);
            new FrameworkController.RunTestsAction(_controller, EMPTY_FILTER, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.Attributes["result"], Is.EqualTo("Failed"));
            Assert.That(result.Attributes["passed"], Is.EqualTo(MockAssembly.Success.ToString()));
            Assert.That(result.Attributes["failed"], Is.EqualTo(MockAssembly.ErrorsAndFailures.ToString()));
            Assert.That(result.Attributes["skipped"], Is.EqualTo(MockAssembly.Skipped.ToString()));
            Assert.That(result.Attributes["inconclusive"], Is.EqualTo(MockAssembly.Inconclusive.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.GreaterThan(0), "Run result should have child tests");
        }
示例#12
0
        public void RunTestsAction_AfterLoad_ReturnsRunnableSuite(string filter)
        {
            new FrameworkController.LoadTestsAction(_controller, _handler);
            new FrameworkController.RunTestsAction(_controller, filter, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            // TODO: Any failure here throws an exception because the call to RunTestsAction
            // has destroyed the test context. We need to figure out how to execute the run
            // in a cleaner way, perhaps on another thread or in a process.
            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.Attributes["result"], Is.EqualTo("Failed"));
            Assert.That(result.Attributes["passed"], Is.EqualTo(MockAssembly.Passed.ToString()));
            Assert.That(result.Attributes["failed"], Is.EqualTo(MockAssembly.Failed.ToString()));
            Assert.That(result.Attributes["warnings"], Is.EqualTo(MockAssembly.Warnings.ToString()));
            Assert.That(result.Attributes["skipped"], Is.EqualTo(MockAssembly.Skipped.ToString()));
            Assert.That(result.Attributes["inconclusive"], Is.EqualTo(MockAssembly.Inconclusive.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.GreaterThan(0), "Run result should have child tests");
        }
示例#13
0
 public TNode ToXml(bool recursive)
 {
     return(TNode.FromXml($"<filter><test>{fullName}</test></filter>"));
 }