Skip to content

Commit

Permalink
ccnet#286 Fix PR: Change NUnit v2 to v3
Browse files Browse the repository at this point in the history
- fixed failing tests
- added FluentAssertions library
- compact build target in ccnet.build
- fixed assembly bindings errors in UnitTests project
  • Loading branch information
savornicesei committed Jan 26, 2020
1 parent 5d8c162 commit 32020a5
Show file tree
Hide file tree
Showing 32 changed files with 313 additions and 127 deletions.
32 changes: 13 additions & 19 deletions ccnet.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- properties -->
<property name="nant.verbosity" overwrite="false" value="false" />
<property name="build.configuration" overwrite="false" value="Build" />
<property name="build.target" overwrite="false" value="Build" />
<property name="build.target" overwrite="false" value="Clean;Build" />
<property name="build.project" overwrite="false" value="ccnet.sln" />
<property name="build.target.framework" overwrite="false" value="4.5" />
<property name="codemetrics.output.type" overwrite="false" value="XmlFile" />
Expand Down Expand Up @@ -36,7 +36,10 @@
<property name="nuget.executable" value="${path::combine( path::combine(tools.dir, 'Cake'), 'nuget.exe')}" if="${not environment::variable-exists('NUGET_EXE')}" />

<!-- NuGet tools retrieved at restore time -->
<property name="vswhere.executable" value="${path::combine( path::combine(path::combine(tools.dir, 'vswhere.2.8.4'), 'tools'), 'vswhere.exe')}" unless="${property::exists('vswhere.path')}" />
<if test="${not property::exists('vswhere.executable')}">
<property name="vswhere.executable" value="${path::combine( path::combine(path::combine(tools.dir, 'vswhere.2.8.4'), 'tools'), 'vswhere.exe')}" if="${platform::is-windows()}" />
<property name="vswhere.executable" value="" if="${platform::is-unix()}" />
</if>
<property name="shfb.path" value="${path::combine( path::combine(tools.dir, 'EWSoftware.SHFB.2019.11.17'), 'tools')}" unless="${property::exists('shfb.path')}" />
<property name="nunit.executable" value="${path::combine( path::combine(path::combine(tools.dir, 'NUnit.ConsoleRunner.3.10.0'), 'tools'), 'nunit3-console.exe')}" unless="${property::exists('nunit.executable')}" />

Expand All @@ -62,7 +65,7 @@
<include buildfile="${path::combine(tools.dir, 'ccnet-packaging-webdashboard-packages.inc.build')}" />

<!-- Targets -->
<target name="all" depends="clean, init, build, runTests, runCodeMetrics, package" description="" />
<target name="all" depends="build, runTests, runCodeMetrics, package" description="" />


<target name="ClearDocFolders" description="Clearing doc folder of all existing files.">
Expand Down Expand Up @@ -135,7 +138,7 @@
</exec>
</target>

<target name="init" description="Initial compilation setup">
<target name="init" depends="clean" description="Initial compilation setup">
<mkdir dir="${build.dir}" unless="${directory::exists(build.dir)}" verbose="${nant.verbosity}" />
<mkdir dir="${build.metrics.dir}" unless="${directory::exists(build.metrics.dir)}" verbose="${nant.verbosity}" />
<mkdir dir="${publish.dir}" unless="${directory::exists(publish.dir)}" verbose="${nant.verbosity}" />
Expand Down Expand Up @@ -167,9 +170,13 @@
<echo message="Build Directory: ${build.dir}" />
<echo message="MSBuild path: ${build.dir}" />

<property name="msbuild.file" value="${framework::get-msbuild-path(vswhere.executable)}" />
<property name="msbuild.exe" value="${msbuild.file}" if="${platform::is-windows()}" />
<property name="msbuild.exe" value="mono" if="${platform::is-unix()}" />

<!-- build for Linux - msbuild task still uses xbuild that was deprecated starting with mono 5.0 -->
<exec program="mono" if="${platform::is-unix()}" basedir="${src.dir}" workingdir="${src.dir}" verbose="${nant.verbosity}">
<arg value="${framework::get-msbuild-path('')}" />
<exec program="${msbuild.exe}" basedir="${src.dir}" workingdir="${src.dir}" verbose="${nant.verbosity}">
<arg value="msbuild.file" if="${platform::is-unix()}"/>
<arg value="${path::combine(src.dir, build.project)}" />
<arg value="/t:${build.target}" />
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>
Expand All @@ -187,19 +194,6 @@
<arg value="/p:MONO_PATH=${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</exec>

