using System;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;
namespace ThoughtWorks.CruiseControl.UnitTests.Remote.Messages{
[TestFixture]
public class ProjectRequestTests
{
[Test]
public void GetSetAllPropertiesWorks()
{
ProjectRequest request = new ProjectRequest();
request.ProjectName = "new project";
Assert.AreEqual("new project", request.ProjectName, "ProjectName fails the get/set test");
}
[Test]
public void InitialiseRequestWithSessionSetsTheCorrectValues()
{
string sessionToken = "the session";
DateTime now = DateTime.Now;
ProjectRequest request = new ProjectRequest(sessionToken);
Assert.IsFalse(string.IsNullOrEmpty(request.Identifier), "Identifier was not set");
Assert.AreEqual(Environment.MachineName, request.SourceName, "Source name doesn't match the machine name");
Assert.AreEqual(sessionToken, request.SessionToken, "SessionToken doesn't match the input token");
Assert.IsTrue((now <= request.Timestamp), "Timestamp was not set");
}
[Test]
public void InitialiseRequestWithSessionAndProjectSetsTheCorrectValues()
{
string sessionToken = "the session";
string projectName = "the project";
DateTime now = DateTime.Now;
ProjectRequest request = new ProjectRequest(sessionToken, projectName);
Assert.IsFalse(string.IsNullOrEmpty(request.Identifier), "Identifier was not set");
Assert.AreEqual(Environment.MachineName, request.SourceName, "Source name doesn't match the machine name");
Assert.AreEqual(sessionToken, request.SessionToken, "SessionToken doesn't match the input token");
Assert.AreEqual(projectName, request.ProjectName, "ProjectName doesn't match the input project name");
Assert.IsTrue((now <= request.Timestamp), "Timestamp was not set");
}
[Test]
public void ToStringSerialisesDefaultValues()
{
ProjectRequest request = new ProjectRequest();
string actual = request.ToString();
string expected = string.Format("<projectMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" source=\"{1}\" />",
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);
}
[Test]
public void ToStringSerialisesAllValues()
{
ProjectRequest request = new ProjectRequest();
request.Identifier = "identifier";
request.ProjectName = "projectName";
request.ServerName = "serverName";
request.SessionToken = "sessionToken";
request.SourceName = "sourceName";
request.Timestamp = DateTime.Now;
string actual = request.ToString();
string expected = string.Format("<projectMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"timestamp=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" server=\"{1}\" source=\"{2}\" session=\"{3}\" project=\"{5}\" />",
request.Identifier,
request.ServerName,
request.SourceName,
request.SessionToken,
request.Timestamp,
request.ProjectName);
Assert.AreEqual(expected, actual);
}
}
}
|