From cbb7d6415139ca8c1e82f6b67c60eeeffc947524 Mon Sep 17 00:00:00 2001 From: Simona Avornicesei Date: Wed, 22 Jan 2020 00:35:24 +0200 Subject: [PATCH] #286 Fix PR: Change NUnit v2 to v3 - fix some broken tests - detect latest MSBuild available - fix cake script --- .gitignore | 9 +- Tools/ccnet-utils.inc.build | 102 +++++++++++++++++- build.cake | 2 +- ccnet.build | 86 ++++++++++----- project/UnitTests/CCnetDeploymentTests.cs | 5 +- .../Core/Label/DefaultLabellerTest.cs | 4 +- project/UnitTests/GlobalSetup.cs | 18 ++++ project/UnitTests/TestHelpers.cs | 14 +-- project/UnitTests/UnitTests.csproj | 3 +- .../WebDashboard/IO/FingerprintFactoryTest.cs | 4 +- 10 files changed, 203 insertions(+), 44 deletions(-) create mode 100644 project/UnitTests/GlobalSetup.cs diff --git a/.gitignore b/.gitignore index f160e3530..245d973cf 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,11 @@ docgen/ wiki/ **/CommonAssemblyInfo.cs +#ignore NuGet tools +[Tt]ools/EWSoftware.SHFB* +[Tt]ools/vswhere* +[Tt]ools/NUnit.ConsoleRunner* + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## @@ -366,4 +371,6 @@ _site/ #cake [Tt]ools/Cake/* -![Tt]ools/Cake/packages.config \ No newline at end of file +![Tt]ools/Cake/packages.config + +thelabelprefix.txt diff --git a/Tools/ccnet-utils.inc.build b/Tools/ccnet-utils.inc.build index 4bcd0775d..15435902f 100644 --- a/Tools/ccnet-utils.inc.build +++ b/Tools/ccnet-utils.inc.build @@ -11,5 +11,105 @@ - + + + + \ No newline at end of file diff --git a/build.cake b/build.cake index 237523639..83b9fb8a4 100644 --- a/build.cake +++ b/build.cake @@ -96,7 +96,7 @@ Task("build-all") //Tools\NAnt\NAnt.exe clean build -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build.log.txt %* using(var process = StartAndReturnProcess(nantExe, new ProcessSettings{ - Arguments = " all -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build.log.txt" , + Arguments = " all -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build-all.log.txt" , RedirectStandardError = false, RedirectStandardOutput = false, Silent = false diff --git a/ccnet.build b/ccnet.build index 225ef3523..53081774a 100644 --- a/ccnet.build +++ b/ccnet.build @@ -31,9 +31,14 @@ - + + + - + + + + @@ -90,6 +95,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -138,23 +165,40 @@ + + + + + + + + + + + + + + + + + + + + + - + + + - + - - - - - - - - + + @@ -223,23 +267,11 @@ - - - - + + + diff --git a/project/UnitTests/CCnetDeploymentTests.cs b/project/UnitTests/CCnetDeploymentTests.cs index 16a06ce8a..e399f7e86 100644 --- a/project/UnitTests/CCnetDeploymentTests.cs +++ b/project/UnitTests/CCnetDeploymentTests.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using NUnit.Framework; namespace ThoughtWorks.CruiseControl.UnitTests @@ -18,9 +19,9 @@ public class CCnetDeploymentTests public void TestForAdminPackageOfWebDashboardIsEmpty() { #if DEBUG - string configFile = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"..\..\..\Webdashboard\dashboard.config"); + string configFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\Webdashboard\dashboard.config"); #else - string configFile = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"..\..\Project\Webdashboard\dashboard.config"); + string configFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"..\..\Project\Webdashboard\dashboard.config"); #endif Assert.IsTrue(System.IO.File.Exists(configFile), "Dashboard.config not found at {0}", configFile); diff --git a/project/UnitTests/Core/Label/DefaultLabellerTest.cs b/project/UnitTests/Core/Label/DefaultLabellerTest.cs index acc7d1070..8552b1674 100644 --- a/project/UnitTests/Core/Label/DefaultLabellerTest.cs +++ b/project/UnitTests/Core/Label/DefaultLabellerTest.cs @@ -263,7 +263,7 @@ public void GeneratePrefixedLabelFromLabelPrefixFileAndLabelPrefixsFileSearchPat [Test] public void MustThrowExceptionWhenSpecifyingNonExistentFile() { - var ex = Assert.Throws(() => + var ex = Assert.Throws(() => { string lblFile = "DummyFile.txt"; @@ -278,7 +278,7 @@ public void MustThrowExceptionWhenSpecifyingNonExistentFile() [Test] public void MustThrowExceptionWhenContentsOfLabelPrefixFileDoesNotMatchLabelPrefixsFileSearchPattern() { - var ex = Assert.Throws(() => + var ex = Assert.Throws(() => { string lblFile = "thelabelprefix.txt"; System.IO.File.WriteAllText(lblFile, "ho ho ho"); diff --git a/project/UnitTests/GlobalSetup.cs b/project/UnitTests/GlobalSetup.cs new file mode 100644 index 000000000..a4385d515 --- /dev/null +++ b/project/UnitTests/GlobalSetup.cs @@ -0,0 +1,18 @@ +using System; +using System.IO; +using NUnit.Framework; + +namespace ThoughtWorks.CruiseControl.UnitTests +{ + [SetUpFixture] + public class GlobalSetup + { + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; + // or identically under the hoods + //Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } + } +} diff --git a/project/UnitTests/TestHelpers.cs b/project/UnitTests/TestHelpers.cs index d486475dd..493e75e6b 100644 --- a/project/UnitTests/TestHelpers.cs +++ b/project/UnitTests/TestHelpers.cs @@ -8,7 +8,7 @@ namespace ThoughtWorks.CruiseControl.UnitTests { /// - /// Helper methods for testing the serialisation/deserialisation of objects. + /// Helper methods for testing the serialization / serialization of objects. /// public static class TestHelpers { @@ -21,13 +21,13 @@ public static void EnsureLanguageIsValid() } /// - /// Tests that an object can be serialised and de-serialised. + /// Tests that an object can be serialized and deserialized. /// /// The value to test. - /// The de-serialised object. + /// The deserialized object. /// - /// This does not test that the de-serialised object is the same as the source, it only tests - /// that the object can actually be serialised and de-serialised. + /// This does not test that the deserialized object is the same as the source, it only tests + /// that the object can actually be serialized and deserialized. /// public static object RunSerialisationTest(object value) { @@ -40,7 +40,7 @@ public static object RunSerialisationTest(object value) } catch (Exception error) { - Assert.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Unable to serialise: {0}", error.Message)); + Assert.Fail(string.Format(CultureInfo.CurrentCulture,"Unable to serialize: {0}", error.Message)); } stream.Position = 0; @@ -50,7 +50,7 @@ public static object RunSerialisationTest(object value) } catch (Exception error) { - Assert.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Unable to deserialise: {0}", error.Message)); + Assert.Fail(string.Format(CultureInfo.CurrentCulture,"Unable to serialize: {0}", error.Message)); } return result; } diff --git a/project/UnitTests/UnitTests.csproj b/project/UnitTests/UnitTests.csproj index 6097ad511..8a610a5c2 100644 --- a/project/UnitTests/UnitTests.csproj +++ b/project/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + @@ -428,6 +428,7 @@ + diff --git a/project/UnitTests/WebDashboard/IO/FingerprintFactoryTest.cs b/project/UnitTests/WebDashboard/IO/FingerprintFactoryTest.cs index 718ea4090..19402cdce 100644 --- a/project/UnitTests/WebDashboard/IO/FingerprintFactoryTest.cs +++ b/project/UnitTests/WebDashboard/IO/FingerprintFactoryTest.cs @@ -53,7 +53,7 @@ public void ShouldBuildAFingerprintWithValuesFromRequestIfBothHeadersAreAvailabl } [Test] - [Ignore] + [Ignore("TODO: provide a reason")] public void ShouldFailGracefullyWithDatesFromBrowserWhichAreNotInRfc1123FormatByReturningValidButIncorrectFingerprint() { DateTime lastModifiedDate = new DateTime(2007, 4, 20); @@ -81,4 +81,4 @@ public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFrom Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag); } } -} \ No newline at end of file +}