protected override void Before_all_tests()
        {
            base.Before_all_tests();

            Func<ResultType, ExceptionInfo, TestCaseResultServerEvent> getResult = (resultType, exceptionInfo) =>
                {
                    return new TestCaseResultServerEvent(resultType)
                               {
                                   ClassName = "class_name",
                                   MethodName = "method_name",
                                   NamespaceName = "namespace.here",
                                   Finished = new DateTime(2009, 2, 2, 2, 2, 2),
                                   Started = new DateTime(2009, 2, 2, 2, 2, 1),
                                   ExceptionInfo = exceptionInfo,
                                   XapFilePath = "Test.xap",
                               };
                };

            var testReport = new TestReport("Test.xap")
                .AddResult(getResult(ResultType.Passed, null))
                .AddResult(getResult(ResultType.Failed, new ExceptionInfo(GetException())))
                .AddResult(getResult(ResultType.Ignored, null))
                .AddResult(getResult(ResultType.SystemGeneratedFailure, new ExceptionInfo(new Exception("fail"))))
                ;

            _xmlReport = new XmlReport(testReport.ToTestReportCollection());
        }
        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;
            }
        }
        public void Should_be_able_to_add_test_results()
        {
            var result = new TestReport("test");

            result.AddResult(TestCaseResultFactory.CreatePassed());
            result.AddResult(TestCaseResultFactory.CreateFailed());

            result.TotalResults.ShouldEqual(2);
        }
        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);
        }
        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 TestReportGeneratedServerEvent(TestReport testReport, TimeSpan elapsedTimeOfRun, bool shouldPrintSummary)
 {
     TestReport = testReport;
     ElapsedTimeOfRun = elapsedTimeOfRun;
     ShouldPrintSummary = shouldPrintSummary;
 }
        protected override void Before_all_tests()
        {
            base.Before_all_tests();

            _result = new TestReport("test");

            _result
                .AddResult(TestCaseResultFactory.CreateIgnored())
                .AddResult(TestCaseResultFactory.CreateFailed())
                .AddResult(TestCaseResultFactory.CreateFailed())
                .AddResult(TestCaseResultFactory.CreatePassed())
                .AddResult(TestCaseResultFactory.CreatePassed())
                .AddResult(TestCaseResultFactory.CreatePassed())
                ;
        }
        public void when_only_passing_tests_are_added_the_FinalResult_should_be_successful()
        {
            var result = new TestReport("test");

            result
                .AddResult(TestCaseResultFactory.CreatePassed())
                .AddResult(TestCaseResultFactory.CreatePassed());

            result.FinalResult.ShouldEqual(RunCompletedState.Successful);
        }