From 6aba2d8f096e1e577ad2ad2921fb0b1b241ba503 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev <3026792+tolik518@users.noreply.github.com> Date: Sat, 21 Oct 2023 12:23:51 +0200 Subject: [PATCH] Fixing test-workflow (#21) * renamed DataReaderTest * renamed workflow * adjusted tests.yml * adjusted the test runner for .net framework --- .github/workflows/tests.yml | 40 ++++++++++--------- .../{ReaderTests.cs => DataReaderTests.cs} | 14 +++++-- SoG_SGreader.Test/SoG_SGreader.Test.csproj | 2 +- SoG_SGreader.Test/packages.config | 1 + 4 files changed, 33 insertions(+), 24 deletions(-) rename SoG_SGreader.Test/{ReaderTests.cs => DataReaderTests.cs} (92%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4f54517..be4c936 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,26 +1,28 @@ -name: dotnet package +name: Tests on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest + steps: - uses: actions/checkout@v4 - - name: Setup dotnet 4.5.2 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: "4.5.2" - - name: Display dotnet version - run: dotnet --version - - name: Install dependencies - run: dotnet restore - - name: Test with dotnet - run: dotnet test --logger trx --results-directory "TestResults" - - name: Upload dotnet test results - uses: actions/upload-artifact@v3 - with: - name: dotnet-results-4.5.2 - path: TestResults - # Use always() to always run this step to publish test results when there are test failures - if: ${{ always() }} \ No newline at end of file + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v1.3.1 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v1.2.0 + + - name: Restore NuGet packages + run: nuget restore SoG_SGreader.sln + + - name: Build with MSBuild + run: msbuild /p:Configuration=Release /m /p:BuildInParallel=true /p:BuildIncrementally=true SoG_SGreader.sln + + - name: Setup VSTest Console + uses: darenm/Setup-VSTest@v1.2 + + - name: Test + run: vstest.console.exe /TestAdapterPath:"packages" SoG_SGreader.Test\bin\Release\SoG_SGreader.Test.dll \ No newline at end of file diff --git a/SoG_SGreader.Test/ReaderTests.cs b/SoG_SGreader.Test/DataReaderTests.cs similarity index 92% rename from SoG_SGreader.Test/ReaderTests.cs rename to SoG_SGreader.Test/DataReaderTests.cs index 79aaa69..5360ab4 100644 --- a/SoG_SGreader.Test/ReaderTests.cs +++ b/SoG_SGreader.Test/DataReaderTests.cs @@ -7,7 +7,7 @@ namespace SoG_SGreader.Test { - public class ReaderTests + public class DataReaderTests { private static List players = new List(); @@ -15,9 +15,15 @@ private static Player GetSaveGame(int saveGameNumber) { DataReader dataReader = new DataReader(); var txtConsoleMock = new Mock().Object; - - string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName; - string filePath = Path.Combine(projectDirectory, "SaveGames", saveGameNumber + ".cha"); + + string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName; + + // Exception for GitHub Actions Test Runner + if (Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") != null) { + projectDirectory = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"); + } + + string filePath = Path.Combine(projectDirectory, "SoG_SGreader.Test", "SaveGames", saveGameNumber + ".cha"); return dataReader.ReadFromFile(filePath, txtConsoleMock); } diff --git a/SoG_SGreader.Test/SoG_SGreader.Test.csproj b/SoG_SGreader.Test/SoG_SGreader.Test.csproj index d5ae9b8..1f6e08f 100644 --- a/SoG_SGreader.Test/SoG_SGreader.Test.csproj +++ b/SoG_SGreader.Test/SoG_SGreader.Test.csproj @@ -66,7 +66,7 @@ - + diff --git a/SoG_SGreader.Test/packages.config b/SoG_SGreader.Test/packages.config index dfa77f5..d0f3e36 100644 --- a/SoG_SGreader.Test/packages.config +++ b/SoG_SGreader.Test/packages.config @@ -10,4 +10,5 @@ + \ No newline at end of file