Пример #1
0
        public void TestAddWithAssemblyAlreadyAddedDoesNotReAddAssemblyAndReturnsAlreadyAddedAssembly()
        {
            NUnitSuite      suite              = new NUnitSuite("suite-name");
            Assembly        assembly           = typeof(TestFixtureStubOne).Assembly;
            List <Assembly> expectedAssemblies = new List <Assembly> {
                assembly
            };

            ITest testInitial = suite.Add(assembly);

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

            ITest test = suite.Add(assembly);

            Assert.IsNotNull(test);
            Assert.AreSame(testInitial, test);
            Assert.AreEqual(RunState.Runnable, test.RunState);
            Assert.AreEqual("XamarinNUnitRunner.Test.Stub.dll", test.Name);
            Assert.IsTrue(suite.ContainsAssembly(assembly));
            Assert.IsTrue(suite.GetTestAssemblyRunner(assembly).IsTestLoaded);
            CollectionAssert.AreEquivalent(expectedAssemblies, suite.TestAssemblies);
        }
Пример #2
0
        /// <summary>
        ///     Check common NUnitSuite constructor properties.
        /// </summary>
        /// <param name="suite">The NUnitSuite to check.</param>
        /// <param name="argsEmpty">If the argument list is considered empty</param>
        private static void TestCommonConstructorProperties(NUnitSuite suite, bool argsEmpty = true)
        {
            Assert.IsNotNull(suite.Id);
            Assert.IsNotEmpty(suite.Id);
            Assert.IsNull(suite.MethodName);
            Assert.IsNull(suite.Method);
            Assert.IsNotNull(suite.Arguments);
            if (argsEmpty)
            {
                CollectionAssert.IsEmpty(suite.Arguments);
            }

            Assert.AreEqual(RunState.Runnable, suite.RunState);
            Assert.AreEqual(c_SuiteXmlElement, suite.XmlElementName);
            Assert.AreEqual(suite.GetType().Name, suite.TestType);
            Assert.AreEqual(0, suite.TestCaseCount);
            Assert.IsNotNull(suite.Properties);
            CollectionAssert.IsEmpty(suite.Properties.Keys);
            Assert.IsTrue(suite.IsSuite);
            Assert.IsFalse(suite.HasChildren);
            Assert.IsNull(suite.Parent);
            Assert.IsNotNull(suite.Tests);
            CollectionAssert.IsEmpty(suite.Tests);
            Assert.IsNotNull(suite.SetUpMethods);
            CollectionAssert.IsEmpty(suite.SetUpMethods);
            Assert.IsNotNull(suite.TearDownMethods);
            CollectionAssert.IsEmpty(suite.TearDownMethods);
        }
Пример #3
0
        public void TestConstructorWithFixtureTypeInfoAndArguments([Values] bool isArgsNull)
        {
            object[]    args             = isArgsNull ? null : new object[] { "arg1", "arg2" };
            TypeWrapper wrapper          = new TypeWrapper(GetType());
            string      name             = wrapper.GetDisplayName();
            string      parentName       = wrapper.Namespace;
            string      expectedFullName = name;

            if (!string.IsNullOrEmpty(parentName))
            {
                expectedFullName = parentName + "." + name;
            }

            NUnitSuite suite = new NUnitSuite(wrapper, args);

            Assert.AreEqual(name, suite.Name);
            Assert.AreEqual(expectedFullName, suite.FullName);
            Assert.AreEqual(wrapper.FullName, suite.ClassName);
            Assert.IsNotNull(suite.Arguments);
            Assert.AreEqual(wrapper.FullName, suite.TypeInfo.FullName);

            TestCommonConstructorProperties(suite, isArgsNull);
            if (!isArgsNull)
            {
                CollectionAssert.AreEquivalent(args, suite.Arguments);
            }
        }
Пример #4
0
        public void TestTestAssembliesPropertyReturnsListOfAddedAssemblies([Values] bool isEmpty)
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

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

            if (!isEmpty)
            {
                suite.Add(assembly);
            }

            IList <Assembly> assemblies = suite.TestAssemblies;

            Assert.IsNotNull(assemblies);
            if (isEmpty)
            {
                CollectionAssert.IsEmpty(assemblies);
            }
            else
            {
                CollectionAssert.AreEquivalent(expected, assemblies);
            }
        }
