CruiseServerHttpClientTests.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » Remote » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » Remote » CruiseServerHttpClientTests.cs
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote;
using Rhino.Mocks;
using System.Net;

namespace ThoughtWorks.CruiseControl.UnitTests.Remote{
    [TestFixture]
    public class CruiseServerHttpClientTests
    {
        #region Private fields
        private const string xmlFrom11 = @"<Projects CCType=""CCNet"">
<Project name=""CCNet"" category="""" activity=""Sleeping"" lastBuildStatus=""Failure"" lastBuildLabel=""1.5.0.4286"" lastBuildTime=""2009-05-26T21:54:27.00000"" nextBuildTime=""2009-05-26T22:24:04.00000"" webUrl=""http://ccnetlive.thoughtworks.com/ccnet/server/local/project/CCNet/ViewLatestBuildReport.aspx"" CurrentMessage="""" BuildStage="""" serverName=""local""/>
</Projects>";
        private readonly ProjectStatus projectFrom11 = new ProjectStatus
        {
            Name = "CCNet",
            Category = string.Empty,
            Activity = ProjectActivity.Sleeping,
            BuildStatus = IntegrationStatus.Failure,
            LastBuildLabel = "1.5.0.4286",
            LastBuildDate = new DateTime(2009, 5, 26, 21, 54, 27),
            NextBuildTime = new DateTime(2009, 5, 26, 22, 24, 04),
            WebURL = "http://ccnetlive.thoughtworks.com/ccnet/server/local/project/CCNet/ViewLatestBuildReport.aspx",
            BuildStage = string.Empty,
            ServerName = "local"
        };
        private const string xmlFromCC = @"<Projects>
<Project name=""website-validation"" activity=""Sleeping"" lastBuildStatus=""Failure"" lastBuildLabel="""" lastBuildTime=""2008-09-23T02:03:45"" webUrl=""http://cclive.thoughtworks.com/dashboard/build/detail/website-validation""/>
</Projects>";
        private readonly ProjectStatus projectFromCC = new ProjectStatus
        {
            Category = string.Empty,
            Name = "website-validation",
            Activity = ProjectActivity.Sleeping,
            BuildStatus = IntegrationStatus.Failure,
            LastBuildLabel = string.Empty,
            LastBuildDate = new DateTime(2008, 9, 23, 2, 3, 45),
            NextBuildTime = DateTime.MaxValue,
            BuildStage = string.Empty,
            ServerName = string.Empty,
            WebURL = "http://cclive.thoughtworks.com/dashboard/build/detail/website-validation"
        };
        private const string xmlFrom144 = @"<CruiseControl>
<Projects>
<Project name=""CCNet"" category="""" activity=""Sleeping"" status=""Running"" lastBuildStatus=""Failure"" lastBuildLabel=""1.5.0.4286"" lastBuildTime=""2009-05-26T21:54:27.21875"" nextBuildTime=""2009-05-26T22:24:04.90625"" webUrl=""http://ccnetlive.thoughtworks.com/ccnet/server/local/project/CCNet/ViewLatestBuildReport.aspx"" buildStage="""" serverName=""CCNETLIVE""/>
</Projects>
<Queues>
<Queue name=""CCNet"">
<Request projectName=""CCNet"" activity=""Building"" />
</Queue>
</Queues>
</CruiseControl>";
        private readonly ProjectStatus projectFrom144 = new ProjectStatus
        {
            Name = "CCNet",
            Category = string.Empty,
            Activity = ProjectActivity.Sleeping,
            BuildStatus = IntegrationStatus.Failure,
            LastBuildLabel = "1.5.0.4286",
            LastBuildDate = new DateTime(2009, 5, 26, 21, 54, 27),
            NextBuildTime = new DateTime(2009, 5, 26, 22, 24, 04),
            WebURL = "http://ccnetlive.thoughtworks.com/ccnet/server/local/project/CCNet/ViewLatestBuildReport.aspx",
            BuildStage = string.Empty,
            ServerName = "CCNETLIVE"
        };
        private readonly QueueSnapshot queueFrom144 = new QueueSnapshot
        {
            QueueName = "CCNet"
        };
        private readonly QueuedRequestSnapshot requestFrom144 = new QueuedRequestSnapshot
        {
            Activity = ProjectActivity.Building,
            ProjectName = "CCNet"
        };
        private MockRepository mocks = new MockRepository();
        #endregion

        [Test]
        public void GetProjectStatusCorrectlyHandlesRelativePath()
        {
            var webClient = mocks.StrictMock<WebClient>();
            Expect.Call(webClient.DownloadString("http://relative/XmlStatusReport.aspx"))
                .Return(xmlFrom11);
            var client = new CruiseServerHttpClient("http://relative", webClient);

            mocks.ReplayAll();
            var results = client.GetProjectStatus();

            Assert.IsNotNull(results, "No projects parsed");
            Assert.AreEqual(1, results.Length, "Unexpected number of projects returned");
            CompareProjects(projectFrom11, results[0]);
            mocks.VerifyAll();
        }

