public void TestConstructorWithSuite()
        {
            const string       name   = "suite-name";
            NUnitSuite         suite  = new NUnitSuite(name);
            NUnitRunnerForTest runner = new NUnitRunnerForTest(suite);

            Assert.IsNotNull(runner.TestSuite);
            Assert.AreSame(suite, runner.TestSuite);
            Assert.AreEqual(name, runner.TestSuite.Name);
            Assert.AreEqual(name, runner.TestSuite.FullName);
        }
        public void TestAddTestAssemblyThrowsArgumentNullExceptionWhenAssemblyIsNull()
        {
            NUnitSuite         suite    = new NUnitSuite("suite-name");
            Assembly           assembly = null;
            NUnitRunnerForTest runner   = new NUnitRunnerForTest(suite);

            Assert.Throws(
                Is.TypeOf <ArgumentNullException>().And.Message
                .EqualTo("The assembly cannot be null. (Parameter 'assembly')"),
                // ReSharper disable once ExpressionIsAlwaysNull
                () => runner.AddTestAssembly(assembly));
        }
        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 TestAddTestAssemblyWithAssemblyLoadInvalidDoesNotAddAssemblyAndReturnsNull()
        {
            NUnitSuiteForTest suite = new NUnitSuiteForTest("suite-name");

            suite.IsLoadedTestNull = true;
            NUnitRunnerForTest runner = new NUnitRunnerForTest(suite);

            Assembly assembly = typeof(TestFixtureStubOne).Assembly;

            ITest test = runner.AddTestAssembly(assembly);

            Assert.IsNull(test);
            Assert.IsFalse(runner.TestSuite.ContainsAssembly(assembly));
            CollectionAssert.IsEmpty(runner.TestSuite.TestAssemblies);
        }
        public void TestAddTestAssemblyWithAssemblyLoadNotRunnableDoesNotAddAssemblyAndReturnsErroneousTest()
        {
            NUnitSuiteForTest suite = new NUnitSuiteForTest("suite-name");

            suite.IsLoadedTestInvalid = true;
            NUnitRunnerForTest runner = new NUnitRunnerForTest(suite);

            Assembly assembly = typeof(TestFixtureStubOne).Assembly;

            ITest test = runner.AddTestAssembly(assembly);

            Assert.IsNotNull(test);
            Assert.AreEqual(RunState.NotRunnable, test.RunState);
            Assert.IsFalse(suite.ContainsAssembly(assembly));
            CollectionAssert.IsEmpty(suite.TestAssemblies);
        }