public void TestAddTestAssemblyAsyncWithAssemblyAlreadyAddedDoesNotReAddAssemblyAndReturnsAlreadyAddedAssembly()
        {
            INUnitRunner    runner             = new NUnitRunner("suite-name");
            Assembly        assembly           = typeof(TestFixtureStubOne).Assembly;
            List <Assembly> expectedAssemblies = new List <Assembly> {
                assembly
            };

            Task <ITest> testInitialTask = runner.AddTestAssemblyAsync(assembly);

            Assert.IsNotNull(testInitialTask);
            testInitialTask.Wait();
            ITest testInitial = testInitialTask.Result;

            Assert.IsNotNull(testInitial);
            Assert.AreEqual(RunState.Runnable, testInitial.RunState);
            Assert.AreEqual("XamarinNUnitRunner.Test.Stub.dll", testInitial.Name);
            Assert.IsTrue(runner.TestSuite.ContainsAssembly(assembly));
            Assert.IsTrue(runner.TestSuite.GetTestAssemblyRunner(assembly).IsTestLoaded);
            CollectionAssert.AreEquivalent(expectedAssemblies, runner.TestSuite.TestAssemblies);

            Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);

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

            Assert.IsNotNull(test);
            Assert.AreSame(testInitial, test);
            Assert.AreEqual(RunState.Runnable, test.RunState);
            Assert.AreEqual("XamarinNUnitRunner.Test.Stub.dll", test.Name);
            Assert.IsTrue(runner.TestSuite.ContainsAssembly(assembly));
            Assert.IsTrue(runner.TestSuite.GetTestAssemblyRunner(assembly).IsTestLoaded);
            CollectionAssert.AreEquivalent(expectedAssemblies, runner.TestSuite.TestAssemblies);
        }
        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 TestAddTestAssemblyAsyncWithAssemblyNotAlreadyAddedLoadsAndAddsAssemblyAndReturnsAddedTest(
            [Values] bool withSettings)
        {
            string workingDirectory              = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), ".."));
            string expectedDirectory             = withSettings ? workingDirectory : Directory.GetCurrentDirectory();
            Dictionary <string, object> settings = withSettings
                ? new Dictionary <string, object>
            {
                { FrameworkPackageSettings.WorkDirectory, workingDirectory }
            }
                : null;

            INUnitRunner runner = new NUnitRunner("suite-name");

            Assembly        assembly           = typeof(TestFixtureStubOne).Assembly;
            List <Assembly> expectedAssemblies = new List <Assembly> {
                assembly
            };

            Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly, settings);

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

            Assert.IsNotNull(test);
            Assert.AreEqual(RunState.Runnable, test.RunState);
            Assert.AreEqual("XamarinNUnitRunner.Test.Stub.dll", test.Name);
            Assert.IsTrue(runner.TestSuite.ContainsAssembly(assembly));
            Assert.IsTrue(runner.TestSuite.GetTestAssemblyRunner(assembly).IsTestLoaded);
            Assert.AreEqual(expectedDirectory, TestContext.CurrentContext.WorkDirectory);
            CollectionAssert.AreEquivalent(expectedAssemblies, runner.TestSuite.TestAssemblies);
        }
        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 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);
        }