        [Test]
        public void ForceBuildCorrectlyHandlesRelativePath()
        {
            var webClient = mocks.StrictMock<WebClient>();
            Expect.Call(webClient.UploadValues("http://relative/ViewFarmReport.aspx", null))
                .IgnoreArguments()
                .Return(new byte[0]);
            var client = new CruiseServerHttpClient("http://relative", webClient);

            mocks.ReplayAll();
            client.ForceBuild("Project1");

            mocks.VerifyAll();
        }

        [Test]
        public void GetProjectStatusCorrectlyHandles1_1Data()
        {
            var webClient = mocks.StrictMock<WebClient>();
            Expect.Call(webClient.DownloadString("http://relative/XmlStatusReport.aspx"))
                .Return(xmlFrom11);
            var client = new CruiseServerHttpClient("http://relative", webClient);

            mocks.ReplayAll();
            var results = client.GetProjectStatus();

            Assert.IsNotNull(results, "No projects parsed");
            Assert.AreEqual(1, results.Length, "Unexpected number of projects returned");
            CompareProjects(projectFrom11, results[0]);
            mocks.VerifyAll();
        }

        [Test]
        public void GetProjectStatusCorrectlyHandles1_4_4Data()
        {
            var webClient = mocks.StrictMock<WebClient>();
            Expect.Call(webClient.DownloadString("http://relative/XmlServerReport.aspx"))
                .Return(xmlFrom144);
            var client = new CruiseServerHttpClient("http://relative", webClient);

            mocks.ReplayAll();
            var results = client.GetCruiseServerSnapshot();

            Assert.IsNotNull(results, "Snapshot not parsed");
            Assert.AreEqual(1, results.ProjectStatuses.Length, "Unexpected number of projects returned");
            CompareProjects(projectFrom144, results.ProjectStatuses[0]);
            Assert.AreEqual(1, results.QueueSetSnapshot.Queues.Count, "Unexpected number of queues returned");
            Assert.AreEqual(queueFrom144.QueueName, results.QueueSetSnapshot.Queues[0].QueueName, "Queue name does not match");
            Assert.AreEqual(1, results.QueueSetSnapshot.Queues[0].Requests.Count, "Unexpected number of queue requests returned");
            Assert.AreEqual(requestFrom144.Activity, results.QueueSetSnapshot.Queues[0].Requests[0].Activity, "Queue request activity does not match");
            Assert.AreEqual(requestFrom144.ProjectName, results.QueueSetSnapshot.Queues[0].Requests[0].ProjectName, "Queue request project name does not match");

            mocks.VerifyAll();
        }

        [Test]
        public void GetProjectStatusCorrectlyHandlesCCData()
        {
            var webClient = mocks.StrictMock<WebClient>();
            Expect.Call(webClient.DownloadString("http://relative/XmlStatusReport.aspx"))
                .Return(xmlFromCC);
            var client = new CruiseServerHttpClient("http://relative", webClient);

            mocks.ReplayAll();
            var results = client.GetProjectStatus();

            Assert.IsNotNull(results, "No projects parsed");
            Assert.AreEqual(1, results.Length, "Unexpected number of projects returned");
            CompareProjects(projectFromCC, results[0]);
            mocks.VerifyAll();
        }

        private void CompareProjects(ProjectStatus expected, ProjectStatus actual)
        {
            var dateFormat = "yyyy-MM-ddTHH:mm:ss";     // For some reason .NET will give slightly different results for date/times
            Assert.AreEqual(expected.Name, actual.Name, "Name does not match");
            Assert.AreEqual(expected.Category, actual.Category, "Category does not match");
            Assert.AreEqual(expected.Activity, actual.Activity, "Activity does not match");
            Assert.AreEqual(expected.BuildStatus, actual.BuildStatus, "BuildStatus does not match");
            Assert.AreEqual(expected.LastBuildLabel, actual.LastBuildLabel, "LastBuildLabel does not match");
            Assert.AreEqual(expected.LastBuildDate.ToString(dateFormat), actual.LastBuildDate.ToString(dateFormat), "LastBuildDate does not match");
            Assert.AreEqual(expected.NextBuildTime.ToString(dateFormat), actual.NextBuildTime.ToString(dateFormat), "NextBuildTime does not match");
            Assert.AreEqual(expected.WebURL, actual.WebURL, "WebURL does not match");
            Assert.AreEqual(expected.BuildStage, actual.BuildStage, "BuildStage does not match");
            Assert.AreEqual(expected.ServerName, actual.ServerName, "ServerName does not match");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.