public void TestExploreTestsAsyncWithAssemblyReturnsLoadedTestCases([Values] bool withChildTests,
                                                                            [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : null;

            INUnitRunner runner   = new NUnitRunner("suite-name");
            Assembly     assembly = typeof(TestFixtureStubOne).Assembly;

            int expected = 0;

            if (withChildTests)
            {
                expected = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);
                testTask.Wait();
            }

            Task <ITest> exploreTask = runner.ExploreTestsAsync(assembly, filter);

            Assert.IsNotNull(exploreTask);
            exploreTask.Wait();
            ITest test = exploreTask.Result;

            if (withChildTests)
            {
                Assert.IsNotNull(test);
                Assert.AreEqual(expected, test.TestCaseCount);
            }
            else
            {
                Assert.IsNull(test);
            }
        }
        public void TestCountTestCasesAsyncReturnsNumberOfTestCasesLoaded([Values] bool withChildTests,
                                                                          [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : null;

            INUnitRunner runner   = new NUnitRunner("suite-name");
            Assembly     assembly = typeof(TestFixtureStubOne).Assembly;

            int expected = 0;

            if (withChildTests)
            {
                expected = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);
                testTask.Wait();
            }

            Task <int> countTask = runner.CountTestCasesAsync(filter);

            Assert.IsNotNull(countTask);
            countTask.Wait();
            int count = countTask.Result;

            Assert.AreEqual(expected, count);
        }
        public void TestRunTestsAsyncWithAssemblyRunsTestsAndReturnsTheRanTests([Values] bool withChildTests,
                                                                                [Values] bool withListener, [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : null;
            ResultState expectedState = ResultState.Inconclusive;

            if (withChildTests)
            {
                expectedState = withFilter ? ResultState.Success : ResultState.ChildFailure;
            }

            TestListenerForTest listener = withListener ? new TestListenerForTest() : null;

            INUnitRunner runner   = new NUnitRunner("suite-name");
            Assembly     assembly = typeof(TestFixtureStubOne).Assembly;

            int expectedCaseCount   = 0;
            int expectedResultCount = 0;

            if (withChildTests)
            {
                expectedCaseCount = TestFixtureStubHelper.GeTestFixtureStub().ResultsDepth +
                                    (withFilter ? 2 : TestFixtureStubHelper.GeTestFixtureStub().ResultCount);
                expectedResultCount = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);
                testTask.Wait();
            }

            Task <ITestResult> testsTask = runner.RunTestsAsync(assembly, listener, filter);

            Assert.IsNotNull(testsTask);
            testsTask.Wait();
            ITestResult results = testsTask.Result;

            if (withChildTests)
            {
                Assert.IsNotNull(results);
                Assert.IsFalse(runner.IsTestRunning);
                Assert.IsTrue(runner.IsTestComplete);
                Assert.AreEqual(expectedState, results.ResultState);
                int totalResultCount = results.FailCount + results.InconclusiveCount + results.PassCount +
                                       results.SkipCount +
                                       results.WarningCount;
                Assert.AreEqual(expectedResultCount, totalResultCount);

                if (withListener)
                {
                    Assert.AreEqual(expectedCaseCount, listener.Tests.Count);
                }
            }
            else
            {
                Assert.IsNull(results);
            }
        }
        public void TestConstructorWithTestSuiteAndFilter([Values] bool withChildTests, [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : NUnitFilter.Empty;

            NUnitSuite suiteInitial = new NUnitSuite("suite-one");

            if (withChildTests)
            {
                suiteInitial.Add(typeof(TestFixtureStubOne).Assembly);
            }

            NUnitSuite suite = new NUnitSuite(suiteInitial, filter);

            Assert.AreEqual(suiteInitial.Name, suite.Name);
            Assert.AreEqual(suiteInitial.FullName, suite.FullName);
            Assert.IsNull(suite.ClassName);
            Assert.IsNull(suite.TypeInfo);
            Assert.IsNotNull(suite.Id);
            Assert.IsNotEmpty(suite.Id);
            Assert.IsNull(suite.MethodName);
            Assert.IsNull(suite.Method);
            Assert.IsNull(suite.Arguments);
            Assert.AreEqual(RunState.Runnable, suite.RunState);
            Assert.AreEqual(c_SuiteXmlElement, suite.XmlElementName);
            Assert.AreEqual(suite.GetType().Name, suite.TestType);
            Assert.IsNotNull(suite.Properties);
            CollectionAssert.IsEmpty(suite.Properties.Keys);
            Assert.IsTrue(suite.IsSuite);
            Assert.IsNull(suite.Parent);
            Assert.IsNotNull(suite.Tests);
            if (withChildTests)
            {
                int testCount = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Assert.AreEqual(testCount, suite.TestCaseCount);
                Assert.IsTrue(suite.HasChildren);
                CollectionAssert.IsNotEmpty(suite.Tests);
            }
            else
            {
                Assert.AreEqual(0, suite.TestCaseCount);
                Assert.IsFalse(suite.HasChildren);
                CollectionAssert.IsEmpty(suite.Tests);
            }

            Assert.IsNotNull(suite.SetUpMethods);
            CollectionAssert.IsEmpty(suite.SetUpMethods);
            Assert.IsNotNull(suite.TearDownMethods);
            CollectionAssert.IsEmpty(suite.TearDownMethods);
        }
        TestRunTestsAsyncWithAlreadyRunningTestWaitsForPreviousCompletionAndThenRunsTestsAndReturnsTheRanTests()
        {
            TestListenerForTest listener = new TestListenerForTest();

            NUnitSuiteForTest         suite          = new NUnitSuiteForTest("suite-name");
            TestAssemblyRunnerForTest assemblyRunner = new TestAssemblyRunnerForTest();

            assemblyRunner.IsTestLoaded  = true;
            assemblyRunner.IsTestRunning = true;
            suite.RunnerToLoad           = assemblyRunner;

            NUnitRunnerForTest runner   = new NUnitRunnerForTest(suite);
            Assembly           assembly = typeof(TestFixtureStubOne).Assembly;

            int expectedCaseCount = TestFixtureStubHelper.GeTestFixtureStub().ResultsDepth +
                                    TestFixtureStubHelper.GeTestFixtureStub().ResultCount;
            int          expectedResultCount = TestFixtureStubHelper.GeTestFixtureStub().TestCount;
            Task <ITest> testTask            = runner.AddTestAssemblyAsync(assembly);

            testTask.Wait();

            Assert.IsTrue(runner.IsTestRunning);
            Assert.IsFalse(runner.IsTestComplete);

            Task <ITestResult> testsTask = runner.RunTestsAsync(listener);

            Assert.IsNotNull(testsTask);
            Assert.IsTrue(runner.IsTestRunning);
            Assert.IsFalse(runner.IsTestComplete);

            Thread.Sleep(50);
            assemblyRunner.IsTestRunning = false;

            testsTask.Wait();
            ITestResult results = testsTask.Result;

            Assert.IsFalse(runner.IsTestRunning);
            Assert.IsTrue(runner.IsTestComplete);

            Assert.IsNotNull(results);
            Assert.IsFalse(runner.IsTestRunning);
            Assert.IsTrue(runner.IsTestComplete);
            Assert.AreEqual(ResultState.ChildFailure, results.ResultState);
            int totalResultCount = results.FailCount + results.InconclusiveCount + results.PassCount +
                                   results.SkipCount +
                                   results.WarningCount;

            Assert.AreEqual(expectedResultCount, totalResultCount);
            Assert.AreEqual(expectedCaseCount, listener.Tests.Count);
        }
        public void TestGetTestResultsAsyncWithAssemblyReturnsResults([Values] bool withChildTests,
                                                                      [Values] bool runTests, [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : null;
            ResultState expectedState = ResultState.Inconclusive;

            if (withChildTests && runTests)
            {
                expectedState = withFilter ? ResultState.Success : ResultState.ChildFailure;
            }

            INUnitRunner runner   = new NUnitRunner("suite-name");
            Assembly     assembly = typeof(TestFixtureStubOne).Assembly;

            int expectedCount = 0;

            if (withChildTests)
            {
                expectedCount = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);
                testTask.Wait();
            }

            if (runTests)
            {
                runner.RunTests(null, filter);
            }
            else
            {
                expectedCount = 0;
            }

            Task <ITestResult> resultTask = runner.GetTestResultsAsync(assembly);

            Assert.IsNotNull(resultTask);
            resultTask.Wait();
            ITestResult results = resultTask.Result;

            Assert.IsNotNull(results);
            Assert.AreEqual(expectedState, results.ResultState);
            int totalCount = results.FailCount + results.InconclusiveCount + results.PassCount + results.SkipCount +
                             results.WarningCount;

            Assert.AreEqual(expectedCount, totalCount);
        }
        public void TestExploreTestsWithAssemblyAddedReturnsLoadedTestCases([Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : NUnitFilter.Empty;
            int expected = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;

            NUnitSuite suite = new NUnitSuite("suite-name");

            suite.Add(typeof(TestFixtureStubOne).Assembly);

            ITest tests = suite.ExploreTests(filter);

            Assert.IsNotNull(tests);
            Assert.AreEqual(suite.Name, tests.Name);
            Assert.IsTrue(tests.HasChildren);
            Assert.AreEqual(1, tests.Tests.Count);
            Assert.AreEqual(expected, tests.TestCaseCount);
        }