<exec program="${framework::get-msbuild-path(vswhere.executable)}" if="${platform::is-windows()}" basedir="${src.dir}" workingdir="${src.dir}" verbose="${nant.verbosity}">
<arg value="${path::combine(src.dir, build.project)}" />
<arg value="/t:${build.target}" />
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>

<!-- This is a hack until CCTrayLib uses plugins for Windows only stuff -->
<arg value="/p:DISABLE_COM=${platform::is-unix()}" />

<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<arg value="/p:DISABLE_JSCRIPT=${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</exec>

<!-- copy ccnet.config into the server dictionary -->
<copy file="${path::combine( path::combine(src.dir, 'service'), 'ccnet.config')}" tofile="${path::combine( path::combine(build.dir, 'Server'), 'ccnet.config')}" verbose="${nant.verbosity}"/>
</target>
Expand Down
70 changes: 41 additions & 29 deletions project/UnitTests/Core/SourceControl/FileSourceControlTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using FluentAssertions;
using FluentAssertions.Execution;
using Moq;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core;
Expand Down Expand Up @@ -69,23 +71,28 @@ public void GetModifications_EmptyLocal()

Modification[] mods = sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue));

Assert.AreEqual(4, mods.Length);
Assert.AreEqual("file1.txt", mods[0].FileName);
Assert.AreEqual("file2.txt", mods[1].FileName);
Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FileName);
Assert.AreEqual("file3.txt", mods[3].FileName);
Assert.AreEqual(Path.GetDirectoryName(file1), mods[0].FolderName);
Assert.AreEqual(Path.GetDirectoryName(file2), mods[1].FolderName);
Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FolderName);
Assert.AreEqual(Path.GetDirectoryName(file3), mods[3].FolderName);

Assert.AreEqual(new FileInfo(file1).LastWriteTime, mods[0].ModifiedTime);
Assert.AreEqual(new FileInfo(file2).LastWriteTime, mods[1].ModifiedTime);
Assert.AreEqual(new FileInfo(tempSubRoot.ToString()).LastWriteTime, mods[2].ModifiedTime);
Assert.AreEqual(new FileInfo(file3).LastWriteTime, mods[3].ModifiedTime);

mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue));
Assert.AreEqual(0, mods.Length);
using( new AssertionScope())
{
mods.Length.Should().Be(4);
mods[0].FileName.Should().Be("file1.txt");
mods[1].FileName.Should().Be("file2.txt");
mods[2].FileName.Should().Be(Path.GetFileName(tempSubRoot.ToString()));
mods[3].FileName.Should().Be("file3.txt");

mods[0].FolderName.Should().Be(Path.GetDirectoryName(file1));
mods[1].FolderName.Should().Be(Path.GetDirectoryName(file2));
mods[2].FolderName.Should().Be(Path.GetFileName(tempSubRoot.ToString()));
mods[3].FolderName.Should().Be(Path.GetDirectoryName(file3));

new FileInfo(file1).LastWriteTime.Should().BeCloseTo(mods[0].ModifiedTime, 100);
new FileInfo(file2).LastWriteTime.Should().BeCloseTo(mods[1].ModifiedTime, 100);
new FileInfo(tempSubRoot.ToString()).LastWriteTime.Should().BeCloseTo(mods[2].ModifiedTime, 100);
new FileInfo(file3).LastWriteTime.Should().BeCloseTo(mods[3].ModifiedTime, 100);
}

mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue));

mods.Length.Should().Be(0);
}

[Test]
Expand Down Expand Up @@ -151,20 +158,25 @@ public void GetModifications_NonRecursive()

Modification[] mods = sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue));

Assert.AreEqual(3, mods.Length);
Assert.AreEqual("file1.txt", mods[0].FileName);
Assert.AreEqual("file2.txt", mods[1].FileName);
Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FileName);
Assert.AreEqual(Path.GetDirectoryName(file1), mods[0].FolderName);
Assert.AreEqual(Path.GetDirectoryName(file2), mods[1].FolderName);
Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FolderName);
using(new AssertionScope())
{
mods.Length.Should().Be(3);

mods[0].FileName.Should().Be("file1.txt");
mods[1].FileName.Should().Be("file2.txt");
mods[2].FileName.Should().Be(Path.GetFileName(tempSubRoot.ToString()));

Assert.AreEqual(new FileInfo(file1).LastWriteTime, mods[0].ModifiedTime);
Assert.AreEqual(new FileInfo(file2).LastWriteTime, mods[1].ModifiedTime);
Assert.AreEqual(new FileInfo(tempSubRoot.ToString()).LastWriteTime, mods[2].ModifiedTime);
mods[0].FolderName.Should().Be(Path.GetDirectoryName(file1));
mods[1].FolderName.Should().Be(Path.GetDirectoryName(file2));
mods[2].FolderName.Should().Be(Path.GetFileName(tempSubRoot.ToString()));

new FileInfo(file1).LastWriteTime.Should().BeCloseTo(mods[0].ModifiedTime, 100);
new FileInfo(file2).LastWriteTime.Should().BeCloseTo(mods[1].ModifiedTime, 100);
new FileInfo(tempSubRoot.ToString()).LastWriteTime.Should().BeCloseTo(mods[2].ModifiedTime, 100);
}

mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue));
Assert.AreEqual(0, mods.Length);
mods.Length.Should().Be(0);
}
}
}
}
8 changes: 6 additions & 2 deletions project/UnitTests/Remote/ItemStatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote;

public class ItemStatusTests
Expand Down Expand Up @@ -155,7 +157,9 @@ public void ToStringGeneratesXml()
"</childItem>" +
"</childItems>" +
"</itemStatus>";
Assert.AreEqual(expected, xml);
//Assert.AreEqual(expected, xml);

XDocument.Parse(xml).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand Down
23 changes: 16 additions & 7 deletions project/UnitTests/Remote/Messages/BuildIntegrationRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote;
using ThoughtWorks.CruiseControl.Remote.Messages;
Expand Down Expand Up @@ -48,11 +51,15 @@ public void InitialiseRequestWithSessionAndProjectSetsTheCorrectValues()
string projectName = "the project";
DateTime now = DateTime.Now;
BuildIntegrationRequest request = new BuildIntegrationRequest(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");

using (new AssertionScope())
{
request.Identifier.Should().NotBeNullOrEmpty("Identifier should be set");
request.SourceName.Should().BeEquivalentTo(Environment.MachineName, "SourceName should match the machine name");
request.SessionToken.Should().BeEquivalentTo(sessionToken, "SessionToken should match the input token");
request.ProjectName.Should().BeEquivalentTo(projectName, "ProjectName should match the input project name");
request.Timestamp.Should().Be(now, "Timestamp must be set");
}
}

[Test]
Expand All @@ -66,7 +73,8 @@ public void ToStringSerialisesDefaultValues()
request.SourceName,
request.Timestamp,
request.BuildCondition);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -93,7 +101,8 @@ public void ToStringSerialisesAllValues()
request.Timestamp,
request.ProjectName,
request.BuildCondition);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
8 changes: 6 additions & 2 deletions project/UnitTests/Remote/Messages/BuildListRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;
using ThoughtWorks.CruiseControl.Remote;
using System.Xml.Linq;
using FluentAssertions;

namespace ThoughtWorks.CruiseControl.UnitTests.Remote.Messages
{
Expand Down Expand Up @@ -52,7 +54,8 @@ public void ToStringSerialisesDefaultValues()
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -73,7 +76,8 @@ public void ToStringSerialisesAllValues()
request.SourceName,
request.SessionToken,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;
using ThoughtWorks.CruiseControl.Remote.Parameters;
Expand Down Expand Up @@ -55,7 +57,8 @@ public void ToStringSerialisesDefaultValues()
"timestamp=\"{1:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" result=\"{0}\" />",
response.Result,
response.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -82,7 +85,8 @@ public void ToStringSerialisesAllValues()
response.RequestIdentifier,
response.Result,
response.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
8 changes: 6 additions & 2 deletions project/UnitTests/Remote/Messages/BuildRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;
using ThoughtWorks.CruiseControl.Remote;
using System.Xml.Linq;
using FluentAssertions;

namespace ThoughtWorks.CruiseControl.UnitTests.Remote.Messages
{
Expand Down Expand Up @@ -52,7 +54,8 @@ public void ToStringSerialisesDefaultValues()
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -73,7 +76,8 @@ public void ToStringSerialisesAllValues()
request.SourceName,
request.SessionToken,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;
using ThoughtWorks.CruiseControl.Remote;
using System.Xml.Linq;
using FluentAssertions;

namespace ThoughtWorks.CruiseControl.UnitTests.Remote.Messages
{
Expand Down Expand Up @@ -59,7 +61,8 @@ public void ToStringSerialisesDefaultValues()
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -86,7 +89,8 @@ public void ToStringSerialisesAllValues()
request.SourceName,
request.SessionToken,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Remote.Messages;

Expand Down Expand Up @@ -29,7 +31,8 @@ public void ToStringSerialisesDefaultValues()
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}

[Test]
Expand All @@ -55,7 +58,8 @@ public void ToStringSerialisesAllValues()
request.OldPassword,
request.NewPassword,
request.UserName);
Assert.AreEqual(expected, actual);

XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
}
}
}
Loading

0 comments on commit 32020a5

Please sign in to comment.