public void TestFixtureSetUp()
        {
            NamingConventionDialogTypeLocator.Cache.Clear();

            var assemblyBuilder = new TestAssemblyBuilder("TestAssembly");

            // Create types used in tests
            assemblyBuilder.CreateType("TestAssembly.DialogViewModel", typeof(ViewModelBase));
            assemblyBuilder.CreateType("TestAssembly.Dialog");

            assemblyBuilder.CreateType("TestAssembly.ViewModels.DialogViewModel", typeof(ViewModelBase));
            assemblyBuilder.CreateType("TestAssembly.Views.Dialog");

            assemblyBuilder.CreateType("TestAssembly.ViewModels.Module.DialogViewModel", typeof(ViewModelBase));
            assemblyBuilder.CreateType("TestAssembly.Views.Module.Dialog");

            assemblyBuilder.CreateType("TestAssembly.Module.ViewModels.DialogViewModel", typeof(ViewModelBase));
            assemblyBuilder.CreateType("TestAssembly.Module.Views.Dialog");

            assemblyBuilder.CreateType("TestAssembly.ModuleWithoutViewNamespace.ViewModel.DialogViewModel", typeof(ViewModelBase));

            assemblyBuilder.CreateType("TestAssembly.UnconventionalNamespace.DialogViewModel", typeof(ViewModelBase));

            // Create assembly
            testAssembly = assemblyBuilder.Build();
        }
Ejemplo n.º 2
0
        public void AssemblyObjectHasClassList()
        {
            StubExecutorWrapper wrapper = CreateStubExecutor();

            TestAssembly assembly = TestAssemblyBuilder.Build(wrapper);

            var testClasses = assembly.EnumerateClasses();

            Assert.Equal(2, testClasses.Count());
            TestClass testClass = testClasses.First();

            Assert.Equal("ThisIsTheType", testClass.TypeName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build a suite based on a TestPackage
        /// </summary>
        /// <param name="package">The TestPackage</param>
        /// <returns>A TestSuite</returns>
        public TestSuite Build(TestPackage package)
        {
            bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true);
            bool mergeAssemblies     = package.GetSetting("MergeAssemblies", false);

            if (package.IsSingleAssembly)
            {
                return(BuildSingleAssembly(package));
            }

            TestSuite            rootSuite     = new TestSuite(package.FullName);
            NamespaceTreeBuilder namespaceTree =
                new NamespaceTreeBuilder(rootSuite);

            builders.Clear();
            foreach (string assemblyName in package.Assemblies)
            {
                TestAssemblyBuilder builder = new TestAssemblyBuilder();
                builders.Add(builder);

                Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies);

                if (testAssembly != null)
                {
                    if (!mergeAssemblies)
                    {
                        rootSuite.Add(testAssembly);
                    }
                    else if (autoNamespaceSuites)
                    {
                        namespaceTree.Add(testAssembly.Tests);
                        rootSuite = namespaceTree.RootSuite;
                    }
                    else
                    {
                        foreach (Test test in testAssembly.Tests)
                        {
                            rootSuite.Add(test);
                        }
                    }
                }
            }

            if (rootSuite.Tests.Count == 0)
            {
                return(null);
            }

            return(rootSuite);
        }
Ejemplo n.º 4
0
        public void ExcludingCategoryDoesNotRunExplicitTestFixtures()
        {
            TestFilter          filter     = new NotFilter(new CategoryFilter("MockCategory"));
            TestAssemblyBuilder builder    = new TestAssemblyBuilder();
            TestSuite           suite      = builder.Build("mock-assembly.dll", true);
            TestResult          result     = suite.Run(NullListener.NULL, filter);
            ResultSummarizer    summarizer = new ResultSummarizer(result);

            Assert.AreEqual(MockAssembly.Tests - MockAssembly.NotRun - 2, summarizer.ResultCount);
            Console.WriteLine("{0} ignored, {1} explicit, {2} not run",
                              MockAssembly.Ignored, MockAssembly.Explicit, MockAssembly.NotRun);
            Console.WriteLine("{0} tests were run out of {1}",
                              MockAssembly.Tests - MockAssembly.NotRun - 2, MockAssembly.Tests);
        }
Ejemplo n.º 5
0
        private TestSuite BuildSingleAssembly(TestPackage package)
        {
            TestAssemblyBuilder builder = new TestAssemblyBuilder();

            builders.Clear();
            builders.Add(builder);

            TestSuite suite = (TestSuite)builder.Build(
                package.FullName,
                package.TestName, package.GetSetting("AutoNamespaceSuites", true));

            ProviderCache.Clear();

            return(suite);
        }
		    public static int Main(string[] args)
            {
                var testAssembly = TestAssemblyBuilder.Build(
                    new ExecutorWrapper(args[0], null, false));
                var tests = testAssembly.EnumerateTestMethods(x =>  x
                    .DisplayName
                    .ToLowerInvariant();
                var testMethods = (args.Length > 1 && !string.IsNullOrEmpty(args[1])
                    ? tests.Contains(args[1].ToLowerInvariant())).ToList()
                    : tests.ToList();
                if (testMethods.Count == 0)
				    return 0;
                var runnerCallback = new TestMethodRunnerCallback();
                testAssembly.Run(testMethods, runnerCallback);
                return runnerCallback.FailedCount;
            }
Ejemplo n.º 7
0
        public void CanLoadAssemblyAtRelativeDirectoryLocation()
        {
            DirectoryInfo current   = new DirectoryInfo(Environment.CurrentDirectory);
            string        dir       = current.Name;
            string        parentDir = current.Parent.FullName;

            try
            {
                Environment.CurrentDirectory = parentDir;
                TestAssemblyBuilder builder = new TestAssemblyBuilder();
                Assert.IsNotNull(builder.Build(dir + Path.DirectorySeparatorChar + "mock-assembly.dll", false));
            }
            finally
            {
                Environment.CurrentDirectory = current.FullName;
            }
        }
Ejemplo n.º 8
0
        public void DoRunTests()
        {
            var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            try
            {
                using (var wrapper = new ExecutorWrapper(executingAssembly.Location, null, true))
                {
                    var assembly = TestAssemblyBuilder.Build(wrapper);
                    var methods  = assembly
                                   .EnumerateTestMethods()
                                   .ToList();

                    var activeMethods = methods
                                        .Where(m =>
                                               UseFirefox && m.TestClass.TypeName.Contains("Firefox") ||
                                               UseChrome && m.TestClass.TypeName.Contains("Chrome") ||
                                               UseInternetExplorer && m.TestClass.TypeName.Contains("Internet") ||
                                               UsePhantomJs && m.TestClass.TypeName.Contains("Phantom")
                                               )
                                        .ToList();

                    if (activeMethods.Count > 0)
                    {
                        assembly.Run(activeMethods, this);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            finally
            {
                Application.Current.Dispatcher.BeginInvoke((Action)(DoDone));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Build a suite based on a TestPackage
        /// </summary>
        /// <param name="package">The TestPackage</param>
        /// <returns>A TestSuite</returns>
        public TestSuite Build(TestPackage package)
        {
            bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true);
            bool mergeAssemblies     = package.GetSetting("MergeAssemblies", false);

            TestExecutionContext.CurrentContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0);

            if (package.IsSingleAssembly)
            {
                return(BuildSingleAssembly(package));
            }
            string targetAssemblyName = null;

            if (package.TestName != null && package.Assemblies.Contains(package.TestName))
            {
                targetAssemblyName = package.TestName;
                package.TestName   = null;
            }

            TestSuite            rootSuite     = new ProjectRootSuite(package.FullName);
            NamespaceTreeBuilder namespaceTree =
                new NamespaceTreeBuilder(rootSuite);

            builders.Clear();
            foreach (string assemblyName in package.Assemblies)
            {
                if (targetAssemblyName == null || targetAssemblyName == assemblyName)
                {
                    TestAssemblyBuilder builder = new TestAssemblyBuilder();
                    builders.Add(builder);

                    Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies);

                    if (testAssembly != null)
                    {
                        if (!mergeAssemblies)
                        {
                            rootSuite.Add(testAssembly);
                        }
                        else if (autoNamespaceSuites)
                        {
                            namespaceTree.Add(testAssembly.Tests);
                            rootSuite = namespaceTree.RootSuite;
                        }
                        else
                        {
                            foreach (Test test in testAssembly.Tests)
                            {
                                rootSuite.Add(test);
                            }
                        }
                    }
                }
            }

            ProviderCache.Clear();

            if (rootSuite.Tests.Count == 0)
            {
                return(null);
            }

            return(rootSuite);
        }
Ejemplo n.º 10
0
        public void CanLoadAssemblyInCurrentDirectory()
        {
            TestAssemblyBuilder builder = new TestAssemblyBuilder();

            Assert.IsNotNull(builder.Build("mock-assembly.dll", false));
        }