private FacadeTestRunState RunType(IFacadeTestListener testListener, string assemblyPath, string typeName, FacadeOptions facadeOptions)
 {
     return(Run(testListener, assemblyPath, new AndFilter <ITestDescriptor>(new Filter <ITestDescriptor>[]
     {
         new TypeFilter <ITestDescriptor>(new EqualityFilter <string>(typeName), true)
     }), facadeOptions));
 }
 private FacadeTestRunState RunNamespace(IFacadeTestListener testListener, string assemblyPath, string @namespace, FacadeOptions facadeOptions)
 {
     return(Run(testListener, assemblyPath, new AndFilter <ITestDescriptor>(new Filter <ITestDescriptor>[]
     {
         new NamespaceFilter <ITestDescriptor>(new EqualityFilter <string>(@namespace))
     }), facadeOptions));
 }
        /// <summary>
        /// Inform the user that no tests were run and the reason for it. TD.NET displays
        /// a message like "0 Passed, 0 Failed, 0 Skipped" but it does it in the status bar,
        /// which may be harder to notice for the user. Be aware that this message will
        /// only be displayed when the user runs an individual test or fixture (TD.NET
        /// ignores the messages we send when it's running an entire assembly).
        /// </summary>
        /// <param name="testListener">An ITestListener object to write the message to.</param>
        /// <param name="reason">The reason no tests were run for.</param>
        private static void InformNoTestsWereRun(IFacadeTestListener testListener, string reason)
        {
            reason = String.IsNullOrEmpty(reason) ? String.Empty : " (" + reason + ")";
            string message = String.Format("** {0}{1} **", Resources.MbUnitTestRunner_NoTestsWereRun, reason);

            testListener.WriteLine(message, FacadeCategory.Warning);
        }
        public TDNetExtension(IFacadeTestListener testListener)
        {
            if (testListener == null)
                throw new ArgumentNullException(@"testListener");

            this.testListener = testListener;
        }
