Exemplo n.º 1
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);
        }
        public void TestConstructorWithNUnitRunner([Values] bool isRunnerNull, [Values] bool isTestNull)
        {
            NUnitRunner    runner = isRunnerNull ? null : new NUnitRunner("runner-name");
            TestsViewModel test   = isTestNull ? null : new TestsViewModel(runner, new NUnitSuite("suite-name"));

            TestDetailPage page = new TestDetailPage(test, false);

            Assert.AreSame(test, page.ViewModel);
            Assert.AreSame(test?.TestRunner, page.ViewModel?.TestRunner);
            Assert.AreSame(test?.Test, page.ViewModel?.Test);
        }