From 4bfa9608610f19f01483a87a66e93384bca59707 Mon Sep 17 00:00:00 2001 From: Jorixon <143650598+Jorixon@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:21:17 +0200 Subject: [PATCH] ci: Simple characters.json tests and automatic builds --- .github/workflows/dotnet-desktop.yml | 20 ++++++++----- src/GIMI-ModManager.sln | 23 +++++++++++++++ src/JASM.Tests/CharactersJsonTests.cs | 42 +++++++++++++++++++++++++++ src/JASM.Tests/GlobalUsings.cs | 1 + src/JASM.Tests/JASM.Tests.csproj | 29 ++++++++++++++++++ 5 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 src/JASM.Tests/CharactersJsonTests.cs create mode 100644 src/JASM.Tests/GlobalUsings.cs create mode 100644 src/JASM.Tests/JASM.Tests.csproj diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml index 6c281a7a..1a637010 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/dotnet-desktop.yml @@ -6,10 +6,18 @@ name: WinUI 3 unpackaged app on: workflow_dispatch: -jobs: + pull_request: + branches: [ main ] + paths: + - 'src/**' + push: + branches: [ main ] + paths: + - 'src/**' + - 'CHANGELOG.md' +jobs: build: - strategy: matrix: configuration: [Release] @@ -18,9 +26,6 @@ jobs: 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: - Solution_Name: GIMI-ModManager # Replace with your solution name, i.e. App1 - steps: - name: Checkout uses: actions/checkout@v4 @@ -33,9 +38,8 @@ jobs: with: dotnet-version: 7.0.x - # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild - - name: Setup MSBuild.exe - uses: microsoft/setup-msbuild@v1.1 + - name: Test + run: dotnet test ${{ github.workspace }}\src - name: Build, publish and zip the app run: python ${{ github.workspace }}\Build\Release.py diff --git a/src/GIMI-ModManager.sln b/src/GIMI-ModManager.sln index 89924bfb..5b8242e9 100644 --- a/src/GIMI-ModManager.sln +++ b/src/GIMI-ModManager.sln @@ -9,6 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GIMI-ModManager.Core", "GIM EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elevator", "Elevator\Elevator.csproj", "{3C239075-C121-4DDB-88C5-B181863797B7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JASM.Tests", "JASM.Tests\JASM.Tests.csproj", "{992DF5F9-CBB9-4483-A71D-C0083C173B1C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4E3DE2B1-EF6D-4E01-BCAB-3505C3B9E365}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,10 +75,29 @@ Global {3C239075-C121-4DDB-88C5-B181863797B7}.Release|x64.ActiveCfg = Release|x64 {3C239075-C121-4DDB-88C5-B181863797B7}.Release|x64.Build.0 = Release|x64 {3C239075-C121-4DDB-88C5-B181863797B7}.Release|x86.ActiveCfg = Release|x64 + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|arm64.ActiveCfg = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|arm64.Build.0 = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|x64.ActiveCfg = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|x64.Build.0 = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|x86.ActiveCfg = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Debug|x86.Build.0 = Debug|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|Any CPU.Build.0 = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|arm64.ActiveCfg = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|arm64.Build.0 = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|x64.ActiveCfg = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|x64.Build.0 = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|x86.ActiveCfg = Release|Any CPU + {992DF5F9-CBB9-4483-A71D-C0083C173B1C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {992DF5F9-CBB9-4483-A71D-C0083C173B1C} = {4E3DE2B1-EF6D-4E01-BCAB-3505C3B9E365} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E01F4EA5-3B64-4C68-9474-CB87A51AF7D9} EndGlobalSection diff --git a/src/JASM.Tests/CharactersJsonTests.cs b/src/JASM.Tests/CharactersJsonTests.cs new file mode 100644 index 00000000..62ab69e9 --- /dev/null +++ b/src/JASM.Tests/CharactersJsonTests.cs @@ -0,0 +1,42 @@ +using GIMI_ModManager.Core.Services; + +namespace JASM.Tests +{ + public class CharactersJsonTests + { + private readonly string AssetsUriPath = Path.GetFullPath("..\\..\\..\\..\\GIMI-ModManager.WinUI\\Assets"); + + private async Task InitGenshinService() + { + if (!File.Exists(AssetsUriPath + "\\characters.json")) + throw new FileNotFoundException("Assets file not found.", AssetsUriPath); + var genshinService = new GenshinService(); + await genshinService.InitializeAsync(AssetsUriPath); + return genshinService; + } + + [Fact] + public async void CheckFor_DuplicateCharacterIds() + { + var genshinService = await InitGenshinService(); + var characters = genshinService.GetCharacters(); + + var duplicateIds = characters.GroupBy(character => character.Id).Where(g => g.Count() > 1); + + Assert.Empty(duplicateIds); + } + + + [Fact] + public async void CheckFor_DuplicateNames() + { + var genshinService = await InitGenshinService(); + var characters = genshinService.GetCharacters(); + + var duplicateNames = characters.GroupBy(character => character.DisplayName.ToLower()) + .Where(g => g.Count() > 1); + + Assert.Empty(duplicateNames); + } + } +} \ No newline at end of file diff --git a/src/JASM.Tests/GlobalUsings.cs b/src/JASM.Tests/GlobalUsings.cs new file mode 100644 index 00000000..8c927eb7 --- /dev/null +++ b/src/JASM.Tests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/src/JASM.Tests/JASM.Tests.csproj b/src/JASM.Tests/JASM.Tests.csproj new file mode 100644 index 00000000..cea4f4f7 --- /dev/null +++ b/src/JASM.Tests/JASM.Tests.csproj @@ -0,0 +1,29 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + +