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

            ITest testInitial = runner.AddTestAssembly(assembly);

            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);

            ITest test = runner.AddTestAssembly(assembly);

            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);
        }
예제 #2
0
        public void TestReloadResultsCommandReturnsImmediatelyWhenTestRunnerIsNull()
        {
            int         invocationCount = 0;
            NUnitRunner runner          = new NUnitRunner("runner-name");

            runner.AddTestAssembly(typeof(TestFixtureStubOne).Assembly);

            TestsViewModel model = new TestsViewModel(null, runner.TestSuite);

            model.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("IsBusy"))
                {
                    invocationCount++;
                }
            };

            model.ReloadResultsCommand.Execute(null);

            WaitForCommand(model);

            Assert.IsFalse(model.IsBusy);
            Assert.AreEqual(0, invocationCount);
            CollectionAssert.IsEmpty(model.Tests);
        }
        public void TestAddTestAssemblyWithAssemblyNotAlreadyAddedLoadsAndAddsAssemblyAndReturnsAddedTest(
            [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
            };

            ITest test = runner.AddTestAssembly(assembly, settings);

            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);
        }
예제 #4
0
        public void TestOnItemSelectedWithSelectedItemTestWithoutChildTestsPushesTestDetailPageToStackAndCaches()
        {
            NUnitRunner runner = new NUnitRunner("runner-name");

            runner.AddTestAssembly(typeof(TestFixtureStubOne).Assembly);
            IMethodInfo    methodOne          = new MethodWrapper(typeof(TestsPageTest), GetType().GetMethods().First());
            IMethodInfo    methodTwo          = new MethodWrapper(typeof(TestsPageTest), GetType().GetMethods().Last());
            ITest          firstTestInstance  = new TestMethod(methodOne);
            ITest          secondTestInstance = new TestMethod(methodTwo);
            TestsViewModel firstTest          = new TestsViewModel(runner, firstTestInstance);
            TestsViewModel secondTest         = new TestsViewModel(runner, secondTestInstance);

            Assert.IsFalse(firstTest.Test.IsSuite);
            Assert.IsFalse(firstTest.Test.HasChildren);
            Assert.IsFalse(secondTest.Test.IsSuite);
            Assert.IsFalse(secondTest.Test.HasChildren);

            SelectedItemChangedEventArgs firstArgs  = new SelectedItemChangedEventArgs(firstTest, 0);
            SelectedItemChangedEventArgs secondArgs = new SelectedItemChangedEventArgs(secondTest, 0);

            TestsPageForTest page = new TestsPageForTest(runner);

            // Load first page
            page.InvokeOnItemSelected(null, firstArgs);

            Assert.AreEqual(1, page.NavigationStack.Count);
            TestDetailPage firstTestsPage = page.NavigationStack.First() as TestDetailPage;

            Assert.IsNotNull(firstTestsPage);
            Assert.AreEqual(firstTest, firstTestsPage.ViewModel);
            Assert.AreEqual(runner, firstTestsPage.ViewModel.TestRunner);
            Assert.AreEqual(firstTestInstance, firstTestsPage.ViewModel.Test);

            // Load second page
            page.InvokeOnItemSelected(null, secondArgs);

            Assert.AreEqual(2, page.NavigationStack.Count);
            TestDetailPage secondTestsPage = page.NavigationStack[1] as TestDetailPage;

            Assert.IsNotNull(secondTestsPage);
            Assert.AreEqual(secondTest, secondTestsPage.ViewModel);
            Assert.AreEqual(runner, secondTestsPage.ViewModel.TestRunner);
            Assert.AreEqual(secondTestInstance, secondTestsPage.ViewModel.Test);

            // Load first page again
            IList <Page> expectedStack = new List <Page>(page.NavigationStack);

            expectedStack.Add(firstTestsPage);

            page.InvokeOnItemSelected(null, firstArgs);

            Assert.AreEqual(3, page.NavigationStack.Count);
            Assert.AreSame(firstTestsPage, page.NavigationStack[2]);
            CollectionAssert.AreEqual(expectedStack, page.NavigationStack);
        }
예제 #5
0
        public MainPage()
        {
            InitializeComponent();

            // TODO - Initialize test runner and add test assembly references
            NUnitRunner runner = new NUnitRunner(GetType().Namespace);

            runner.AddTestAssembly(typeof(Test.Stub.TestFixtureStubOne).Assembly);

            XamarinNUnitRunner.App app = new XamarinNUnitRunner.App(runner);
            LoadApplication(app);
        }
예제 #6
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Xamarin.Forms.Forms.Init();

            // TODO - Initialize test runner and add test assembly references
            NUnitRunner runner = new NUnitRunner(GetType().Namespace);

            runner.AddTestAssembly(typeof(Test.Stub.TestFixtureStubOne).Assembly);

            LoadApplication(new App(runner));

            return(base.FinishedLaunching(app, options));
        }
예제 #7
0
        public void TestOnAppearingLoadsTests()
        {
            NUnitRunner runner = new NUnitRunner("runner-name");

            runner.AddTestAssembly(typeof(TestFixtureStubOne).Assembly);

            TestsPageForTest page = new TestsPageForTest(runner);

            CollectionAssert.IsEmpty(page.ViewModel.Tests);
            Assert.IsNull(page.ViewModel?.Result?.Result);

            page.InvokeOnAppearing();

            while (page.ViewModel.IsBusy)
            {
                Thread.Sleep(10);
            }

            CollectionAssert.IsNotEmpty(page.ViewModel.Tests);

            page.ViewModel.Result = new NUnitTestResult(new TestSuiteResult(runner.TestSuite));

            IList <TestsViewModel> tests = new List <TestsViewModel>(page.ViewModel.Tests);

            runner.AddTestAssembly(GetType().Assembly);

            page.InvokeOnAppearing();

            while (page.ViewModel.IsBusy)
            {
                Thread.Sleep(10);
            }

            CollectionAssert.AreEquivalent(tests, page.ViewModel.Tests);
            Assert.IsNotNull(page.ViewModel.Result.Result);
            CollectionAssert.IsNotEmpty(page.ViewModel.Tests.Select(x => x.Result));
        }
예제 #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);

            // TODO - Initialize test runner and add test assembly references
            NUnitRunner runner = new NUnitRunner(GetType().Namespace);

            runner.AddTestAssembly(typeof(Test.Stub.TestFixtureStubOne).Assembly);

            LoadApplication(new App(runner));
        }
        public void TestRunTestsClickedRunsTests()
        {
            NUnitRunner runner = new NUnitRunner("runner-name");

            runner.AddTestAssembly(typeof(TestFixtureStubOne).Assembly);
            TestsViewModel test = new TestsViewModel(runner, new NUnitSuite("suite-name"));

            TestDetailPageForTest page = new TestDetailPageForTest(test);

            Assert.IsNotNull(page.ViewModel.Result);
            Assert.IsNull(page.ViewModel.Result.Result);

            page.InvokeRunTestsClicked(this, EventArgs.Empty);

            while (page.ViewModel.IsBusy)
            {
                Thread.Sleep(10);
            }

            Assert.IsNotNull(page.ViewModel.Result);
        }
예제 #10
0
        public void TestReloadResultsCommandReloadsTestResults([Values] bool withTest, [Values] bool withResults,
                                                               [Values] bool withAdditionalTests)
        {
            int         invocationCount = 0;
            NUnitRunner runner          = new NUnitRunner("runner-name");

            runner.AddTestAssembly(typeof(TestFixtureStubOne).Assembly);
            int expectedRunnerCount = withAdditionalTests ? 2 : 1;

            if (withAdditionalTests)
            {
                runner.AddTestAssembly(GetType().Assembly);
            }

            Assert.AreEqual(expectedRunnerCount, runner.TestSuite.TestAssemblyRunners.Count);

            ITest testInstance = runner.TestSuite;
            ITest test         = withTest ? testInstance : null;

            TestsViewModel model = new TestsViewModel(runner, test);

            ITestFilter        filter          = NUnitFilter.Where.Class(typeof(TestFixtureStubOne).Namespace).Build().Filter;
            ITestResult        expectedResult  = withResults ? runner.RunTests(null, filter) : null;
            List <ITestResult> expectedResults = new List <ITestResult>();

            model.Result = withResults ? new NUnitTestResult(expectedResult) : null;
            if (withResults)
            {
                expectedResults.AddRange(expectedResult.Children);
            }
            else
            {
                expectedResults.Add(null);
                if (withAdditionalTests)
                {
                    expectedResults.Add(null);
                }
            }

            model.LoadTestsCommand.Execute(null);

            WaitForCommand(model);

            model.PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case "IsBusy":
                    invocationCount++;
                    break;
                }
            };

            model.ReloadResultsCommand.Execute(null);

            WaitForCommand(model);

            Assert.IsFalse(model.IsBusy);
            Assert.AreEqual(2, invocationCount);
            Assert.IsNotNull(model.Test);
            Assert.AreEqual(testInstance, model.Test);

            IList <ITest> actualTests = model.Tests.Select(x => x.Test).ToList();

            // Matching test is not the root, so search for the test instance with the namespace of the test fixture
            IList <ITest> foundTests = new List <ITest>();
            int           skipCount  = 0;
            ITest         foundTest  = GetTestByName(testInstance, typeof(TestFixtureStubOne).Namespace, ref skipCount);

            foundTests.Add(foundTest);

            // Matching result is not the root, so search for the result instance with the namespace of the test fixture
            skipCount = 0;
            IList <ITestResult> foundResults = expectedResults
                                               .Select(result => GetTestResultByName(result, typeof(TestFixtureStubOne).Namespace, ref skipCount))
                                               .ToList();

            if (withAdditionalTests)
            {
                // Matching test is not the root, so search for the test instance with the namespace of the test fixture
                // Skip the first found match as the namespace is a sub-space of another
                // The first found is x.y of sub-space x.y.z, but the actual is just x.y with no sub-space
                skipCount = 1;
                foundTest = GetTestByName(testInstance, GetType().Assembly.GetName().Name, ref skipCount);
                foundTests.Add(foundTest);
            }

            CollectionAssert.AreEquivalent(foundTests, actualTests);

            IList <ITestResult> actualResults = model.Tests.Select(x => x.Result.Result).ToList();

            CollectionAssert.AreEquivalent(foundResults, actualResults);
            Assert.AreEqual(expectedResult, model.Result?.Result);
        }