Exemplo n.º 1
0
        private IEnumerable <CruiseControlNetBuildStatus> GetBuildStatuses(string rootUrl, string userName, string password)
        {
            rootUrl = GetRootUrl(rootUrl);
            var url = new Uri(rootUrl + "/XmlStatusReport.aspx");
            var doc = DownloadXml(url.ToString(), userName, password);

            if (doc.Root == null)
            {
                throw new Exception("Could not get project list");
            }
            IEnumerable <XElement> projectElems = doc.Root.Elements("Project");

            List <CruiseControlNetBuildStatus> results = new List <CruiseControlNetBuildStatus>();

            if (projectElems != null)
            {
                foreach (XElement projectElem in projectElems)
                {
                    try
                    {
                        var    name             = projectElem.AttributeValue("name");
                        var    lastBuildTimeStr = projectElem.AttributeValueOrDefault("lastBuildTime");
                        string parsedBuildTime  = CruiseControlNetBuildStatus.ParseCruiseControlDateToId(lastBuildTimeStr);
                        string lastBuildNumber  = projectElem.AttributeValueOrDefault("lastBuildLabel");
                        string lastBuildStatus  = projectElem.AttributeValueOrDefault("lastBuildStatus");

                        var XMLUrl = lastBuildStatus != null && lastBuildStatus.Equals("Success") ?
                                     string.Format("{0}/server/local/project/{1}/build/log{2}Lbuild.{3}.xml/XmlBuildLog.aspx", rootUrl, name, parsedBuildTime, lastBuildNumber) :
                                     string.Format("{0}/server/local/project/{1}/build/log{2}.xml/XmlBuildLog.aspx", rootUrl, name, parsedBuildTime);

                        var      buildLog = DownloadXml(XMLUrl.ToString(), userName, password);
                        XElement buildLogModificationElems = buildLog.Root == null ? null : buildLog.Root.Element("modifications");

                        results.Add(new CruiseControlNetBuildStatus(projectElem, buildLogModificationElems));
                    }
                    catch (Exception ex)
                    {
                        _log.Debug(ex);
                    }
                }
            }

            return(results);
        }
        public void CruiseControlNetBuildStatus_BrokenWithAuthor()
        {
            var document = ResourceManager.CruiseControlNetBrokenWithAuthor;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting();
            buildDefinitionSetting.Name = "Name";
            buildDefinitionSetting.Id = "BuildDefinitionId";
            XElement projectElement = document.Root.Element("Project");
            CruiseControlNetBuildStatus.ClearCache();
            CruiseControlNetBuildStatus buildStatus = new CruiseControlNetBuildStatus(projectElement, null);

            Assert.AreEqual(BuildStatusEnum.Broken, buildStatus.BuildStatusEnum);
            Assert.AreEqual("Lee", buildStatus.RequestedBy);
            Assert.IsNotNull(buildStatus.StartedTime);
            AssertAreClose(new DateTime(2012, 8, 16, 19, 23, 34, 276), buildStatus.StartedTime.Value);
            Assert.IsNull(buildStatus.Comment);
            Assert.IsNotNull(buildStatus.FinishedTime);
            AssertAreClose(new DateTime(2012, 8, 16, 19, 23, 34, 276), buildStatus.FinishedTime.Value);
            Assert.AreEqual("20120816192334", buildStatus.BuildId);
        }
        public void CruiseControlNetBuildStatus_InProgress()
        {
            var document = ResourceManager.CruiseControlNetJoesProject1;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting();
            buildDefinitionSetting.Name = "Name";
            buildDefinitionSetting.Id = "BuildDefinitionId";
            XElement projectElement = document.Root.Element("Project");
            CruiseControlNetBuildStatus.ClearCache();
            CruiseControlNetBuildStatus buildStatus = new CruiseControlNetBuildStatus(projectElement, null);

            Assert.AreEqual(BuildStatusEnum.InProgress, buildStatus.BuildStatusEnum);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.BuildDefinitionId);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.Name);
            Assert.AreEqual(null, buildStatus.RequestedBy);
            Assert.IsNotNull(buildStatus.StartedTime);
            Assert.AreEqual(new DateTime(2011, 8, 28, 17, 20, 5, 375), buildStatus.StartedTime.Value.ToUniversalTime(), HudsonBuildStatusTest.DateAsCode(buildStatus.StartedTime.Value.ToUniversalTime()));
            Assert.IsNull(buildStatus.Comment);
            Assert.IsNotNull(buildStatus.FinishedTime);
            Assert.AreEqual(new DateTime(2011, 8, 28, 17, 20, 5, 375), buildStatus.FinishedTime.Value.ToUniversalTime(), HudsonBuildStatusTest.DateAsCode(buildStatus.FinishedTime.Value.ToUniversalTime()));
            //Assert.AreEqual("http://win7ci:8081/job/SvnTest/30/", buildStatus.Url);
            //Assert.AreEqual(30, buildStatus.BuildId);
        }
        public void CruiseControlNetBuildStatus_ChangesToInProgress()
        {
            var inProgressStatus = ResourceManager.CruiseControlNetJoesProject1;
            var notInProgressStatus = ResourceManager.CruiseControlNetJoesProject2;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting();
            buildDefinitionSetting.Name = "Name";
            buildDefinitionSetting.Id = "BuildDefinitionId";
            XElement notInProgressStatusProjectElement = notInProgressStatus.Root.Element("Project");
            XElement inProgressStatusProjectElement = inProgressStatus.Root.Element("Project");
            CruiseControlNetBuildStatus.ClearCache();
            new CruiseControlNetBuildStatus(notInProgressStatusProjectElement, null);
            CruiseControlNetBuildStatus buildStatus = new CruiseControlNetBuildStatus(inProgressStatusProjectElement, null);

            Assert.AreEqual(BuildStatusEnum.InProgress, buildStatus.BuildStatusEnum);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.BuildDefinitionId);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.Name);
            Assert.AreEqual(null, buildStatus.RequestedBy);
            Assert.IsNotNull(buildStatus.StartedTime);
            Assert.AreEqual(DateTime.Now.ToString(), buildStatus.StartedTime.Value.ToString());
            Assert.IsNull(buildStatus.Comment);
            Assert.IsNull(buildStatus.FinishedTime);
            Assert.AreEqual("http://VMXP/ccnet/server/local/project/CruiseControlNetProj1/build/log20110828202005Lbuild.3.xml/ViewBuildReport.aspx", buildStatus.Url);
            Assert.AreEqual("3", buildStatus.BuildId);
        }
        public void CruiseControlNetBuildStatus_TwoBackToBackNotStartedBuilds_StartedTimeShouldBeLastBuild()
        {
            var document = ResourceManager.CruiseControlNetJoesProject2;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting();
            buildDefinitionSetting.Name = "Name";
            buildDefinitionSetting.Id = "BuildDefinitionId";
            XElement projectElement = document.Root.Element("Project");
            CruiseControlNetBuildStatus.ClearCache();
            new CruiseControlNetBuildStatus(projectElement);
            CruiseControlNetBuildStatus buildStatus = new CruiseControlNetBuildStatus(projectElement);

            Assert.AreEqual(BuildStatusEnum.Unknown, buildStatus.BuildStatusEnum);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.BuildDefinitionId);
            Assert.AreEqual("CruiseControlNetProj1", buildStatus.Name);
            Assert.AreEqual(null, buildStatus.RequestedBy);
            Assert.IsNotNull(buildStatus.StartedTime);
            Assert.AreEqual(new DateTime(2011, 8, 27, 17, 21, 27, 843).ToString(), buildStatus.StartedTime.Value.ToUniversalTime().ToString(), HudsonBuildStatusTest.DateAsCode(buildStatus.StartedTime.Value.ToUniversalTime()));
            Assert.IsNull(buildStatus.Comment);
            Assert.IsNotNull(buildStatus.FinishedTime);
            Assert.AreEqual(new DateTime(2011, 8, 27, 17, 21, 27, 843).ToString(), buildStatus.FinishedTime.Value.ToUniversalTime().ToString(), HudsonBuildStatusTest.DateAsCode(buildStatus.FinishedTime.Value.ToUniversalTime()));
            //Assert.AreEqual("http://win7ci:8081/job/SvnTest/30/", buildStatus.Url);
            //Assert.AreEqual(30, buildStatus.BuildId);
        }