From 3656cbf0ae82a09057e4fec0fbc09dc73c0378ab Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:01:11 +0100 Subject: [PATCH 1/8] Run on Windows and Ubuntu --- .github/workflows/dotnet-core-desktop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index 2473173..b277e05 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -52,7 +52,7 @@ jobs: matrix: configuration: [Debug, Release] - runs-on: windows-latest # For a list of available runner types, refer to + runs-on: [windows-latest, ubuntu-latest] # For a list of available runner types, refer to # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on env: From 916235db1bd945096b9c177b561a82840bda4db1 Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:06:14 +0100 Subject: [PATCH 2/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index b277e05..8e15d82 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -45,14 +45,13 @@ on: branches: [ master ] jobs: - - build: + build_windows: strategy: matrix: configuration: [Debug, Release] - runs-on: [windows-latest, ubuntu-latest] # For a list of available runner types, refer to + runs-on: windows-latest # For a list of available runner types, refer to # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on env: @@ -85,4 +84,26 @@ jobs: run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration env: Configuration: ${{ matrix.configuration }} + + + build_ubuntu: + runs-on: ubuntu-latest + + strategy: + matrix: + configuration: [Debug, Release] + env: + Solution_Name: eawx-build.sln # Replace with your solution name, i.e. MyWpfApp.sln. + Test_Project_Path: eawx-build-test/eawx-build-test.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj. + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + + steps: + - name: Setup .NET Core SDK + uses: actions/setup-dotnet@v1.7.2 + with: + dotnet-version: 3.1.101 + + # Execute all unit tests in the solution + - name: Execute unit tests + run: dotnet test From 8304004bf83d1cd8ec1edb610b0873e8fbc0f496 Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:08:27 +0100 Subject: [PATCH 3/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index 8e15d82..cbd6ab4 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -99,6 +99,9 @@ jobs: ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: + - name: Install zlib + run: sudo apt-get install -y zlib1g + - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1.7.2 with: From a158dc4d25874d4a6fd0c333a49acc79bf63f4b2 Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:11:52 +0100 Subject: [PATCH 4/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index cbd6ab4..b729fd9 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -109,4 +109,4 @@ jobs: # Execute all unit tests in the solution - name: Execute unit tests - run: dotnet test + run: dotnet test Test_Project_Path From db2944e429778822235277a95da3dc04bdbf8c5d Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:12:53 +0100 Subject: [PATCH 5/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index b729fd9..c9e8ca7 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -109,4 +109,4 @@ jobs: # Execute all unit tests in the solution - name: Execute unit tests - run: dotnet test Test_Project_Path + run: dotnet test $env:Test_Project_Path From 216f3ca5e87a734650eadc2263ec1b851ea3cd5b Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:14:45 +0100 Subject: [PATCH 6/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index c9e8ca7..9ac97ee 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -109,4 +109,4 @@ jobs: # Execute all unit tests in the solution - name: Execute unit tests - run: dotnet test $env:Test_Project_Path + run: dotnet test eawx-build-test/eawx-build-test.csproj From 3e3d7d314cfdf678b26f4ab218ba2fcf1df1d9a9 Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Fri, 29 Jan 2021 02:16:26 +0100 Subject: [PATCH 7/8] Update dotnet-core-desktop.yml --- .github/workflows/dotnet-core-desktop.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index 9ac97ee..03cf644 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -102,6 +102,11 @@ jobs: - name: Install zlib run: sudo apt-get install -y zlib1g + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1.7.2 with: @@ -109,4 +114,4 @@ jobs: # Execute all unit tests in the solution - name: Execute unit tests - run: dotnet test eawx-build-test/eawx-build-test.csproj + run: dotnet test From c992bc6f8305afa589aaf1b20b8602710842f047 Mon Sep 17 00:00:00 2001 From: Sven Marcus Date: Wed, 3 Feb 2021 11:42:14 +0100 Subject: [PATCH 8/8] Introduce custom TestMethod Attributes for Platform and Environment --- .../EawXBuildApplicationLuaAcceptanceTest.cs | 4 +- .../EawXBuildApplicationXmlAcceptanceTest.cs | 8 +-- eawx-build-test/Native/FileLinkerTest.cs | 28 +++------- eawx-build-test/Services/IO/IOServiceTest.cs | 23 +++----- .../Services/Process/ProcessRunnerTest.cs | 53 +++++++++++++++++-- .../FacepunchSteamWorkshopAdapterTest.cs | 8 +-- .../FacepunchWorkshopItemAdapterTest.cs | 19 ++----- eawx-build-test/TestAttributes.cs | 39 ++++++++++++++ 8 files changed, 116 insertions(+), 66 deletions(-) create mode 100644 eawx-build-test/TestAttributes.cs diff --git a/eawx-build-test/EawXBuildApplicationLuaAcceptanceTest.cs b/eawx-build-test/EawXBuildApplicationLuaAcceptanceTest.cs index 447a796..2999a50 100644 --- a/eawx-build-test/EawXBuildApplicationLuaAcceptanceTest.cs +++ b/eawx-build-test/EawXBuildApplicationLuaAcceptanceTest.cs @@ -60,8 +60,8 @@ public void GivenConfig_With_OneProject_OneJob_And_CopyTask__WhenRunning__Should Assert.IsTrue(actual); } - [TestMethod] - public void GivenConfig_With_OneProject_OneJob_And_RunProcessTask__WhenRunning__ShouldRunProcess() { + [PlatformSpecificTestMethod("Linux", "OSX")] + public void GivenUnixLikeSystem_And_Config_With_OneProject_OneJob_And_RunProcessTask__WhenRunning__ShouldRunProcess() { const string config = @" local proj = project('pid0') local job = proj:add_job('My-Job') diff --git a/eawx-build-test/EawXBuildApplicationXmlAcceptanceTest.cs b/eawx-build-test/EawXBuildApplicationXmlAcceptanceTest.cs index e4bb8ab..9a15671 100644 --- a/eawx-build-test/EawXBuildApplicationXmlAcceptanceTest.cs +++ b/eawx-build-test/EawXBuildApplicationXmlAcceptanceTest.cs @@ -55,7 +55,7 @@ public class EawXBuildXmlApplicationTest { [TestInitialize] public void SetUp() { - _services = ConfigureServices(_fileSystem); + _services = ConfigureServices(); } [TestCleanup] @@ -91,8 +91,8 @@ public void WhenRunningWith_OneProject_OneJob_And_CopyTask__ShouldCopyFileToTarg Assert.IsTrue(actual); } - [TestMethod] - public void WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgram() { + [PlatformSpecificTestMethod("Linux", "OSX")] + public void GivenUnixLikeSystem__WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgram() { var options = new RunOptions { BackendXml = true, ConfigPath = "eaw-ci.xml", @@ -112,7 +112,7 @@ public void WhenRunningWith_OneProject_OneJob_And_RunProgramTask__ShouldRunProgr Assert.AreEqual("Hello World", actual); } - private static ServiceCollection ConfigureServices(IFileSystem fileSystem, LogLevel logLevel = LogLevel.None) { + private static ServiceCollection ConfigureServices(LogLevel logLevel = LogLevel.None) { var services = new ServiceCollection(); services.AddLogging(builder => builder.AddConsole()); services.Configure(options => diff --git a/eawx-build-test/Native/FileLinkerTest.cs b/eawx-build-test/Native/FileLinkerTest.cs index e6ad7fb..048d2c3 100644 --- a/eawx-build-test/Native/FileLinkerTest.cs +++ b/eawx-build-test/Native/FileLinkerTest.cs @@ -34,10 +34,8 @@ public void TearDown() { Assert.IsFalse(_fileSystem.File.Exists(GetPlatformTargetPath())); } - [TestMethod] + [PlatformSpecificTestMethod("OSX")] public void GivenRunningMacOS__WhenLinkingFileWithUnixStylePath__FileShouldExist() { - if (!TestUtility.IsMacOS()) Assert.Inconclusive(); - var sut = new MacOSFileLinker(); sut.CreateLink(UnixFilePath, UnixLinkedFilePath); @@ -45,10 +43,8 @@ public void GivenRunningMacOS__WhenLinkingFileWithUnixStylePath__FileShouldExist Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath)); } - [TestMethod] + [PlatformSpecificTestMethod("OSX")] public void GivenRunningMacOS__WhenLinkingFileWithWinStylePath__FileShouldExist() { - if (!TestUtility.IsMacOS()) Assert.Inconclusive(); - var sut = new MacOSFileLinker(); sut.CreateLink(WinFilePath, WinLinkedFilePath); @@ -56,10 +52,8 @@ public void GivenRunningMacOS__WhenLinkingFileWithWinStylePath__FileShouldExist( Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath)); } - [TestMethod] + [PlatformSpecificTestMethod("Windows")] public void GivenRunningWindows__WhenLinkingFileWithUnixStylePath__FileShouldExist() { - if (!TestUtility.IsWindows()) Assert.Inconclusive(); - var sut = new WinFileLinker(); sut.CreateLink(UnixFilePath, UnixLinkedFilePath); @@ -67,10 +61,8 @@ public void GivenRunningWindows__WhenLinkingFileWithUnixStylePath__FileShouldExi Assert.IsTrue(_fileSystem.File.Exists(WinLinkedFilePath)); } - [TestMethod] + [PlatformSpecificTestMethod("Windows")] public void GivenRunningWindows__WhenLinkingFileWithWinStylePath__FileShouldExist() { - if (!TestUtility.IsWindows()) Assert.Inconclusive(); - var sut = new WinFileLinker(); sut.CreateLink(WinFilePath, WinLinkedFilePath); @@ -78,10 +70,8 @@ public void GivenRunningWindows__WhenLinkingFileWithWinStylePath__FileShouldExis Assert.IsTrue(_fileSystem.File.Exists(WinLinkedFilePath)); } - [TestMethod] + [PlatformSpecificTestMethod("Linux")] public void GivenRunningLinux__WhenLinkingFileWithUnixStylePath__FileShouldExist() { - if (!TestUtility.IsLinux()) Assert.Inconclusive(); - var sut = new LinuxFileLinker(); sut.CreateLink(UnixFilePath, UnixLinkedFilePath); @@ -89,10 +79,8 @@ public void GivenRunningLinux__WhenLinkingFileWithUnixStylePath__FileShouldExist Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath)); } - [TestMethod] + [PlatformSpecificTestMethod("Linux")] public void GivenRunningLinux__WhenLinkingFileWithWinStylePath__FileShouldExist() { - if (!TestUtility.IsLinux()) Assert.Inconclusive(); - var sut = new LinuxFileLinker(); sut.CreateLink(WinFilePath, WinLinkedFilePath); @@ -100,11 +88,11 @@ public void GivenRunningLinux__WhenLinkingFileWithWinStylePath__FileShouldExist( Assert.IsTrue(_fileSystem.File.Exists(UnixLinkedFilePath)); } - private string GetPlatformSourcePath() { + private static string GetPlatformSourcePath() { return TestUtility.IsWindows() ? WinFilePath : UnixFilePath; } - private string GetPlatformTargetPath() { + private static string GetPlatformTargetPath() { return TestUtility.IsWindows() ? WinLinkedFilePath : UnixLinkedFilePath; } } diff --git a/eawx-build-test/Services/IO/IOServiceTest.cs b/eawx-build-test/Services/IO/IOServiceTest.cs index 395855e..f7574f6 100644 --- a/eawx-build-test/Services/IO/IOServiceTest.cs +++ b/eawx-build-test/Services/IO/IOServiceTest.cs @@ -15,7 +15,7 @@ public void SetUp() { TestUtility.GetConfiguredMockFileSystem(out _fileSystem, out _assertions); } - [TestMethod] + [PlatformSpecificTestMethod("Windows")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("C:/data/test/path", ".dat", true)] [DataRow("C:/data/test/path", ".xml", false)] @@ -25,8 +25,6 @@ public void SetUp() { [DataRow("C:/data/path", ".dat", false)] public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__WIN(string absoluteDirectoryPath, string fileExtension, bool expected) { - if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows."); - const string fileName = "test"; var svc = new IOService(_fileSystem); Assert.AreEqual(expected, svc.IsValidPath( @@ -34,7 +32,7 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__WI string.Empty, fileExtension)); } - [TestMethod] + [PlatformSpecificTestMethod("Linux", "OSX")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("/mnt/c/data/test/path", ".dat", true)] [DataRow("/mnt/c/data/test/path", ".xml", false)] @@ -44,8 +42,6 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__WI [DataRow("/mnt/c/data/path", ".dat", false)] public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__UNX(string absoluteDirectoryPath, string fileExtension, bool expected) { - if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix."); - const string fileName = "test"; var svc = new IOService(_fileSystem); Assert.AreEqual(expected, svc.IsValidPath( @@ -53,7 +49,7 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__UN string.Empty, fileExtension)); } - [TestMethod] + [PlatformSpecificTestMethod("Windows")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("data/test/path", ".dat")] [DataRow("/test/path", ".xml")] @@ -63,8 +59,6 @@ public void GivenAbsolutePathToFile__WithRootedPath__IsValidPath__IsExpected__UN [DataRow("data/path", ".dat")] public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_WIN(string absoluteDirectoryPath, string fileExtension) { - if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows."); - const string fileName = "test"; var svc = new IOService(_fileSystem); Assert.IsFalse(svc.IsValidPath( @@ -72,7 +66,7 @@ public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_WIN string.Empty, fileExtension)); } - [TestMethod] + [PlatformSpecificTestMethod("Linux", "OSX")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("data/test/path", ".dat")] [DataRow("/test/path", ".xml")] @@ -83,7 +77,6 @@ public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_WIN public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_UNX(string absoluteDirectoryPath, string fileExtension) { var svc = new IOService(_fileSystem); - if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix."); const string fileName = "test"; Assert.IsFalse(svc.IsValidPath( @@ -91,7 +84,7 @@ public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_UNX string.Empty, fileExtension)); } - [TestMethod] + [PlatformSpecificTestMethod("Linux", "OSX")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("test/path", "/mnt/c/data", ".dat", true)] [DataRow("../../path", "/mnt/c/data/test/path", ".xml", true)] @@ -99,8 +92,6 @@ public void GivenRelativePathToFile__WithoutRootedPath__IsValidPath__IsFalse_UNX [DataRow("../path", "/mnt/c/data/test/path", ".xml", false)] public void GivenRelativePathToFile__IsValidPath__IsExpected_UNX(string relativeDirectoryPath, string basePath, string fileExtension, bool expected) { - if (!TestUtility.IsLinuxOrMacOS()) Assert.Inconclusive("OS not compatible, required OS is Unix."); - const string fileName = "test"; var svc = new IOService(_fileSystem); Assert.AreEqual(expected, svc.IsValidPath( @@ -108,7 +99,7 @@ public void GivenRelativePathToFile__IsValidPath__IsExpected_UNX(string relative basePath, fileExtension)); } - [TestMethod] + [PlatformSpecificTestMethod("Windows")] [TestCategory(TestUtility.TEST_TYPE_UTILITY)] [DataRow("test/path", "C:/data", ".dat", true)] [DataRow("../../path", "C:/data/test/path", ".xml", true)] @@ -116,8 +107,6 @@ public void GivenRelativePathToFile__IsValidPath__IsExpected_UNX(string relative [DataRow("../path", "C:/data/test/path", ".xml", false)] public void GivenRelativePathToFile__IsValidPath__IsExpected_WIN(string relativeDirectoryPath, string basePath, string fileExtension, bool expected) { - if (!TestUtility.IsWindows()) Assert.Inconclusive("OS not compatible, required OS is Windows."); - const string fileName = "test"; var svc = new IOService(_fileSystem); Assert.AreEqual(expected, svc.IsValidPath( diff --git a/eawx-build-test/Services/Process/ProcessRunnerTest.cs b/eawx-build-test/Services/Process/ProcessRunnerTest.cs index 3e1ef89..763d7e0 100644 --- a/eawx-build-test/Services/Process/ProcessRunnerTest.cs +++ b/eawx-build-test/Services/Process/ProcessRunnerTest.cs @@ -8,7 +8,8 @@ namespace EawXBuildTest.Services.Process { [TestClass] public class ProcessRunnerTest { - [TestMethod] + + [PlatformSpecificTestMethod("Linux", "OSX")] public void GivenEcho__WhenStarting__ShouldExitWithCodeZero() { var sut = new ProcessRunner(); @@ -19,7 +20,7 @@ public void GivenEcho__WhenStarting__ShouldExitWithCodeZero() { Assert.AreEqual(0, actual); } - [TestMethod] + [PlatformSpecificTestMethod("Linux", "OSX")] public void GivenEchoWithArgs__WhenStarting__ShouldPrintOutArgs() { var stringBuilder = new StringBuilder(); Console.SetOut(new StringWriter(stringBuilder)); @@ -34,7 +35,7 @@ public void GivenEchoWithArgs__WhenStarting__ShouldPrintOutArgs() { Assert.AreEqual(expected, actual); } - [TestMethod] + [PlatformSpecificTestMethod("Linux", "OSX")] public void GivenProcessStartInfoForEcho__WhenStarting__ShouldPrintOutArgs() { var stringBuilder = new StringBuilder(); Console.SetOut(new StringWriter(stringBuilder)); @@ -53,5 +54,51 @@ public void GivenProcessStartInfoForEcho__WhenStarting__ShouldPrintOutArgs() { var actual = stringBuilder.ToString().Trim(); Assert.AreEqual(expected, actual); } + + [PlatformSpecificTestMethod("Windows")] + public void GivenCmdNoCommand__WhenStarting__ShouldExitWithCodeZero() { + var sut = new ProcessRunner(); + + sut.Start("cmd.exe", "/c"); + sut.WaitForExit(); + + var actual = sut.ExitCode; + Assert.AreEqual(0, actual); + } + + [PlatformSpecificTestMethod("Windows")] + public void GivenCmdWithEchoCommandAndArgs__WhenStarting__ShouldPrintOutArgs() { + var stringBuilder = new StringBuilder(); + Console.SetOut(new StringWriter(stringBuilder)); + + var sut = new ProcessRunner(); + + const string expected = "Hello World"; + sut.Start("cmd.exe", "/c echo " + expected); + sut.WaitForExit(); + + var actual = stringBuilder.ToString().Trim(); + Assert.AreEqual(expected, actual); + } + + [PlatformSpecificTestMethod("Windows")] + public void GivenProcessStartInfoForCmdWithEcho__WhenStarting__ShouldPrintOutArgs() { + var stringBuilder = new StringBuilder(); + Console.SetOut(new StringWriter(stringBuilder)); + + var sut = new ProcessRunner(); + + const string expected = "Hello World"; + var startInfo = new ProcessStartInfo { + FileName = "cmd.exe", + Arguments = "/c echo " + expected + }; + + sut.Start(startInfo); + sut.WaitForExit(); + + var actual = stringBuilder.ToString().Trim(); + Assert.AreEqual(expected, actual); + } } } \ No newline at end of file diff --git a/eawx-build-test/Steam/Facepunch.Adapters/FacepunchSteamWorkshopAdapterTest.cs b/eawx-build-test/Steam/Facepunch.Adapters/FacepunchSteamWorkshopAdapterTest.cs index f91cd5c..2f02712 100644 --- a/eawx-build-test/Steam/Facepunch.Adapters/FacepunchSteamWorkshopAdapterTest.cs +++ b/eawx-build-test/Steam/Facepunch.Adapters/FacepunchSteamWorkshopAdapterTest.cs @@ -55,10 +55,8 @@ public void TearDown() { _itemFolder.Delete(true); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] public async Task GivenWorkshopChangeSet__WhenPublishingToSteam__ItemShouldBeOnWorkshop() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - var changeSet = new WorkshopItemChangeSet(_fileSystem) { Title = Title, DescriptionFilePath = DescriptionFilePath, @@ -75,10 +73,8 @@ public async Task GivenWorkshopChangeSet__WhenPublishingToSteam__ItemShouldBeOnW await AssertItemMatchesSettings(publishTaskResult); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] public async Task WhenQueryingForItemId__ShouldReturnItemWithId() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - _sut.Init(32470); const ulong fotrWorkshopId = 1976399102; var workshopItem = await _sut.QueryWorkshopItemByIdAsync(fotrWorkshopId); diff --git a/eawx-build-test/Steam/Facepunch.Adapters/FacepunchWorkshopItemAdapterTest.cs b/eawx-build-test/Steam/Facepunch.Adapters/FacepunchWorkshopItemAdapterTest.cs index 672d087..3b02565 100644 --- a/eawx-build-test/Steam/Facepunch.Adapters/FacepunchWorkshopItemAdapterTest.cs +++ b/eawx-build-test/Steam/Facepunch.Adapters/FacepunchWorkshopItemAdapterTest.cs @@ -86,10 +86,8 @@ public void TearDown() { } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] public async Task GivenWorkshopItem__WhenUpdatingSuccessfully__ShouldReturnOk() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - var item = await Item.GetAsync(_itemId); Assert.IsNotNull(item); @@ -100,11 +98,9 @@ public async Task GivenWorkshopItem__WhenUpdatingSuccessfully__ShouldReturnOk() Assert.AreEqual(PublishResult.Ok, actual); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] [Ignore] public async Task GivenWorkshopItemWithChangedTitle__WhenUpdating__TitleShouldHaveChanged() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - var item = await Item.GetAsync(_itemId); Assert.IsNotNull(item); @@ -116,11 +112,9 @@ public async Task GivenWorkshopItemWithChangedTitle__WhenUpdating__TitleShouldHa Assert.AreEqual(Title, item.Value.Title); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] [Ignore] public async Task GivenWorkshopItemWithChangedDescription__WhenUpdating__DescriptionShouldHaveChanged() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - var item = await Item.GetAsync(_itemId); Assert.IsNotNull(item); @@ -134,11 +128,9 @@ public async Task GivenWorkshopItemWithChangedDescription__WhenUpdating__Descrip Assert.AreEqual(Description, item.Value.Description); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] [Ignore] public async Task GivenWorkshopItemWithChangedVisibility__WhenUpdating__VisibilityShouldHaveChanged() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); - var item = await Item.GetAsync(_itemId); Assert.IsNotNull(item); @@ -152,9 +144,8 @@ public async Task GivenWorkshopItemWithChangedVisibility__WhenUpdating__Visibili Assert.IsTrue(item.Value.IsPublic); } - [TestMethod] + [TestMethodWithRequiredEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT", "YES")] public async Task GivenWorkshopItemWithChangedItemFolderPath__WhenUpdating__ShouldHaveChangedFiles() { - if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") Assert.Inconclusive(); var item = GetItem(_itemId); var sut = new FacepunchWorkshopItemAdapter(item); diff --git a/eawx-build-test/TestAttributes.cs b/eawx-build-test/TestAttributes.cs new file mode 100644 index 0000000..7935a59 --- /dev/null +++ b/eawx-build-test/TestAttributes.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EawXBuildTest { + public class PlatformSpecificTestMethod : TestMethodAttribute { + public PlatformSpecificTestMethod(params string[] platforms) { + Platforms = platforms.Select(platformName => OSPlatform.Create(platformName.ToUpper())); + } + + public override TestResult[] Execute(ITestMethod testMethod) { + var platformMatches = Platforms.Any(RuntimeInformation.IsOSPlatform); + return !platformMatches + ? new[] {new TestResult {Outcome = UnitTestOutcome.Inconclusive}} + : base.Execute(testMethod); + } + + public IEnumerable Platforms { get; } + } + + public class TestMethodWithRequiredEnvironmentVariable : TestMethodAttribute { + private readonly string _variableName; + private readonly string _requiredValue; + + public TestMethodWithRequiredEnvironmentVariable(string variableName, string requiredValue) { + _variableName = variableName; + _requiredValue = requiredValue; + } + + public override TestResult[] Execute(ITestMethod testMethod) { + var variable = System.Environment.GetEnvironmentVariable(_variableName); + + return variable == null || !variable.Equals(_requiredValue) + ? new[] {new TestResult {Outcome = UnitTestOutcome.Inconclusive}} + : base.Execute(testMethod); + } + } +} \ No newline at end of file