Пример #5
0
        public void TestTestAssemblyRunnersPropertyReturnsListOfAddedTestAssemblyRunners([Values] bool isEmpty)
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

            Assembly assembly = typeof(TestFixtureStubOne).Assembly;
            IList <ITestAssemblyRunner> expected = new List <ITestAssemblyRunner>();

            if (!isEmpty)
            {
                suite.Add(assembly);
                expected.Add(suite.GetTestAssemblyRunner(assembly));
            }

            IList <ITestAssemblyRunner> runners = suite.TestAssemblyRunners;

            Assert.IsNotNull(runners);
            if (isEmpty)
            {
                CollectionAssert.IsEmpty(runners);
            }
            else
            {
                CollectionAssert.AreEquivalent(expected, runners);
            }
        }
Пример #6
0
        public void TestAddWithAssemblyNotAlreadyAddedLoadsAndAddsAssemblyAndReturnsAddedTest(
            [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;

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

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

            ITest test = suite.Add(assembly, settings);

            Assert.IsNotNull(test);
            Assert.AreEqual(RunState.Runnable, test.RunState);
            Assert.AreEqual("XamarinNUnitRunner.Test.Stub.dll", test.Name);
            Assert.IsTrue(suite.ContainsAssembly(assembly));
            Assert.IsTrue(suite.GetTestAssemblyRunner(assembly).IsTestLoaded);
            Assert.AreEqual(expectedDirectory, TestContext.CurrentContext.WorkDirectory);
            CollectionAssert.AreEquivalent(expectedAssemblies, suite.TestAssemblies);
        }
Пример #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="NUnitRunner" /> class.
        /// </summary>
        /// <param name="name">The name of the suite.</param>
        /// <exception cref="ArgumentException"><see cref="name" /> is <c>null</c> or empty.</exception>
        public NUnitRunner(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw ExceptionHelper.ThrowArgumentExceptionForNullOrEmpty(nameof(name));
            }

            TestSuite = new NUnitSuite(name);
        }
Пример #8
0
        public void TestContainsAssemblyWithAssemblyNullReturnsFalse()
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

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

            bool contains = suite.ContainsAssembly(null);

            Assert.IsFalse(contains);
        }
Пример #9
0
        public void TestGetTestAssemblyRunnerWithAssemblyNullReturnsNull()
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

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

            ITestAssemblyRunner runner = suite.GetTestAssemblyRunner(null);

            Assert.IsNull(runner);
        }
Пример #10
0
        public void TestContainsAssemblyWithAssemblyAddedReturnsTrue()
        {
            NUnitSuite suite    = new NUnitSuite("suite-name");
            Assembly   assembly = typeof(TestFixtureStubOne).Assembly;

            suite.Add(assembly);

            bool contains = suite.ContainsAssembly(assembly);

            Assert.IsTrue(contains);
        }
Пример #11
0
        public void TestAddThrowsArgumentNullExceptionWhenAssemblyIsNull()
        {
            NUnitSuite suite    = new NUnitSuite("suite-name");
            Assembly   assembly = null;

            Assert.Throws(
                Is.TypeOf <ArgumentNullException>().And.Message
                .EqualTo("The assembly cannot be null. (Parameter 'assembly')"),
                // ReSharper disable once ExpressionIsAlwaysNull
                () => suite.Add(assembly));
        }
Пример #12
0
        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);
        }
Пример #13
0
        public void TestConstructorThrowsArgumentNullExceptionWhenSuiteIsNull()
        {
            NUnitSuite suite = null;

            Assert.Throws(
                Is.TypeOf <ArgumentNullException>().And.Message
                .EqualTo("The suite cannot be null. (Parameter 'suite')"),
                // ReSharper disable once ObjectCreationAsStatement
                // ReSharper disable once ExpressionIsAlwaysNull
                () => { new NUnitRunnerForTest(suite); });
        }
Пример #14
0
        public void TestGetTestAssemblyRunnerWithAssemblyAddedReturnsTestAssemblyRunner()
        {
            NUnitSuite suite    = new NUnitSuite("suite-name");
            Assembly   assembly = typeof(TestFixtureStubOne).Assembly;

            suite.Add(assembly);

            ITestAssemblyRunner runner = suite.GetTestAssemblyRunner(assembly);

            Assert.IsNotNull(runner);
        }
Пример #15
0
        public void TestAddTestAssemblyAsyncThrowsArgumentNullExceptionWhenAssemblyIsNull()
        {
            NUnitSuite         suite    = new NUnitSuite("suite-name");
            Assembly           assembly = null;
            NUnitRunnerForTest runner   = new NUnitRunnerForTest(suite);

            Assert.ThrowsAsync(
                Is.TypeOf <ArgumentNullException>().And.Message
                .EqualTo("The assembly cannot be null. (Parameter 'assembly')"),
                // ReSharper disable once ExpressionIsAlwaysNull
                async() => await runner.AddTestAssemblyAsync(assembly));
        }
