コード例 #1
0
        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));
        }
コード例 #2
0
        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()));
        }
コード例 #3
0
 public void RaiseOnExecutionProgress(string sectionName, TestSection sectionReport)
 {
     var local = OnExecutionProgress;
     if (local != null)
     {
         local(this, new TestExecutionProgressEventArgs(-1, sectionName, sectionReport));
     }
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReportTestSectionEventArgs"/> class.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <exception cref="ArgumentNullException">
        ///   Thrown when <paramref name="section"/> is <see langword="null" />.
        /// </exception>
        public ReportTestSectionEventArgs(TestSection section)
        {
            {
            Lokad.Enforce.Argument(() => section);
             }

             Section = section;
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestExecutionProgressEventArgs"/> class.
        /// </summary>
        /// <param name="id">The ID of the test. Is allowed to be <see langword="null" />.</param>
        /// <param name="sectionName">The name of the report section under which the current section should be stored.</param>
        /// <param name="section">The report test section.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="sectionName"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="sectionName"/> is an empty string.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="section"/> is <see langword="null" />.
        /// </exception>
        public TestExecutionProgressEventArgs(int id, string sectionName, TestSection section)
        {
            {
                Lokad.Enforce.Argument(() => sectionName);
                Lokad.Enforce.Argument(() => sectionName, Lokad.Rules.StringIs.NotEmpty);
                Lokad.Enforce.Argument(() => section);
            }

            m_Id = id;
            m_SectionName = sectionName;
            m_Section = section;
        }
コード例 #6
0
        public void Create()
        {
            var section = new TestSection(
            "SomeName",
            DateTimeOffset.Now,
            DateTimeOffset.Now.AddSeconds(10),
            true,
            new List<DateBasedTestInformation>(),
            new List<DateBasedTestInformation>(),
            new List<DateBasedTestInformation>());

             var args = new ReportTestSectionEventArgs(section);
             Assert.AreSame(section, args.Section);
        }
コード例 #7
0
ファイル: ReportTest.cs プロジェクト: pvandervelde/Sherlock
        public void Create()
        {
            var productName = "product";
            var productVersion = "1.2.3.4";
            var owner = "owner";
            var description = "description";
            var start = DateTimeOffset.Now;
            var end = start.AddSeconds(10);

            var header = new ReportHeader(
                start,
                end,
                productName,
                productVersion,
                owner,
                description);

            var name = "name";
            var section = new TestSection(
                "someName",
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                true,
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>());
            var testSections = new List<TestSection>
                {
                    section
                };
            var reportSection = new ReportSection(name, testSections);
            var sections = new List<ReportSection>
                {
                    reportSection
                };

            var report = new Report(header, sections);

            Assert.AreSame(header, report.Header);
            Assert.That(
                report.Sections(),
                Is.EquivalentTo(sections));
        }
コード例 #8
0
        public void Create()
        {
            var name = "name";
            var section = new TestSection(
               "someName",
               DateTimeOffset.Now,
               DateTimeOffset.Now,
               true,
               new List<DateBasedTestInformation>(),
               new List<DateBasedTestInformation>(),
               new List<DateBasedTestInformation>());
            var sections = new List<TestSection> { section };

            var reportSection = new ReportSection(name, sections);

            Assert.AreEqual(name, reportSection.Name);
            Assert.That(
                reportSection.Sections(),
                Is.EquivalentTo(sections));
        }
コード例 #9
0
        public void RoundTripSerialise()
        {
            var name = "name";
            var section = new TestSection(
               "someName",
               DateTimeOffset.Now,
               DateTimeOffset.Now,
               true,
               new List<DateBasedTestInformation>(),
               new List<DateBasedTestInformation>(),
               new List<DateBasedTestInformation>());
            var sections = new List<TestSection> { section };

            var reportSection = new ReportSection(name, sections);
            var otherReportSection = AssertExtensions.RoundTripSerialize(reportSection);

            Assert.AreEqual(reportSection.Name, otherReportSection.Name);

            // We'll assume that if one of the fields is correct then the other fields will be correct
            // too. This is (relatively) safe because there is a serialize / deserialize test for
            // the TestSection class.
            Assert.AreEqual(reportSection.Sections().Count(), otherReportSection.Sections().Count());
            Assert.AreEqual(reportSection.Sections().First().Name, otherReportSection.Sections().First().Name);
        }
コード例 #10
0
ファイル: ReportTest.cs プロジェクト: pvandervelde/Sherlock
        public void RoundTripSerialise()
        {
            var productName = "product";
            var productVersion = "1.2.3.4";
            var owner = "owner";
            var description = "description";
            var start = DateTimeOffset.Now;
            var end = start.AddSeconds(10);

            var header = new ReportHeader(
                start,
                end,
                productName,
                productVersion,
                owner,
                description);

            var name = "name";
            var section = new TestSection(
                "someName",
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                true,
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>());
            var testSections = new List<TestSection>
                {
                    section
                };
            var reportSection = new ReportSection(name, testSections);
            var sections = new List<ReportSection>
                {
                    reportSection
                };

            var report = new Report(header, sections);
            var otherReport = AssertExtensions.RoundTripSerialize(report);

            // We'll assume that if one of the fields is correct then the other fields will be correct
            // too. This is (relatively) safe because there is a serialize / deserialize test for
            // the ReportHeader class.
            Assert.AreEqual(report.Header.ProductName, otherReport.Header.ProductName);

            // We'll assume that if one of the fields is correct then the other fields will be correct
            // too. This is (relatively) safe because there is a serialize / deserialize test for
            // the TestSection class.
            Assert.AreEqual(report.Sections().Count(), otherReport.Sections().Count());
            Assert.AreEqual(report.Sections().First().Name, otherReport.Sections().First().Name);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        private static TestSection EnvironmentFailedSection(string environmentName)
        {
            var section = new TestSection(
                Resources.ReportSection_Name_Environments,
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                false,
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>(),
                new List<DateBasedTestInformation>
                    {
                        new DateBasedTestInformation(
                            DateTimeOffset.Now,
                            string.Format(
                                CultureInfo.InvariantCulture,
                                Resources.ReportSection_Error_LostContactWithEnvironment_WithEnvironment,
                                environmentName))
                    });

            return section;
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        private static IReport BuildReport(
            string productName,
            string productVersion,
            string owner,
            string description,
            DateTimeOffset start,
            DateTimeOffset end,
            string sectionName,
            TestSection section)
        {
            var header = new ReportHeader(
                start,
                end,
                productName,
                productVersion,
                owner,
                description);

            var testSections = new List<TestSection>
                {
                    section
                };
            var reportSection = new ReportSection(sectionName, testSections);
            var sections = new List<ReportSection>
                {
                    reportSection
                };

            return new Report(header, sections);
        }
コード例 #15
0
        /// <summary>
        /// Finalizes the test section data and passes it on to a storage object.
        /// </summary>
        /// <param name="wasSuccessful">Set to <see langword="true"/> if all tests in the section were successful.</param>
        /// <param name="endTime">The end time.</param>
        /// <exception cref="CannotFinalizeAnUninitializedTestSectionException">
        ///   Thrown when the <c>Initialize</c> method was not called prior to
        ///   calling <see cref="FinalizeAndStore(bool, DateTimeOffset)"/>.
        /// </exception>
        public void FinalizeAndStore(bool wasSuccessful, DateTimeOffset endTime)
        {
            if (!WasInitialized)
             {
            throw new CannotFinalizeAnUninitializedTestSectionException();
             }

             var section = new TestSection(
            m_Name,
            m_StartTime,
            endTime,
            wasSuccessful,
            m_InformationMessages,
            m_WarningMessages,
            m_ErrorMessages);

             m_OnStore(m_ReportSectionName, section);

             // Clear the data. There's no way to finalize twice!
             Clear();
        }
コード例 #16
0
        private static string CreateTestSectionMessagesHtml(TestSection testSection)
        {
            var messages = new SortedList<DateTimeOffset, string>();

            AddTestSectionInfoMessages(messages, testSection);
            AddTestSectionWarningMessages(messages, testSection);
            AddTestSectionErrorMessages(messages, testSection);

            var builder = new StringBuilder();
            foreach (var msg in messages)
            {
                builder.AppendLine(msg.Value);
            }

            return builder.ToString();
        }
コード例 #17
0
        /// <summary>
        /// Creates the HTML that describes a test section.
        /// </summary>
        /// <param name="category">The category of the section.</param>
        /// <param name="section">The report section that holds the test section information.</param>
        /// <param name="hasHighlight">A flag that indicates if this section should be highlighted.</param>
        /// <returns>A string containing the desired HTML.</returns>
        private static string CreateTestSectionHtml(string category, TestSection section, bool hasHighlight)
        {
            var testSectionTemplate = EmbeddedResourceExtracter.LoadEmbeddedTextFile(
               Assembly.GetExecutingAssembly(),
               @"Sherlock.Shared.Core.Reporting.Templates.TestSectionTemplate.html");

            var messages = CreateTestSectionMessagesHtml(section);
            var builder = new StringBuilder(testSectionTemplate);
            {
                var highlightText = hasHighlight ? "class=\"row-light\"" : string.Empty;
                builder.Replace(@"${ROW_HIGHLIGHT}$", highlightText);

                builder.Replace(@"${SECTION_ICON}$", section.WasSuccessful ? TestPassedIconName : TestFailedIconName);
                builder.Replace(@"${SECTION_CATEGORY}$", category);
                builder.Replace(
                   @"${SECTION_DESCRIPTION}$",
                   HttpUtility.HtmlEncode(section.Name)
                      .ReplaceSpaceByHtmlNonBreakingSpaces()
                      .ReplaceTabsByHtmlNonBreakingSpaces()
                      .ReplaceNewLinesByHtmlLineBreaks());

                builder.Replace(@"${SECTION_MESSAGES}$", messages);
            }

            return builder.ToString();
        }
コード例 #18
0
        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());
            }
        }
コード例 #19
0
        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());
            }
        }