Beispiel #5
0
        public TDNetExtension(IFacadeTestListener testListener)
        {
            if (testListener == null)
            {
                throw new ArgumentNullException(@"testListener");
            }

            this.testListener = testListener;
        }
 public FacadeTestRunState Run(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
 {
     try
     {
         return RunImpl(testListener, assemblyPath, cref, facadeOptions);
     }
     catch (Exception ex)
     {
         throw ServerExceptionUtils.Wrap(ex);
     }
 }
 public FacadeTestRunState Run(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
 {
     try
     {
         return(RunImpl(testListener, assemblyPath, cref, facadeOptions));
     }
     catch (Exception ex)
     {
         throw ServerExceptionUtils.Wrap(ex);
     }
 }
        protected override FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
        {
            if (cref == null)
            {
                return(RunAssembly(testListener, assemblyPath, facadeOptions));
            }

            if (cref.Length >= 2)
            {
                char descriptor = cref[0];

                switch (descriptor)
                {
                case 'T':
                    return(RunType(testListener, assemblyPath, cref.Substring(2), facadeOptions));

                case 'N':
                    return(RunNamespace(testListener, assemblyPath, cref.Substring(2), facadeOptions));

                case 'M':
                case 'F':
                case 'P':
                case 'E':
                    int paramsPos = cref.IndexOf('(');
                    if (paramsPos < 0)
                    {
                        paramsPos = cref.Length;
                    }

                    string memberNameWithType = cref.Substring(2, paramsPos - 2);
                    int    memberPos          = memberNameWithType.LastIndexOf('.');
                    if (memberPos < 0)
                    {
                        break;
                    }

                    string typeName   = memberNameWithType.Substring(0, memberPos);
                    string memberName = memberNameWithType.Substring(memberPos + 1);
                    return(RunMember(testListener, assemblyPath, typeName, memberName, facadeOptions));
                }
            }

            return(FacadeTestRunState.NoTests);
        }
        /// <inheritdoc />
        protected override FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
        {
            string versionLabel = VersionPolicy.GetVersionLabel(Assembly.GetExecutingAssembly());
            testListener.WriteLine(String.Format(Resources.RunnerNameAndVersion + "\n", versionLabel), FacadeCategory.Info);

            switch (facadeOptions.FilterCategoryMode)
            {
                case FacadeFilterCategoryMode.Include:
                    testListener.WriteLine(String.Format("Included categories: {0}\n", CombineCategoryNameList(facadeOptions.FilterCategoryNames)), FacadeCategory.Info);
                    break;

                case FacadeFilterCategoryMode.Exclude:
                    testListener.WriteLine(String.Format("Excluded categories: {0}\n", CombineCategoryNameList(facadeOptions.FilterCategoryNames)), FacadeCategory.Info);
                    break;
            }

            EnsureTestRunnerIsCreated();
            return testRunner.Run(testListener, assemblyPath, cref, facadeOptions);
        }
Beispiel #10
0
        /// <inheritdoc />
        protected override FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
        {
            string versionLabel = VersionPolicy.GetVersionLabel(Assembly.GetExecutingAssembly());

            testListener.WriteLine(String.Format(Resources.RunnerNameAndVersion + "\n", versionLabel), FacadeCategory.Info);

            switch (facadeOptions.FilterCategoryMode)
            {
            case FacadeFilterCategoryMode.Include:
                testListener.WriteLine(String.Format("Included categories: {0}\n", CombineCategoryNameList(facadeOptions.FilterCategoryNames)), FacadeCategory.Info);
                break;

            case FacadeFilterCategoryMode.Exclude:
                testListener.WriteLine(String.Format("Excluded categories: {0}\n", CombineCategoryNameList(facadeOptions.FilterCategoryNames)), FacadeCategory.Info);
                break;
            }

            EnsureTestRunnerIsCreated();
            return(testRunner.Run(testListener, assemblyPath, cref, facadeOptions));
        }
        protected override FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions)
        {
            if (cref == null)
                return RunAssembly(testListener, assemblyPath, facadeOptions);

            if (cref.Length >= 2)
            {
                char descriptor = cref[0];

                switch (descriptor)
                {
                    case 'T':
                        return RunType(testListener, assemblyPath, cref.Substring(2), facadeOptions);

                    case 'N':
                        return RunNamespace(testListener, assemblyPath, cref.Substring(2), facadeOptions);

                    case 'M':
                    case 'F':
                    case 'P':
                    case 'E':
                        int paramsPos = cref.IndexOf('(');
                        if (paramsPos < 0)
                            paramsPos = cref.Length;

                        string memberNameWithType = cref.Substring(2, paramsPos - 2);
                        int memberPos = memberNameWithType.LastIndexOf('.');
                        if (memberPos < 0)
                            break;

                        string typeName = memberNameWithType.Substring(0, memberPos);
                        string memberName = memberNameWithType.Substring(memberPos + 1);
                        return RunMember(testListener, assemblyPath, typeName, memberName, facadeOptions);
                }
            }

            return FacadeTestRunState.NoTests;
        }
 protected abstract FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions);
 protected abstract FacadeTestRunState RunImpl(IFacadeTestListener testListener, string assemblyPath, string cref, FacadeOptions facadeOptions);
        private FacadeTestRunState Run(IFacadeTestListener testListener, string assemblyPath, Filter <ITestDescriptor> filter, FacadeOptions facadeOptions)
        {
            if (testListener == null)
            {
                throw new ArgumentNullException(@"testListener");
            }
            if (assemblyPath == null)
            {
                throw new ArgumentNullException("assemblyPath");
            }
            if (facadeOptions == null)
            {
                throw new ArgumentNullException("facadeOptions");
            }

            ILogger logger = new FilteredLogger(new TDNetLogger(testListener), LogSeverity.Info);

            try
            {
                RuntimeAccessor.Instance.AddLogListener(logger);
                var filterRules = new List <FilterRule <ITestDescriptor> >();

                switch (facadeOptions.FilterCategoryMode)
                {
                case FacadeFilterCategoryMode.Disabled:
                    filterRules.Add(new FilterRule <ITestDescriptor>(FilterRuleType.Inclusion, filter));
                    break;

                case FacadeFilterCategoryMode.Include:
                    filterRules.Add(new FilterRule <ITestDescriptor>(FilterRuleType.Inclusion,
                                                                     new AndFilter <ITestDescriptor>(new[] { filter, ToCategoryFilter(facadeOptions.FilterCategoryNames) })));
                    break;

                case FacadeFilterCategoryMode.Exclude:
                    filterRules.Add(new FilterRule <ITestDescriptor>(FilterRuleType.Exclusion, ToCategoryFilter(facadeOptions.FilterCategoryNames)));
                    filterRules.Add(new FilterRule <ITestDescriptor>(FilterRuleType.Inclusion, filter));
                    break;
                }

                var filterSet = new FilterSet <ITestDescriptor>(filterRules);
                launcher.Logger = logger;
                launcher.ProgressMonitorProvider           = new LogProgressMonitorProvider(logger);
                launcher.TestExecutionOptions.FilterSet    = filterSet;
                launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.IsolatedAppDomain;
                launcher.TestProject.AddTestRunnerExtension(new TDNetExtension(testListener)); // This monitor will inform the user in real-time what's going on
                launcher.TestProject.TestPackage.AddFile(new FileInfo(assemblyPath));
                string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(assemblyDirectory);
                launcher.TestProject.TestPackage.WorkingDirectory         = new DirectoryInfo(assemblyDirectory);
                TestLauncherResult result          = RunLauncher(launcher);
                string             reportDirectory = GetReportDirectory(logger);

                if (reportDirectory != null)
                {
                    var reportFormatterOptions = new ReportFormatterOptions();
                    var preferenceManager      = (TDNetPreferenceManager)RuntimeAccessor.ServiceLocator.ResolveByComponentId("TDNetRunner.PreferenceManager");
                    var reportFormat           = preferenceManager.ReportSettings.DetermineReportFormat(result.Report);
                    result.GenerateReports(reportDirectory, Path.GetFileName(assemblyPath), ReportArchive.Normal,
                                           new[] { reportFormat }, reportFormatterOptions,
                                           RuntimeAccessor.ServiceLocator.Resolve <IReportManager>(), NullProgressMonitor.CreateInstance());

                    // This will generate a link to the generated report
                    if (result.ReportDocumentPaths.Count != 0)
                    {
                        Uri    rawUrl     = new Uri(result.ReportDocumentPaths[0]);
                        string displayUrl = "file:///" + rawUrl.LocalPath.Replace(" ", "%20").Replace(@"\", "/");

                        // TDNet just prints the link on its own but it's not always clear to users what it represents.
                        // testListener.TestResultsUrl(displayUrl);
                        testListener.WriteLine("\nTest Report: " + displayUrl, FacadeCategory.Info);
                    }
                }

                // Inform no tests run, if necessary.
                if (result.ResultCode == ResultCode.NoTests)
                {
                    InformNoTestsWereRun(testListener, Resources.MbUnitTestRunner_NoTestsFound);
                }
                else if (result.Statistics.TestCount == 0)
                {
                    InformNoTestsWereRun(testListener, null);
                }

                return(GetTestRunState(result));
            }
            finally
            {
                RuntimeAccessor.Instance.RemoveLogListener(logger);
            }
        }
 private FacadeTestRunState RunMember(IFacadeTestListener testListener, string assemblyPath, string typeName, string memberName, FacadeOptions facadeOptions)
 {
     return Run(testListener, assemblyPath, new AndFilter<ITestDescriptor>(new Filter<ITestDescriptor>[] 
     { 
         new TypeFilter<ITestDescriptor>(new EqualityFilter<string>(typeName), true), 
         new MemberFilter<ITestDescriptor>(new EqualityFilter<string>(memberName)) 
     }), facadeOptions);
 }
 private FacadeTestRunState RunAssembly(IFacadeTestListener testListener, string assemblyPath, FacadeOptions facadeOptions)
 {
     return(Run(testListener, assemblyPath, new AnyFilter <ITestDescriptor>(), facadeOptions));
 }
 private FacadeTestRunState RunAssembly(IFacadeTestListener testListener, string assemblyPath, FacadeOptions facadeOptions)
 {
     return Run(testListener, assemblyPath, new AnyFilter<ITestDescriptor>(), facadeOptions);
 }
 /// <summary>
 /// Inform the user that no tests were run and the reason for it. TD.NET displays
 /// a message like "0 Passed, 0 Failed, 0 Skipped" but it does it in the status bar,
 /// which may be harder to notice for the user. Be aware that this message will
 /// only be displayed when the user runs an individual test or fixture (TD.NET
 /// ignores the messages we send when it's running an entire assembly).
 /// </summary>
 /// <param name="testListener">An ITestListener object to write the message to.</param>
 /// <param name="reason">The reason no tests were run for.</param>
 private static void InformNoTestsWereRun(IFacadeTestListener testListener, string reason)
 {
     reason = String.IsNullOrEmpty(reason) ? String.Empty : " (" + reason + ")";
     string message = String.Format("** {0}{1} **", Resources.MbUnitTestRunner_NoTestsWereRun, reason);
     testListener.WriteLine(message, FacadeCategory.Warning);
 }
        private FacadeTestRunState Run(IFacadeTestListener testListener, string assemblyPath, Filter<ITestDescriptor> filter, FacadeOptions facadeOptions)
        {
            if (testListener == null)
                throw new ArgumentNullException(@"testListener");
            if (assemblyPath == null)
                throw new ArgumentNullException("assemblyPath");
            if (facadeOptions == null)
                throw new ArgumentNullException("facadeOptions");

            ILogger logger = new FilteredLogger(new TDNetLogger(testListener), LogSeverity.Info);

            try
            {
                RuntimeAccessor.Instance.AddLogListener(logger);
                var filterRules = new List<FilterRule<ITestDescriptor>>();

                switch (facadeOptions.FilterCategoryMode)
                {
                    case FacadeFilterCategoryMode.Disabled:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion, filter));
                        break;

                    case FacadeFilterCategoryMode.Include:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion,
                            new AndFilter<ITestDescriptor>(new[] { filter, ToCategoryFilter(facadeOptions.FilterCategoryNames) })));
                        break;

                    case FacadeFilterCategoryMode.Exclude:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Exclusion, ToCategoryFilter(facadeOptions.FilterCategoryNames)));
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion, filter));
                        break;
                }

                var filterSet = new FilterSet<ITestDescriptor>(filterRules);
                launcher.Logger = logger;
                launcher.ProgressMonitorProvider = new LogProgressMonitorProvider(logger);
                launcher.TestExecutionOptions.FilterSet = filterSet;
                launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.IsolatedAppDomain;
                launcher.TestProject.AddTestRunnerExtension(new TDNetExtension(testListener)); // This monitor will inform the user in real-time what's going on
                launcher.TestProject.TestPackage.AddFile(new FileInfo(assemblyPath));
                string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(assemblyDirectory);
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(assemblyDirectory);
                TestLauncherResult result = RunLauncher(launcher);
                string reportDirectory = GetReportDirectory(logger);

                if (reportDirectory != null)
                {
                    var reportFormatterOptions = new ReportFormatterOptions();
                    var preferenceManager = (TDNetPreferenceManager)RuntimeAccessor.ServiceLocator.ResolveByComponentId("TDNetRunner.PreferenceManager");
                    var reportFormat = preferenceManager.ReportSettings.DetermineReportFormat(result.Report);
                    result.GenerateReports(reportDirectory, Path.GetFileName(assemblyPath), ReportArchive.Normal,
                        new[] { reportFormat }, reportFormatterOptions,
                        RuntimeAccessor.ServiceLocator.Resolve<IReportManager>(), NullProgressMonitor.CreateInstance());

                    // This will generate a link to the generated report
                    if (result.ReportDocumentPaths.Count != 0)
                    {
                        Uri rawUrl = new Uri(result.ReportDocumentPaths[0]);
                        string displayUrl = "file:///" + rawUrl.LocalPath.Replace(" ", "%20").Replace(@"\", "/");

                        // TDNet just prints the link on its own but it's not always clear to users what it represents.
                        // testListener.TestResultsUrl(displayUrl);
                        testListener.WriteLine("\nTest Report: " + displayUrl, FacadeCategory.Info);
                    }
                }

                // Inform no tests run, if necessary.
                if (result.ResultCode == ResultCode.NoTests)
                {
                    InformNoTestsWereRun(testListener, Resources.MbUnitTestRunner_NoTestsFound);
                }
                else if (result.Statistics.TestCount == 0)
                {
                    InformNoTestsWereRun(testListener, null);
                }

                return GetTestRunState(result);
            }
            finally
            {
                RuntimeAccessor.Instance.RemoveLogListener(logger);
            }
        }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the TDNetLogger class.
 /// </summary>
 /// <param name="testListener">An ITestListener object where the
 /// messages will be written to.</param>
 public TDNetLogger(IFacadeTestListener testListener)
 {
     this.testListener = testListener;
 }
Beispiel #21
0
 /// <summary>
 /// Initializes a new instance of the TDNetLogger class.
 /// </summary>
 /// <param name="testListener">An ITestListener object where the
 /// messages will be written to.</param>
 public TDNetLogger(IFacadeTestListener testListener)
 {
     this.testListener = testListener;
 }
 private FacadeTestRunState RunNamespace(IFacadeTestListener testListener, string assemblyPath, string @namespace, FacadeOptions facadeOptions)
 {
     return Run(testListener, assemblyPath, new AndFilter<ITestDescriptor>(new Filter<ITestDescriptor>[]
     {
         new NamespaceFilter<ITestDescriptor>(new EqualityFilter<string>(@namespace))
     }), facadeOptions);
 }