public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();
            try
            {
                var report = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                testReport.AddResult(TestCaseResultFactory.CreateFailed());
                testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                File.ReadAllText(tempFileName).Trace();

                string xmlSchemaPath = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\vstst.xsd";
                IList<string> validationErrors = new List<string>();
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, File.ReadAllText(xmlSchemaPath), out validationErrors);

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                validationErrors.Count.ShouldEqual(0);
            }
            catch (Exception)
            {
                if(File.Exists(tempFileName))
                    File.Delete(tempFileName);
                throw;
            }
        }
Exemple #2
0
        public void Should_spit_out_valid_MSTest_trx()
        {
            var report     = new TestReportCollection();
            var testReport = new TestReport(@"C:\Test.xap");

            testReport.AddResult(TestCaseResultFactory.CreatePassed());
            testReport.AddResult(TestCaseResultFactory.CreateFailed());
            //testReport.AddResult(TestCaseResultFactory.CreateIgnored());
            report.Add(testReport);

            report
            .AllTests()
            .Where(w => w.ResultType == ResultType.Failed)
            .Each(x => x.ExceptionInfo.StackTrace = "Some message that will be a stacktrace");

            var testSettings = new TestSettings();

            testSettings.ComputerName = "UserName-LT3";
            var trxReport = new TRXReport(report, new MockGuidSequenceGenerator(), testSettings);
            var output    = trxReport.GetXmlReport();

            var memoryStream = new MemoryStream();

            using (var writer = new StreamWriter(memoryStream))
            {
                var xml = output;
                xml.Save(writer);
                writer.Close();
            }

            string fileData         = memoryStream.ToArray().ToStringFromByteArray();
            string expectedFileData = Resources.SampleTRX_GeneratedFromRealTest.Trim();

            // replace the hard coded credentials with the current domain and user name
            expectedFileData = expectedFileData.Replace(@"DOMAIN\UserName", string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName));

            FixupRegEx("duration=\"00:00:00.0000000\"", ref expectedFileData, ref fileData,
                       @"duration=\""[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\""");

            FixupRegEx("startTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                       @"startTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][-+][0-9][0-9]:[0-9][0-9]\""");

            FixupRegEx("endTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                       @"endTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][-+][0-9][0-9]:[0-9][0-9]\""");

            //fileData.Trace();
            //expectedFileData.Trace();
            fileData.ShouldEqual(expectedFileData);
        }
Exemple #3
0
        private void TryRun()
        {
            _isRunning = true;
            var       testReportCollection = new TestReportCollection();
            Stopwatch multiRunStopwatch    = Stopwatch.StartNew();

            while (_queuedRuns.Count > 0)
            {
                XapFileBuildChangedServerEvent buildEvent;

                lock (_sync)
                {
                    buildEvent = _queuedRuns.Dequeue();
                }

                var xapPath = buildEvent.XapPath;

                _currentStatLightConfiguration.SetCurrentTo(xapPath);

                _currentStatLightConfiguration.Current.Client.TagFilter = _currentFilterString;

                using (var onetimeRunner = new OnetimeRunner(
                           logger: _logger,
                           eventSubscriptionManager: _eventSubscriptionManager,
                           eventPublisher: _eventPublisher,
                           webServer: _webServer,
                           webBrowsers: _webBrowsers,
                           xapPath: xapPath,
                           dialogMonitorRunner: _dialogMonitorRunner))
                {
                    Stopwatch  singleRunStopwatch = Stopwatch.StartNew();
                    TestReport testReport         = onetimeRunner.Run();
                    singleRunStopwatch.Stop();
                    testReportCollection.Add(testReport);
                    _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, singleRunStopwatch.Elapsed, shouldPrintSummary: _statLightConfigurations.Count > 1));
                }
            }

            multiRunStopwatch.Stop();
            _isRunning = false;

            if (testReportCollection.Any())
            {
                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReportCollection, multiRunStopwatch.Elapsed));
            }
        }
Exemple #4
0
        public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                var report     = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                //testReport.AddResult(TestCaseResultFactory.CreateFailed());
                //testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                //File.ReadAllText(tempFileName).Trace();

                var            xmlSchema = Resources.vstst;
                IList <string> validationErrors;
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, xmlSchema, out validationErrors);

                tempFileName.Trace();

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                if (validationErrors.Any())
                {
                    Assert.Fail("Validation Errors:{0}{1}".FormatWith(Environment.NewLine, string.Join(Environment.NewLine, validationErrors)));
                }
            }
            catch (Exception)
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
                throw;
            }
        }
        public void Should_spit_out_valid_MSTest_trx()
        {
            var report = new TestReportCollection();
            var testReport = new TestReport(@"C:\Test.xap");
            testReport.AddResult(TestCaseResultFactory.CreatePassed());
            testReport.AddResult(TestCaseResultFactory.CreateFailed());
            //testReport.AddResult(TestCaseResultFactory.CreateIgnored());
            report.Add(testReport);

            report
                .AllTests()
                .Where(w => w.ResultType == ResultType.Failed)
                .Each(x => x.ExceptionInfo.StackTrace = "Some message that will be a stacktrace");

            var testSettings = new TestSettings();
            testSettings.ComputerName = "UserName-LT3";
            var trxReport = new TRXReport(report, new MockGuidSequenceGenerator(), testSettings);
            var output = trxReport.GetXmlReport();

            var memoryStream = new MemoryStream();
            using (var writer = new StreamWriter(memoryStream))
            {
                var xml = output;
                xml.Save(writer);
                writer.Close();
            }

            string fileData = memoryStream.ToArray().ToStringFromByteArray();
            string expectedFileData = Resources.SampleTRX_GeneratedFromRealTest;

            FixupRegEx("duration=\"00:00:00.0000000\"", ref expectedFileData, ref fileData,
                @"duration=\""[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9]\""");

            FixupRegEx("startTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                @"startTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]\""");

            FixupRegEx("endTime=\"0000-00-00T00:00:00.0000000-00:00\"", ref expectedFileData, ref fileData,
                @"endTime=\""[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]\""");

            //fileData.Trace();
            //expectedFileData.Trace();
            fileData.ShouldEqual(expectedFileData);
        }
        private TestReportCollection GetTestReports(RunnerType runnerType)
        {
            var testReports = new TestReportCollection();

            IEnumerable <StatLightConfiguration> statLightConfigurations = _currentStatLightConfiguration.ToList();

            if (runnerType == RunnerType.ContinuousTest)
            {
                IRunner continuousTestRunner = _statLightRunnerFactory.CreateContinuousTestRunner(statLightConfigurations);
                continuousTestRunner.Run();
            }
            else
            {
                Stopwatch totalTime = Stopwatch.StartNew();

                do
                {
                    using (IRunner runner = GetRunner(
                               _logger,
                               runnerType,
                               _currentStatLightConfiguration.Current,
                               _statLightRunnerFactory))
                    {
                        _logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));
                        Stopwatch  stopwatch  = Stopwatch.StartNew();
                        TestReport testReport = runner.Run();
                        stopwatch.Stop();
                        testReports.Add(testReport);
                        _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, stopwatch.Elapsed,
                                                                                       statLightConfigurations.Count() >
                                                                                       1));
                    }
                } while (_currentStatLightConfiguration.MoveNext());

                totalTime.Stop();

                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReports, totalTime.Elapsed));
            }

            return(testReports);
        }
        public void Should_conform_to_xml_schema()
        {
            string tempFileName = Path.GetTempFileName();
            try
            {
                var report = new TestReportCollection();
                var testReport = new TestReport(@"C:\Test.xap");
                testReport.AddResult(TestCaseResultFactory.CreatePassed());
                //testReport.AddResult(TestCaseResultFactory.CreateFailed());
                //testReport.AddResult(TestCaseResultFactory.CreateIgnored());

                report.Add(testReport);
                var trxReport = new TRXReport(report);
                trxReport.WriteXmlReport(tempFileName);

                //File.ReadAllText(tempFileName).Trace();

                var xmlSchema = Resources.vstst;
                IList<string> validationErrors;
                XmlSchemaValidatorHelper.ValidateSchema(tempFileName, xmlSchema, out validationErrors);

                tempFileName.Trace();

                foreach (var validationError in validationErrors)
                {
                    validationError.Trace();
                }

                if (validationErrors.Any())
                {
                    Assert.Fail("Validation Errors:{0}{1}".FormatWith(Environment.NewLine, string.Join(Environment.NewLine, validationErrors)));
                }
            }
            catch (Exception)
            {
                if(File.Exists(tempFileName))
                    File.Delete(tempFileName);
                throw;
            }
        }
Exemple #8
0
        public TestReportCollection Run()
        {
            bool showTestingBrowserHost       = _options.ShowTestingBrowserHost;
            bool useRemoteTestPage            = _options.UseRemoteTestPage;
            Collection <string> methodsToTest = _options.MethodsToTest;
            MicrosoftTestingFrameworkVersion?microsoftTestingFrameworkVersion = _options.MicrosoftTestingFrameworkVersion;
            string tagFilters = _options.TagFilters;
            UnitTestProviderType unitTestProviderType = _options.UnitTestProviderType;
            int            numberOfBrowserHosts       = _options.NumberOfBrowserHosts;
            string         queryString       = _options.QueryString;
            WebBrowserType webBrowserType    = _options.WebBrowserType;
            bool           forceBrowserStart = _options.ForceBrowserStart;

            IEnumerable <string> xapPaths = _options.XapPaths;
            IEnumerable <string> testDlls = _options.Dlls;

            _options.DumpValuesForDebug(_logger);

            var runnerType = GetRunnerType();

            _logger.Debug("RunnerType = {0}".FormatWith(runnerType));

            var testReports = new TestReportCollection();

            foreach (var xapPath in xapPaths)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(xapPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                                                                .GetStatLightConfigurationForXap(
                    unitTestProviderType,
                    xapPath,
                    microsoftTestingFrameworkVersion,
                    methodsToTest,
                    tagFilters,
                    numberOfBrowserHosts,
                    useRemoteTestPage,
                    queryString,
                    webBrowserType,
                    forceBrowserStart,
                    showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            foreach (var dllPath in testDlls)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(dllPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                                                                .GetStatLightConfigurationForDll(
                    unitTestProviderType,
                    dllPath,
                    microsoftTestingFrameworkVersion,
                    methodsToTest,
                    tagFilters,
                    numberOfBrowserHosts,
                    useRemoteTestPage,
                    queryString,
                    webBrowserType,
                    forceBrowserStart,
                    showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            string        xmlReportOutputPath = _options.XmlReportOutputPath;
            bool          tfsGenericReport    = _options.TFSGenericReport;
            XmlReportType xmlReportType       = XmlReportType.StatLight;

            if (tfsGenericReport)
            {
                xmlReportType = XmlReportType.TFS;
            }

            WriteXmlReport(testReports, xmlReportOutputPath, xmlReportType);

            return(testReports);
        }
Exemple #9
0
        public TestReportCollection Run()
        {
            bool showTestingBrowserHost = _options.ShowTestingBrowserHost;
            bool useRemoteTestPage = _options.UseRemoteTestPage;
            Collection<string> methodsToTest = _options.MethodsToTest;
            MicrosoftTestingFrameworkVersion? microsoftTestingFrameworkVersion = _options.MicrosoftTestingFrameworkVersion;
            string tagFilters = _options.TagFilters;
            UnitTestProviderType unitTestProviderType = _options.UnitTestProviderType;
            int numberOfBrowserHosts = _options.NumberOfBrowserHosts;
            string queryString = _options.QueryString;
            WebBrowserType webBrowserType = _options.WebBrowserType;
            bool forceBrowserStart = _options.ForceBrowserStart;

            IEnumerable<string> xapPaths = _options.XapPaths;
            IEnumerable<string> testDlls = _options.Dlls;

            _options.DumpValuesForDebug(_logger);

            var runnerType = GetRunnerType();

            _logger.Debug("RunnerType = {0}".FormatWith(runnerType));

            var testReports = new TestReportCollection();

            foreach (var xapPath in xapPaths)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(xapPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                    .GetStatLightConfigurationForXap(
                        unitTestProviderType,
                        xapPath,
                        microsoftTestingFrameworkVersion,
                        methodsToTest,
                        tagFilters,
                        numberOfBrowserHosts,
                        useRemoteTestPage,
                        queryString,
                        webBrowserType,
                        forceBrowserStart,
                        showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            foreach (var dllPath in testDlls)
            {
                _logger.Debug("Starting configuration for: {0}".FormatWith(dllPath));
                StatLightConfiguration statLightConfiguration = _statLightConfigurationFactory
                    .GetStatLightConfigurationForDll(
                        unitTestProviderType,
                        dllPath,
                        microsoftTestingFrameworkVersion,
                        methodsToTest,
                        tagFilters,
                        numberOfBrowserHosts,
                        useRemoteTestPage,
                        queryString,
                        webBrowserType,
                        forceBrowserStart,
                        showTestingBrowserHost);

                var testReport = DoTheRun(runnerType, statLightConfiguration);
                testReports.Add(testReport);
            }

            WriteXmlReport(testReports, _options.XmlReportOutputPath, _options.ReportOutputFileType);

            return testReports;
        }
        private TestReportCollection GetTestReports(RunnerType runnerType)
        {
            var testReports = new TestReportCollection();

            IEnumerable<StatLightConfiguration> statLightConfigurations = _currentStatLightConfiguration.ToList();

            if (runnerType == RunnerType.ContinuousTest)
            {
                IRunner continuousTestRunner = _statLightRunnerFactory.CreateContinuousTestRunner(statLightConfigurations);
                continuousTestRunner.Run();
            }
            else
            {

                Stopwatch totalTime = Stopwatch.StartNew();

                do
                {
                    using (IRunner runner = GetRunner(
                        _logger,
                        runnerType,
                        _currentStatLightConfiguration.Current,
                        _statLightRunnerFactory))
                    {
                        _logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        TestReport testReport = runner.Run();
                        stopwatch.Stop();
                        testReports.Add(testReport);
                        _eventPublisher.SendMessage(new TestReportGeneratedServerEvent(testReport, stopwatch.Elapsed,
                                                                                       statLightConfigurations.Count() >
                                                                                       1));
                    }

                } while (_currentStatLightConfiguration.MoveNext());

                totalTime.Stop();

                _eventPublisher.SendMessage(new TestReportCollectionGeneratedServerEvent(testReports, totalTime.Elapsed));
            }

            return testReports;
        }