public void SetUp()
        {
            TempFileUtil.DeleteTempDir(FULL_CONFIGURED_LOG_DIR);
            TempFileUtil.DeleteTempDir(ARTIFACTS_DIR);
            TempFileUtil.CreateTempDir(ARTIFACTS_DIR);

            publisher = new ModificationHistoryPublisher();
        }
        public void BuildWithoutModificationsShouldPublishNoModifications()
        {
            // Setup
            IntegrationResult result = CreateIntegrationResult(IntegrationStatus.Success, false);

            result.ArtifactDirectory = ARTIFACTS_DIR_PATH;
            string PublishedModifications;
            string ExpectedLoggedModifications = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<History><Build BuildDate=\"{0}\" Success=\"True\" Label=\"{1}\" />\r\n</History>",
                                                               DateUtil.FormatDate(result.StartTime), result.Label);

            // Execute
            publisher.Run(result);

            //Verify
            PublishedModifications = ModificationHistoryPublisher.LoadHistory(ARTIFACTS_DIR_PATH);

            Assert.AreEqual(ExpectedLoggedModifications, PublishedModifications, "Differences in log Detected");
        }
        public void BuildWithoutModificationsShouldNotLogWhenOnlyLogWhenChangesFound()
        {
            // Setup
            publisher.OnlyLogWhenChangesFound = true;

            IntegrationResult result = CreateIntegrationResult(IntegrationStatus.Success, false);

            result.ArtifactDirectory = ARTIFACTS_DIR_PATH;
            string PublishedModifications;
            string ExpectedLoggedModifications = string.Empty;

            // Execute
            publisher.Run(result);

            //Verify
            PublishedModifications = ModificationHistoryPublisher.LoadHistory(ARTIFACTS_DIR_PATH);

            Assert.AreEqual(ExpectedLoggedModifications, PublishedModifications, "Differences in log Detected");
        }
        public void BuildWithModificationsShouldPublishModifications()
        {
            // Setup
            IntegrationResult result = CreateIntegrationResult(IntegrationStatus.Success, true);

            result.ArtifactDirectory = ARTIFACTS_DIR_PATH;
            string PublishedModifications;

            System.Text.StringBuilder ExpectedLoggedModifications = new System.Text.StringBuilder();
            ExpectedLoggedModifications.Append("<History>");
            ExpectedLoggedModifications.Append(GetExpectedMods(result));
            ExpectedLoggedModifications.AppendLine();
            ExpectedLoggedModifications.Append("</History>");

            // Execute
            publisher.Run(result);

            //Verify
            PublishedModifications = ModificationHistoryPublisher.LoadHistory(ARTIFACTS_DIR_PATH);

            Assert.AreEqual(ExpectedLoggedModifications.ToString(), PublishedModifications, "Differences in log Detected");
        }
Example #5
0
        private void KeepMaximumXHistoryDataEntries(IIntegrationResult result, int entriesToKeep)
        {
            string historyXml = ModificationHistoryPublisher.LoadHistory(result.ArtifactDirectory);

            if (historyXml.Length == 0)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(historyXml);

            //if (doc.FirstChild.ChildNodes.Count == 0)
            int nodeCount = doc.FirstChild.ChildNodes.Count;

            if (nodeCount <= entriesToKeep)
            {
                return;
            }


            StringWriter cleanedHistory = new StringWriter();

            for (int i = nodeCount - entriesToKeep; i < nodeCount; i++)
            {
                cleanedHistory.WriteLine(doc.FirstChild.ChildNodes[i].OuterXml);
            }

            StreamWriter historyWriter = new StreamWriter(
                Path.Combine(result.ArtifactDirectory,
                             ModificationHistoryPublisher.DataHistoryFileName));

            historyWriter.WriteLine(cleanedHistory.ToString());
            historyWriter.Close();
        }