public void Create() { var name = "someName"; var start = DateTimeOffset.Now; var end = start.AddSeconds(10); bool success = false; var info = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(1), "info") }; var warning = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(2), "warning") }; var error = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(3), "error") }; var section = new TestSection(name, start, end, success, info, warning, error); Assert.AreEqual(name, section.Name); Assert.AreEqual(start, section.StartTime); Assert.AreEqual(end, section.EndTime); Assert.AreEqual(success, section.WasSuccessful); Assert.That( section.InfoMessages(), Is.EquivalentTo(info)); Assert.That( section.WarningMessages(), Is.EquivalentTo(warning)); Assert.That( section.ErrorMessages(), Is.EquivalentTo(error)); }
public void Transform() { var productName = "product"; var productVersion = "1.2.3.4"; var owner = "owner"; var description = "description"; var start = new DateTimeOffset(2000, 1, 1, 1, 1, 1, new TimeSpan(0, 0, 0)); var end = start.AddSeconds(10); var name = "name"; var section = new TestSection( "someName", start.AddSeconds(1), end.AddSeconds(-1), true, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(2), "info") }, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(3), "warning") }, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(4), "error") }); var report = BuildReport(productName, productVersion, owner, description, start, end, name, section); var outputNames = new List<string>(); var outputs = new List<Stream>(); Action<string, Stream> writer = (fileName, input) => { outputNames.Add(fileName); outputs.Add(input); }; var transformer = new HtmlReportTransformer(); transformer.Transform(report, writer); var result = string.Empty; using (var reader = new StreamReader(outputs[0])) { result = reader.ReadToEnd().Replace("\r\n", string.Empty).Replace(" ", string.Empty); } var expected = EmbeddedResourceExtracter.LoadEmbeddedTextFile( Assembly.GetExecutingAssembly(), @"Sherlock.Shared.Core.Reporting.TestHtmlReport.html"); var builder = new StringBuilder(expected); { builder.Replace("${DESCRIPTION}$", description); builder.Replace("${PRODUCT_NAME}$", productName); builder.Replace("${PRODUCT_VERSION}$", productVersion.ToString(CultureInfo.CurrentCulture)); builder.Replace("${USER_NAME}$", owner); builder.Replace("${TEST_DESCRIPTION}$", description); builder.Replace("${TEST_START_DATE}$", start.ToString("d", CultureInfo.CurrentCulture)); builder.Replace("${TEST_START_TIME}$", start.ToString("T", CultureInfo.CurrentCulture)); builder.Replace("${TEST_END_DATE}$", end.ToString("d", CultureInfo.CurrentCulture)); builder.Replace("${TEST_END_TIME}$", end.ToString("T", CultureInfo.CurrentCulture)); builder.Replace("${TEST_TOTAL_TIME}$", (end - start).ToString("g", CultureInfo.CurrentCulture)); builder.Replace("${SECTION_ICON}$", outputNames[3]); builder.Replace("${SECTION_CATEGORY}$", name); builder.Replace("${SECTION_DESCRIPTION}$", section.Name); builder.Replace("${INFO_ICON}$", outputNames[5]); builder.Replace("${INFO_TIME}$", section.InfoMessages().First().Time.ToString("G", CultureInfo.CurrentCulture)); builder.Replace("${INFO_TEXT}$", section.InfoMessages().First().Information); builder.Replace("${WARNING_ICON}$", outputNames[6]); builder.Replace("${WARNING_TIME}$", section.WarningMessages().First().Time.ToString("G", CultureInfo.CurrentCulture)); builder.Replace("${WARNING_TEXT}$", section.WarningMessages().First().Information); builder.Replace("${ERROR_ICON}$", outputNames[7]); builder.Replace("${ERROR_TIME}$", section.ErrorMessages().First().Time.ToString("G", CultureInfo.CurrentCulture)); builder.Replace("${ERROR_TEXT}$", section.ErrorMessages().First().Information); builder.Replace("${HOST}$", Environment.MachineName); builder.Replace( "${USERNAME}$", string.Format( CultureInfo.InvariantCulture, @"{0}\{1}", Environment.UserDomainName, Environment.UserName)); builder.Replace( "${SHERLOCK_VERSION}$", typeof(HtmlReportTransformer).Assembly.GetName().Version.ToString()); } Assert.AreEqual(builder.ToString().Replace("\r\n", string.Empty).Replace(" ", string.Empty), result); }
private static void AddTestSectionWarningMessages( SortedList<DateTimeOffset, string> collectionToAddTo, TestSection testSection) { var warningMessageTemplate = EmbeddedResourceExtracter.LoadEmbeddedTextFile( Assembly.GetExecutingAssembly(), @"Sherlock.Shared.Core.Reporting.Templates.TestSectionWarningTemplate.html"); foreach (var warning in testSection.WarningMessages()) { var builder = new StringBuilder(warningMessageTemplate); { builder.Replace(@"${WARNING_ICON}$", WarningMessageIconName); builder.Replace(@"${WARNING_TIME}$", warning.Time.ToString("G", CultureInfo.CurrentCulture)); builder.Replace( @"${WARNING_TEXT}$", HttpUtility.HtmlEncode(warning.Information) .ReplaceNewLinesByHtmlLineBreaks() .ReplaceTabsByHtmlNonBreakingSpaces()); } AddMessageToTimeSortedCollection(collectionToAddTo, warning.Time, builder.ToString()); } }
public void RoundTripSerialise() { var name = "someName"; var start = DateTimeOffset.Now; var end = start.AddSeconds(10); bool success = false; var info = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(1), "info") }; var warning = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(2), "warning") }; var error = new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(3), "error") }; var section = new TestSection(name, start, end, success, info, warning, error); var otherSection = AssertExtensions.RoundTripSerialize(section); Assert.AreEqual(section.Name, otherSection.Name); Assert.AreEqual(section.StartTime, otherSection.StartTime); Assert.AreEqual(section.EndTime, otherSection.EndTime); Assert.AreEqual(section.WasSuccessful, otherSection.WasSuccessful); Assert.That( otherSection.InfoMessages(), Is.EquivalentTo(section.InfoMessages())); Assert.That( otherSection.WarningMessages(), Is.EquivalentTo(section.WarningMessages())); Assert.That( otherSection.ErrorMessages(), Is.EquivalentTo(section.ErrorMessages())); }
private static void AddTestSectionWarningMessages( SortedList<DateTimeOffset, string> collectionToAddTo, TestSection testSection) { var warningMessageTemplate = EmbeddedResourceExtracter.LoadEmbeddedTextFile( Assembly.GetExecutingAssembly(), @"Sherlock.Shared.Core.Reporting.Templates.TestSectionWarningTemplate.xml"); foreach (var info in testSection.WarningMessages()) { var builder = new StringBuilder(warningMessageTemplate); { builder.Replace( @"${WARNING_TIME}$", EscapeTextForUseInXml(info.Time.ToString("o", CultureInfo.CurrentCulture))); builder.Replace(@"${WARNING_TEXT}$", EscapeTextForUseInXml(info.Information)); } AddMessageToTimeSortedCollection(collectionToAddTo, info.Time, builder.ToString()); } }
public void Transform() { var productName = "product"; var productVersion = "1.2.3.4"; var owner = "owner"; var description = "description"; var start = new DateTimeOffset(2000, 1, 1, 1, 1, 1, new TimeSpan(0, 0, 0)); var end = start.AddSeconds(10); var name = "name"; var section = new TestSection( "someName", start.AddSeconds(1), end.AddSeconds(-1), true, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(2), "info") }, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(3), "warning") }, new List<DateBasedTestInformation> { new DateBasedTestInformation(start.AddSeconds(4), "error") }); var report = BuildReport(productName, productVersion, owner, description, start, end, name, section); Stream output = null; Action<string, Stream> writer = (fileName, input) => { output = input; }; var transformer = new XmlReportTransformer(); transformer.Transform(report, writer); var result = string.Empty; using (var reader = new StreamReader(output, Encoding.UTF8)) { result = reader.ReadToEnd(); } var expected = EmbeddedResourceExtracter.LoadEmbeddedTextFile( Assembly.GetExecutingAssembly(), @"Sherlock.Shared.Core.Reporting.TestXmlReport.xml"); var builder = new StringBuilder(expected); { builder.Replace("${REPORT_VERSION}$", "1.0"); builder.Replace("${HOST_NAME}$", Environment.MachineName); builder.Replace("${USER_NAME}$", owner); builder.Replace("${DESCRIPTION}$", description); builder.Replace("${SHERLOCK_VERSION}$", typeof(XmlReportTransformer).Assembly.GetName().Version.ToString()); builder.Replace("${TEST_START_TIME}$", start.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${TEST_END_TIME}$", end.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${PRODUCT_NAME}$", productName); builder.Replace("${PRODUCT_VERSION}$", productVersion); builder.Replace("${TEST_RESULT}$", "Passed"); builder.Replace("${REPORT_SECTION_NAME}$", name); builder.Replace("${TEST_SECTION_NAME}$", section.Name); builder.Replace("${TEST_SECTION_START_TIME}$", section.StartTime.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${TEST_SECTION_END_TIME}$", section.EndTime.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${TEST_SECTION_WAS_SUCCESSFUL}$", section.WasSuccessful.ToString()); builder.Replace("${INFO_TIME}$", section.InfoMessages().First().Time.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${INFO_TEXT}$", section.InfoMessages().First().Information); builder.Replace("${WARNING_TIME}$", section.WarningMessages().First().Time.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${WARNING_TEXT}$", section.WarningMessages().First().Information); builder.Replace("${ERROR_TIME}$", section.ErrorMessages().First().Time.ToString("o", CultureInfo.CurrentCulture)); builder.Replace("${ERROR_TEXT}$", section.ErrorMessages().First().Information); } Assert.AreEqual( builder.ToString().Replace("\r\n", string.Empty).Replace(" ", string.Empty), result.Replace("\r\n", string.Empty).Replace(" ", string.Empty)); }