Пример #16
0
        public void TestExploreTestsWithAssemblyNotAddedReturnsEmptyTestCases()
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

            ITest tests = suite.ExploreTests(NUnitFilter.Empty);

            Assert.IsNotNull(tests);
            Assert.AreEqual(suite.Name, tests.Name);
            Assert.IsFalse(tests.HasChildren);
            Assert.AreEqual(0, tests.Tests.Count);
            Assert.AreEqual(0, tests.TestCaseCount);
        }
Пример #17
0
        public void TestConstructorWithName()
        {
            const string name = "suite-name";

            NUnitSuite suite = new NUnitSuite(name);

            Assert.AreEqual(name, suite.Name);
            Assert.AreEqual(name, suite.FullName);
            Assert.IsNull(suite.ClassName);
            Assert.IsNull(suite.TypeInfo);

            TestCommonConstructorProperties(suite);
        }
Пример #18
0
        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);
        }
Пример #19
0
        public void TestIsTestRunningPropertyReturnsFalseIfNoTestIsRunning([Values] bool isEmpty)
        {
            NUnitSuite suite = new NUnitSuite("suite-name");

            Assembly assembly = typeof(TestFixtureStubOne).Assembly;

            if (!isEmpty)
            {
                suite.Add(assembly);
            }

            bool running = suite.IsTestRunning;

            Assert.IsFalse(running);
        }
Пример #20
0
        public void TestOnItemSelectedWithSelectedItemTestDoesNotHaveChildrenAndIsTestSuiteReturnsImmediately()
        {
            NUnitRunner    runner = new NUnitRunner("runner-name");
            ITest          suite  = new NUnitSuite("suite-name");
            TestsViewModel test   = new TestsViewModel(runner, suite);

            Assert.IsTrue(test.Test.IsSuite);
            Assert.IsFalse(test.Test.HasChildren);

            SelectedItemChangedEventArgs args = new SelectedItemChangedEventArgs(test, 0);

            TestsPageForTest page = new TestsPageForTest(runner, test);

            page.InvokeOnItemSelected(null, args);

            CollectionAssert.IsEmpty(page.NavigationStack);
        }
Пример #21
0
        public void TestConstructorWithParentSuiteNameAndName([Values("parent-name", null, "")] string parentName,
                                                              [Values("suite-name", null, "")] string name)
        {
            string expectedFullName = name;

            if (!string.IsNullOrEmpty(parentName))
            {
                expectedFullName = parentName + "." + name;
            }

            NUnitSuite suite = new NUnitSuite(parentName, name);

            Assert.AreEqual(name, suite.Name);
            Assert.AreEqual(expectedFullName, suite.FullName);
            Assert.IsNull(suite.ClassName);
            Assert.IsNull(suite.TypeInfo);

            TestCommonConstructorProperties(suite);
        }
Пример #22
0
        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);
        }
Пример #23
0
        public void TestConstructorWithFixtureType()
        {
            TypeWrapper wrapper          = new TypeWrapper(GetType());
            string      name             = wrapper.GetDisplayName();
            string      parentName       = wrapper.Namespace;
            string      expectedFullName = name;

            if (!string.IsNullOrEmpty(parentName))
            {
                expectedFullName = parentName + "." + name;
            }

            NUnitSuite suite = new NUnitSuite(GetType());

            Assert.AreEqual(name, suite.Name);
            Assert.AreEqual(expectedFullName, suite.FullName);
            Assert.AreEqual(wrapper.FullName, suite.ClassName);
            Assert.AreEqual(wrapper.FullName, suite.TypeInfo.FullName);

            TestCommonConstructorProperties(suite);
        }
 /// <inheritdoc />
 public NUnitRunnerForTest(NUnitSuite suite) : base(suite)
 {
 }
Пример #25
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="NUnitRunner" /> class.
 /// </summary>
 /// <param name="suite">The name of the suite.</param>
 /// <exception cref="ArgumentNullException"><see cref="suite" /> is <c>null</c>.</exception>
 protected NUnitRunner(NUnitSuite suite)
 {
     TestSuite = suite ?? throw ExceptionHelper.ThrowArgumentNullException(nameof(suite));
 }