From bdf70032db158ad4712f69e7a47337ba0e082c71 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 17 Dec 2024 19:45:40 +0100 Subject: [PATCH 01/51] Create sonarcloud.yml workflow --- .github/workflows/sonarcloud.yml | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/sonarcloud.yml diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..e0eaeb6 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,50 @@ +name: SonarQube Analysis + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + sonarcloud: + name: Analyze with SonarQube + runs-on: ubuntu-latest + + steps: + # 1. Checkout del repositorio + - name: Checkout Repository + uses: actions/checkout@v4 + + # 2. Setup de Node.js + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + # 3. Instalación de dependencias + - name: Install Dependencies + run: | + npm install + + # 4. Ejecutar pruebas unitarias + - name: Run Tests + run: | + npm test -- --coverage + + # 5. Configuración de SonarCloud + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@v2.0.2 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + projectBaseDir: . + args: > + -Dsonar.projectKey=autoguru-au_kv-push + -Dsonar.organization=your-organization-key + -Dsonar.sources=src + -Dsonar.tests=tests + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info From 7988eae04518e733a703131f9d50848d11592693 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 15:19:59 +0100 Subject: [PATCH 02/51] Update sonarcloud.yml --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e0eaeb6..de5d19e 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -44,7 +44,7 @@ jobs: projectBaseDir: . args: > -Dsonar.projectKey=autoguru-au_kv-push - -Dsonar.organization=your-organization-key + -Dsonar.organization=autoguru-au -Dsonar.sources=src -Dsonar.tests=tests -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info From e2d43f58209c4b18a3652b77f3006760534b0396 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 15:36:49 +0100 Subject: [PATCH 03/51] Update sonarcloud.yml --- .github/workflows/sonarcloud.yml | 56 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index de5d19e..76ebaa5 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,4 +1,4 @@ -name: SonarQube Analysis +name: SonarQube Analysis (C#) on: push: @@ -10,41 +10,43 @@ on: jobs: sonarcloud: - name: Analyze with SonarQube + name: Analyze with SonarCloud runs-on: ubuntu-latest steps: # 1. Checkout del repositorio - - name: Checkout Repository + - name: Checkout repository uses: actions/checkout@v4 - # 2. Setup de Node.js - - name: Setup Node.js - uses: actions/setup-node@v4 + # 2. Configuración del SDK de .NET + - name: Setup .NET + uses: actions/setup-dotnet@v3 with: - node-version: '20' + dotnet-version: '6.0' - # 3. Instalación de dependencias - - name: Install Dependencies - run: | - npm install + # 3. Restaurar dependencias + - name: Restore dependencies + run: dotnet restore - # 4. Ejecutar pruebas unitarias - - name: Run Tests - run: | - npm test -- --coverage + # 4. Compilar el proyecto + - name: Build project + run: dotnet build --no-restore - # 5. Configuración de SonarCloud - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@v2.0.2 + # 5. Ejecutar análisis de SonarCloud + - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - projectBaseDir: . - args: > - -Dsonar.projectKey=autoguru-au_kv-push - -Dsonar.organization=autoguru-au - -Dsonar.sources=src - -Dsonar.tests=tests - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + run: | + dotnet sonarscanner begin \ + /k:"autoguru-au_kv-push" \ + /o:"your-organization-key" \ + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ + /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + dotnet build + dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + + # 6. Opcional: Ejecutar pruebas y generar cobertura + - name: Run tests + run: | + dotnet test --collect:"XPlat Code Coverage" \ + --results-directory ./TestResults From 8148a0fa1b2c77f96831872fdc94b53bcf31d045 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 15:38:35 +0100 Subject: [PATCH 04/51] Update sonarcloud.yml --- .github/workflows/sonarcloud.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 76ebaa5..95ae35e 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -24,14 +24,14 @@ jobs: with: dotnet-version: '6.0' - # 3. Restaurar dependencias + # 3. Instalar SonarScanner para .NET + - name: Install SonarScanner for .NET + run: dotnet tool install --global dotnet-sonarscanner + + # 4. Restaurar dependencias - name: Restore dependencies run: dotnet restore - # 4. Compilar el proyecto - - name: Build project - run: dotnet build --no-restore - # 5. Ejecutar análisis de SonarCloud - name: Run SonarCloud analysis env: From 8b752819e66855758cbbc75d165e8a816744cf0e Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 15:55:38 +0100 Subject: [PATCH 05/51] testing --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 95ae35e..135d1c1 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -39,7 +39,7 @@ jobs: run: | dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ - /o:"your-organization-key" \ + /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" dotnet build From b25e620536729bdc94c98cc1e98b25c6de472dae Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:06:36 +0100 Subject: [PATCH 06/51] fixed key --- .github/workflows/sonarcloud.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 135d1c1..fd65fed 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,25 +14,25 @@ jobs: runs-on: ubuntu-latest steps: - # 1. Checkout del repositorio + # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v4 - # 2. Configuración del SDK de .NET + # Step 2: Set up the .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '6.0' - # 3. Instalar SonarScanner para .NET + # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - # 4. Restaurar dependencias + # Step 4: Restore project dependencies - name: Restore dependencies run: dotnet restore - # 5. Ejecutar análisis de SonarCloud + # Step 5: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -45,7 +45,7 @@ jobs: dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - # 6. Opcional: Ejecutar pruebas y generar cobertura + # Step 6: Optionally run tests and generate code coverage - name: Run tests run: | dotnet test --collect:"XPlat Code Coverage" \ From 6b2c30639869319738716c943680c1273af9585e Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:26:09 +0100 Subject: [PATCH 07/51] added features to scan --- .github/workflows/sonarcloud.yml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index fd65fed..b2898e8 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -32,21 +32,29 @@ jobs: - name: Restore dependencies run: dotnet restore - # Step 5: Run SonarCloud analysis + # Step 5: Run tests with coverage + - name: Run tests with coverage + run: | + dotnet test --collect:"XPlat Code Coverage" \ + --results-directory ./TestResults + + # Step 6: Convert coverage to OpenCover + - name: Convert coverage to OpenCover + run: | + reportgenerator \ + -reports:./TestResults/**/*.xml \ + -targetdir:./CoverageResults \ + -reporttypes:opencover + + # Step 7: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ - /o:"autoguru-au" \ + /o:"your-organization-key" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - - # Step 6: Optionally run tests and generate code coverage - - name: Run tests - run: | - dotnet test --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults From 64661446d6e9cd9a59e6e7d3f07c71094f8f38f7 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:28:31 +0100 Subject: [PATCH 08/51] test --- .github/workflows/sonarcloud.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index b2898e8..f487323 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -28,17 +28,21 @@ jobs: - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - # Step 4: Restore project dependencies + # Step 4: Install ReportGenerator + - name: Install ReportGenerator + run: dotnet tool install --global dotnet-reportgenerator-globaltool + + # Step 5: Restore project dependencies - name: Restore dependencies run: dotnet restore - # Step 5: Run tests with coverage + # Step 6: Run tests with coverage - name: Run tests with coverage run: | dotnet test --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Step 6: Convert coverage to OpenCover + # Step 7: Convert coverage to OpenCover - name: Convert coverage to OpenCover run: | reportgenerator \ @@ -46,7 +50,7 @@ jobs: -targetdir:./CoverageResults \ -reporttypes:opencover - # Step 7: Run SonarCloud analysis + # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 1ea80a1dd4af98d1724f9a37c07ed71e0dbbf9c0 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:29:11 +0100 Subject: [PATCH 09/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index f487323..a41ddee 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -57,7 +57,7 @@ jobs: run: | dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ - /o:"your-organization-key" \ + /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" dotnet build From 53ed24b5817dae9336888ef745ce9456997e4a24 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:32:19 +0100 Subject: [PATCH 10/51] test --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a41ddee..3f487fb 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -46,7 +46,7 @@ jobs: - name: Convert coverage to OpenCover run: | reportgenerator \ - -reports:./TestResults/**/*.xml \ + -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./CoverageResults \ -reporttypes:opencover @@ -57,7 +57,7 @@ jobs: run: | dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ - /o:"autoguru-au" \ + /o:"your-organization-key" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" dotnet build From 626d5619fcfaf7a3bdd70c554d1aa104ef874266 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:33:56 +0100 Subject: [PATCH 11/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3f487fb..a00dd6e 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -57,7 +57,7 @@ jobs: run: | dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ - /o:"your-organization-key" \ + /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" dotnet build From 65e635c4e34bdfde8a07f094314db013b588ca83 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:37:17 +0100 Subject: [PATCH 12/51] test --- .github/workflows/sonarcloud.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a00dd6e..f843ed0 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -39,8 +39,10 @@ jobs: # Step 6: Run tests with coverage - name: Run tests with coverage run: | - dotnet test --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults + dotnet test \ + --collect:"XPlat Code Coverage" \ + -r ./TestResults \ + --settings ./PathToRunSettings/coverlet.runsettings # Step 7: Convert coverage to OpenCover - name: Convert coverage to OpenCover From a6758cb8dcf97f05155ddea0d12ea44e309dfdc4 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 16:39:01 +0100 Subject: [PATCH 13/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index f843ed0..f10137c 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -41,7 +41,7 @@ jobs: run: | dotnet test \ --collect:"XPlat Code Coverage" \ - -r ./TestResults \ + --results-directory ./TestResults \ --settings ./PathToRunSettings/coverlet.runsettings # Step 7: Convert coverage to OpenCover From d3eb216c174fd55c0ea676e789a6444afb60560e Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 19:26:42 +0100 Subject: [PATCH 14/51] test --- .github/workflows/sonarcloud.yml | 22 +++++++------- AutoGuru.KeyValuePush.sln | 11 +++++++ coverlet.runsettings | 13 ++++++++ src/KeyValuePush.Tests/BasicTests.cs | 13 ++++++++ .../KeyValuePush.Tests.csproj | 30 +++++++++++++++++++ 5 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 coverlet.runsettings create mode 100644 src/KeyValuePush.Tests/BasicTests.cs create mode 100644 src/KeyValuePush.Tests/KeyValuePush.Tests.csproj diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index f10137c..ed4de4b 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -18,11 +18,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Step 2: Set up the .NET SDK + # Step 2: Setup .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0' + dotnet-version: '8.0.x' # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET @@ -32,25 +32,25 @@ jobs: - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool - # Step 5: Restore project dependencies + # Step 5: Restore dependencies - name: Restore dependencies run: dotnet restore - # Step 6: Run tests with coverage + # Step 6: Run tests and collect coverage - name: Run tests with coverage run: | - dotnet test \ + dotnet test src/KeyValuePush.Tests/KeyValuePush.Tests.csproj \ --collect:"XPlat Code Coverage" \ --results-directory ./TestResults \ - --settings ./PathToRunSettings/coverlet.runsettings + --settings ./coverlet.runsettings - # Step 7: Convert coverage to OpenCover - - name: Convert coverage to OpenCover + # Step 7: Convert coverage to OpenCover format + - name: Generate coverage report run: | reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./CoverageResults \ - -reporttypes:opencover + -reports:./TestResults/**/coverage.cobertura.xml \ + -targetdir:./CoverageResults \ + -reporttypes:opencover # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis diff --git a/AutoGuru.KeyValuePush.sln b/AutoGuru.KeyValuePush.sln index f8c01ad..1c3f2b8 100644 --- a/AutoGuru.KeyValuePush.sln +++ b/AutoGuru.KeyValuePush.sln @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Repo Items", ".Repo Items" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGuru.KeyValuePush.Redis", "src\KeyValuePush.Redis\AutoGuru.KeyValuePush.Redis.csproj", "{379E9996-CE05-44CD-B255-5C88B1CE1BED}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6598E4B4-D7D3-4633-9E2F-5C470917258D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyValuePush.Tests", "src\KeyValuePush.Tests\KeyValuePush.Tests.csproj", "{14E2DBAE-46BF-4109-8F87-5894B0C7E07E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +33,10 @@ Global {379E9996-CE05-44CD-B255-5C88B1CE1BED}.Debug|Any CPU.Build.0 = Debug|Any CPU {379E9996-CE05-44CD-B255-5C88B1CE1BED}.Release|Any CPU.ActiveCfg = Release|Any CPU {379E9996-CE05-44CD-B255-5C88B1CE1BED}.Release|Any CPU.Build.0 = Release|Any CPU + {14E2DBAE-46BF-4109-8F87-5894B0C7E07E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14E2DBAE-46BF-4109-8F87-5894B0C7E07E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14E2DBAE-46BF-4109-8F87-5894B0C7E07E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14E2DBAE-46BF-4109-8F87-5894B0C7E07E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -36,4 +44,7 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EE37C22E-E3CE-4E6B-8004-BB25FE05CB98} EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {14E2DBAE-46BF-4109-8F87-5894B0C7E07E} = {6598E4B4-D7D3-4633-9E2F-5C470917258D} + EndGlobalSection EndGlobal diff --git a/coverlet.runsettings b/coverlet.runsettings new file mode 100644 index 0000000..b9c0cc4 --- /dev/null +++ b/coverlet.runsettings @@ -0,0 +1,13 @@ + + + + + + + Cobertura + ./TestResults/ + + + + + diff --git a/src/KeyValuePush.Tests/BasicTests.cs b/src/KeyValuePush.Tests/BasicTests.cs new file mode 100644 index 0000000..e1a8fe4 --- /dev/null +++ b/src/KeyValuePush.Tests/BasicTests.cs @@ -0,0 +1,13 @@ +using Xunit; + +namespace KeyValuePush.Tests +{ + public class BasicTests + { + [Fact] + public void ExampleTest() + { + Assert.True(1 + 1 == 2); + } + } +} diff --git a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj new file mode 100644 index 0000000..ee047fd --- /dev/null +++ b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + false + true + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + + From 25365a184e2b25b1197ac1239eb636a803ac0f42 Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 18 Dec 2024 19:54:29 +0100 Subject: [PATCH 15/51] test --- .github/workflows/sonarcloud.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index ed4de4b..2d02a7d 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -36,13 +36,12 @@ jobs: - name: Restore dependencies run: dotnet restore - # Step 6: Run tests and collect coverage + # Step 6: Run tests with coverage - name: Run tests with coverage run: | - dotnet test src/KeyValuePush.Tests/KeyValuePush.Tests.csproj \ + dotnet test \ --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults \ - --settings ./coverlet.runsettings + --results-directory ./TestResults # Step 7: Convert coverage to OpenCover format - name: Generate coverage report @@ -64,3 +63,4 @@ jobs: /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + From e6bc8f7a6b4c1697d44e23798f6bf307b7a6783d Mon Sep 17 00:00:00 2001 From: vanguile Date: Tue, 24 Dec 2024 17:16:55 +0100 Subject: [PATCH 16/51] tests and coverage ok without coverage tests --- Directory.Build.props | 6 +---- .../KeyValuePush.Tests.csproj | 27 ++++--------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5b4b981..3567382 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,6 @@ - - net6.0;net7.0;net8.0 + net7.0 false Ben McCallum, AutoGuru kv-push @@ -12,11 +11,8 @@ https://github.com/autoguru-au/kv-push https://github.com/autoguru-au/kv-push git - false true true - true enable - diff --git a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj index ee047fd..bcfeadb 100644 --- a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj +++ b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj @@ -1,30 +1,13 @@ - - net8.0 - enable - enable - + net7.0 false - true - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - + + + + - - - - - - - - - From 2220c4fdde29bab157f7dfe8334d78c466ab4951 Mon Sep 17 00:00:00 2001 From: vanguile Date: Thu, 26 Dec 2024 13:39:14 +0100 Subject: [PATCH 17/51] Fixed dictionary tests --- .../DefaultDictionaryBuilderTests.cs | 168 ++++++++++++++++++ .../KeyValuePush.Tests.csproj | 5 + src/KeyValuePush/DefaultDictionaryBuilder.cs | 2 +- 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs diff --git a/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs new file mode 100644 index 0000000..ae9a221 --- /dev/null +++ b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace AutoGuru.KeyValuePush.Tests +{ + public class DefaultDictionaryBuilderTests + { + private readonly DefaultDictionaryBuilder _builder; + + public DefaultDictionaryBuilderTests() + { + _builder = new DefaultDictionaryBuilder(); + } + + [Fact] + public void TryAdd_ShouldAddKeyValuePair_WhenKeyDoesNotExist() + { + var dict = new Dictionary(); + var key = "key1"; + var value = "value1"; + + DefaultDictionaryBuilder.TryAdd(dict, key, value); + + Assert.Single(dict); + Assert.Equal(value, dict[key]); + } + + [Fact] + public void TryAdd_ShouldNotThrow_WhenKeyExistsWithSameValue() + { + var dict = new Dictionary { { "key1", "value1" } }; + var key = "key1"; + var value = "value1"; + + DefaultDictionaryBuilder.TryAdd(dict, key, value); + + Assert.Single(dict); + Assert.Equal(value, dict[key]); + } + + [Fact] + public void TryAdd_ShouldThrowException_WhenKeyExistsWithDifferentValue() + { + var dict = new Dictionary { { "key1", "value1" } }; + var key = "key1"; + var value = "differentValue"; + + var exception = Assert.Throws(() => DefaultDictionaryBuilder.TryAdd(dict, key, value)); + Assert.Equal("Duplicate key of 'key1' with a different value detected.", exception.Message); + } + + [Fact] + public async Task BuildAsync_ShouldReturnDictionary_WhenFilesAreValid() + { + var path = "TestFiles"; + Directory.CreateDirectory(path); + File.WriteAllText(Path.Combine(path, "file1.txt"), "Content1"); + File.WriteAllText(Path.Combine(path, "file2.txt"), "Content2"); + + var result = await _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + + Assert.Equal(2, result.Count); + Assert.Equal("Content1", result["file1"]); + Assert.Equal("Content2", result["file2"]); + + Directory.Delete(path, true); + } + + [Fact] + public async Task BuildAsync_ShouldThrowJsonException_WhenJsonFileIsInvalid() + { + var path = "TestFiles"; + Directory.CreateDirectory(path); + File.WriteAllText(Path.Combine(path, "file1.json"), "Invalid JSON Content"); + + var exception = await Assert.ThrowsAsync(() => _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, true, CancellationToken.None)); + + Assert.Contains("is an invalid start of a value", exception.Message); + Directory.Delete(path, true); + } + + [Fact] + public async Task BuildAsync_ShouldHandleEmptyDirectory() + { + var path = "EmptyDirectory"; + Directory.CreateDirectory(path); + + var result = await _builder.BuildAsync(path, "*.*", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + + Assert.Empty(result); + Directory.Delete(path, true); + } + + [Fact] + public async Task BuildAsync_ShouldReturnEmptyDictionary_WhenNoMatchingFilesFound() + { + var path = "TestFiles"; + Directory.CreateDirectory(path); + + var result = await _builder.BuildAsync(path, "*.xml", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + + Assert.Empty(result); + Directory.Delete(path, true); + } + + [Fact] + public async Task BuildAsync_ShouldSkipJsonFiles_WhenRecurseIntoJsonFilesIsFalse() + { + var path = "TestFiles"; + Directory.CreateDirectory(path); + var jsonContent = JsonSerializer.Serialize(new Dictionary + { + { "Key1", "Value1" }, + { "Key2", "Value2" } + }); + File.WriteAllText(Path.Combine(path, "file1.json"), jsonContent); + + var result = await _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + + Assert.Single(result); + Assert.Equal(jsonContent, result["file1"]); + + Directory.Delete(path, true); + } + + [Fact] + public async Task BuildAsync_ShouldProcessNestedDirectories_WhenSearchOptionIsAllDirectories() + { + var path = "NestedTestFiles"; + var nestedPath = Path.Combine(path, "SubDirectory"); + Directory.CreateDirectory(nestedPath); + File.WriteAllText(Path.Combine(nestedPath, "file1.txt"), "Content1"); + + var result = await _builder.BuildAsync(path, "*.txt", SearchOption.AllDirectories, false, CancellationToken.None); + + Assert.Single(result); + Assert.Equal("Content1", result["file1"]); + + Directory.Delete(path, true); + } + + [Fact] +public async Task BuildAsync_ShouldIgnoreUnsupportedExtensions() +{ + // Arrange + var path = "TestFiles"; + Directory.CreateDirectory(path); + File.WriteAllText(Path.Combine(path, "file1.unsupported"), "Unsupported Content"); + + // Act + var result = await _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + + // Assert + Assert.Empty(result); + + // Clean up + Directory.Delete(path, true); +} + + } + + +} diff --git a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj index bcfeadb..1c8eaae 100644 --- a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj +++ b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj @@ -9,5 +9,10 @@ + + + + + diff --git a/src/KeyValuePush/DefaultDictionaryBuilder.cs b/src/KeyValuePush/DefaultDictionaryBuilder.cs index 61547cb..160962c 100644 --- a/src/KeyValuePush/DefaultDictionaryBuilder.cs +++ b/src/KeyValuePush/DefaultDictionaryBuilder.cs @@ -52,7 +52,7 @@ public async Task> BuildAsync( return dict; } - private static void TryAdd(IDictionary dict, string key, string value) + public static void TryAdd(IDictionary dict, string key, string value) { if (dict.ContainsKey(key)) { From b7aab9580690cb9ef3c8a57cb61f54c7789d463b Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 13:49:30 +0100 Subject: [PATCH 18/51] test dotnet version --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 2d02a7d..474691b 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: '8.0.x' + dotnet-version: '7.0.x' # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET From 81a9bdee4b349d45a12d57a4ba892883fc23114f Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 13:51:24 +0100 Subject: [PATCH 19/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 474691b..990bf68 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -30,7 +30,7 @@ jobs: # Step 4: Install ReportGenerator - name: Install ReportGenerator - run: dotnet tool install --global dotnet-reportgenerator-globaltool + run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 # Step 5: Restore dependencies - name: Restore dependencies From b42168614b47b82bc3261899ad853d1e4a4fe26f Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:27:52 +0100 Subject: [PATCH 20/51] test --- .github/workflows/sonarcloud.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 990bf68..dbc4d55 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -40,16 +40,17 @@ jobs: - name: Run tests with coverage run: | dotnet test \ + --settings coverlet.runsettings \ --collect:"XPlat Code Coverage" \ --results-directory ./TestResults # Step 7: Convert coverage to OpenCover format - - name: Generate coverage report + - name: Convert coverage to OpenCover run: | reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./CoverageResults \ - -reporttypes:opencover + -targetdir:./TestResults/CoverageResults \ + -reporttypes:"Cobertura;Html;opencover" # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis @@ -60,7 +61,7 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml" + /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.opencover.xml" \ + /d:sonar.scanner.skipJreProvisioning=true dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - From 0023978b05f7d651dac370ff99ec0a342e97972b Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:32:16 +0100 Subject: [PATCH 21/51] test --- .github/workflows/sonarcloud.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index dbc4d55..a04f151 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -44,13 +44,14 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Step 7: Convert coverage to OpenCover format - - name: Convert coverage to OpenCover + # Step 7: Convert coverage to Cobertura format + - name: Convert coverage to Cobertura format run: | reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:"Cobertura;Html;opencover" + -reporttypes:Cobertura + # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis @@ -61,7 +62,8 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.opencover.xml" \ + /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/Cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + From dbfb789e991d272609b195c1aff0bb24e99a81bb Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:36:30 +0100 Subject: [PATCH 22/51] test --- .github/workflows/sonarcloud.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a04f151..3c4dcdd 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -52,7 +52,6 @@ jobs: -targetdir:./TestResults/CoverageResults \ -reporttypes:Cobertura - # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis env: @@ -62,8 +61,7 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/Cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="TestResults/CoverageResults/Cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - From 680bc6e87ace5db6df62fc4dfc8d1a31d4e5cf75 Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:40:41 +0100 Subject: [PATCH 23/51] test --- .github/workflows/sonarcloud.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3c4dcdd..da8cf34 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,29 +14,26 @@ jobs: runs-on: ubuntu-latest steps: - # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v4 - # Step 2: Setup .NET SDK + - name: Fetch all history for SonarCloud + run: git fetch --unshallow + - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '7.0.x' - # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - # Step 4: Install ReportGenerator - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 - # Step 5: Restore dependencies - name: Restore dependencies run: dotnet restore - # Step 6: Run tests with coverage - name: Run tests with coverage run: | dotnet test \ @@ -44,15 +41,13 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Step 7: Convert coverage to Cobertura format - - name: Convert coverage to Cobertura format + - name: Convert coverage report run: | reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:Cobertura + -reporttypes:opencover,cobertura - # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -60,8 +55,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.cobertura.reportsPaths="TestResults/CoverageResults/Cobertura.xml" \ + /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.opencover.xml" \ /d:sonar.scanner.skipJreProvisioning=true dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From e35d71697345adc4ba22c905ea24dcdc1a8b8e4d Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:42:24 +0100 Subject: [PATCH 24/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index da8cf34..012466d 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -46,7 +46,7 @@ jobs: reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:opencover,cobertura + -reporttypes:opencover;cobertura - name: Run SonarCloud analysis env: From 3e24cb1d2dba886070f2f1f9b71f668f0e9d5d20 Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:45:52 +0100 Subject: [PATCH 25/51] test --- .github/workflows/sonarcloud.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 012466d..9e19688 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,26 +14,29 @@ jobs: runs-on: ubuntu-latest steps: + # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v4 - - name: Fetch all history for SonarCloud - run: git fetch --unshallow - + # Step 2: Setup .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '7.0.x' + # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner + # Step 4: Install ReportGenerator - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 + # Step 5: Restore dependencies - name: Restore dependencies run: dotnet restore + # Step 6: Run tests with coverage - name: Run tests with coverage run: | dotnet test \ @@ -41,13 +44,15 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - - name: Convert coverage report + # Step 7: Generate coverage report + - name: Generate coverage report run: | reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:opencover;cobertura + -reporttypes:cobertura + # Step 8: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -55,7 +60,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.opencover.xml" \ + /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From c3cadcb2b6a5769c1710164148f07321f6c5a91b Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:48:23 +0100 Subject: [PATCH 26/51] test --- .github/workflows/sonarcloud.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 9e19688..eace0f1 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -61,6 +61,7 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ - /d:sonar.scanner.skipJreProvisioning=true + /d:sonar.scanner.skipJreProvisioning=true \ + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From f8f9afef8ead31103d5e1b49e990ea0e85fd05a0 Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:55:20 +0100 Subject: [PATCH 27/51] test --- .github/workflows/sonarcloud.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index eace0f1..8866198 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -40,16 +40,16 @@ jobs: - name: Run tests with coverage run: | dotnet test \ - --settings coverlet.runsettings \ + --settings src/KeyValuePush.Tests/coverlet.runsettings \ --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults + --results-directory src/KeyValuePush.Tests/TestResults # Step 7: Generate coverage report - name: Generate coverage report run: | reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./TestResults/CoverageResults \ + -reports:src/KeyValuePush.Tests/TestResults/**/coverage.cobertura.xml \ + -targetdir:src/KeyValuePush.Tests/TestResults/CoverageResults \ -reporttypes:cobertura # Step 8: Run SonarCloud analysis @@ -60,7 +60,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="src/KeyValuePush.Tests/TestResults/CoverageResults/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build From d3e52ef0b9a493801613095460d0f7b6123d88ae Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 14:57:23 +0100 Subject: [PATCH 28/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 8866198..d6b6b23 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -40,7 +40,7 @@ jobs: - name: Run tests with coverage run: | dotnet test \ - --settings src/KeyValuePush.Tests/coverlet.runsettings \ + --settings ./coverlet.runsettings \ --collect:"XPlat Code Coverage" \ --results-directory src/KeyValuePush.Tests/TestResults From 694c811d8a5821d7ecb2b3cd0535a8ae2b3f05bf Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:00:02 +0100 Subject: [PATCH 29/51] test --- .github/workflows/sonarcloud.yml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index d6b6b23..a21b3d9 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,45 +14,50 @@ jobs: runs-on: ubuntu-latest steps: - # Step 1: Checkout the repository + # Checkout completo del repositorio - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - # Step 2: Setup .NET SDK + # Configuración de .NET - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '7.0.x' - # Step 3: Install SonarScanner for .NET + # Instalar herramientas necesarias - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - # Step 4: Install ReportGenerator - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 - # Step 5: Restore dependencies + # Restaurar dependencias - name: Restore dependencies run: dotnet restore - # Step 6: Run tests with coverage + # Ejecutar pruebas y generar cobertura - name: Run tests with coverage run: | dotnet test \ --settings ./coverlet.runsettings \ --collect:"XPlat Code Coverage" \ - --results-directory src/KeyValuePush.Tests/TestResults + --results-directory ./TestResults - # Step 7: Generate coverage report + # Generar reporte de cobertura - name: Generate coverage report run: | reportgenerator \ - -reports:src/KeyValuePush.Tests/TestResults/**/coverage.cobertura.xml \ - -targetdir:src/KeyValuePush.Tests/TestResults/CoverageResults \ + -reports:./TestResults/**/coverage.cobertura.xml \ + -targetdir:./TestResults/CoverageResults \ -reporttypes:cobertura - # Step 8: Run SonarCloud analysis + # Verificar existencia del archivo de cobertura + - name: Verify coverage file + run: ls ./TestResults/CoverageResults/coverage.cobertura.xml + + # Ejecutar análisis con SonarCloud - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -60,7 +65,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.cobertura.reportsPaths="src/KeyValuePush.Tests/TestResults/CoverageResults/coverage.cobertura.xml" \ + /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build From 647a127ed1a6153e0de640758eee4c7daceabe32 Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:01:37 +0100 Subject: [PATCH 30/51] test --- .github/workflows/sonarcloud.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a21b3d9..1005ccb 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -45,6 +45,10 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults + # Verificar archivos generados después de las pruebas + - name: List files in TestResults + run: ls -R ./TestResults + # Generar reporte de cobertura - name: Generate coverage report run: | From 46ffa734d4aff60bd9a2ea9e11f791730bca3e9f Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:05:00 +0100 Subject: [PATCH 31/51] test --- .github/workflows/sonarcloud.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 1005ccb..a801c95 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,13 +14,13 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout completo del repositorio + # Checkout del repositorio - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - # Configuración de .NET + # Configurar .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: @@ -37,7 +37,7 @@ jobs: - name: Restore dependencies run: dotnet restore - # Ejecutar pruebas y generar cobertura + # Ejecutar pruebas con cobertura - name: Run tests with coverage run: | dotnet test \ @@ -45,7 +45,7 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Verificar archivos generados después de las pruebas + # Listar archivos en TestResults - name: List files in TestResults run: ls -R ./TestResults @@ -55,11 +55,12 @@ jobs: reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:cobertura + -reporttypes:cobertura \ + -fileName:coverage.cobertura.xml - # Verificar existencia del archivo de cobertura - - name: Verify coverage file - run: ls ./TestResults/CoverageResults/coverage.cobertura.xml + # Verificar archivo de cobertura + - name: Verify CoverageResults files + run: ls -l ./TestResults/CoverageResults/ # Ejecutar análisis con SonarCloud - name: Run SonarCloud analysis From a1681d3c9e823cb93f04d83bd444f015f372ebfa Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:09:25 +0100 Subject: [PATCH 32/51] test --- .github/workflows/sonarcloud.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a801c95..8addc03 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,30 +14,31 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout del repositorio + # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - # Configurar .NET SDK + # Step 2: Setup .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '7.0.x' - # Instalar herramientas necesarias + # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner + # Step 4: Install ReportGenerator - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 - # Restaurar dependencias + # Step 5: Restore dependencies - name: Restore dependencies run: dotnet restore - # Ejecutar pruebas con cobertura + # Step 6: Run tests with coverage - name: Run tests with coverage run: | dotnet test \ @@ -45,24 +46,23 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Listar archivos en TestResults - - name: List files in TestResults - run: ls -R ./TestResults - - # Generar reporte de cobertura + # Step 7: Generate coverage report - name: Generate coverage report run: | reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:cobertura \ - -fileName:coverage.cobertura.xml + -reporttypes:cobertura + + # Step 8: Rename report for consistency + - name: Rename cobertura report + run: mv ./TestResults/CoverageResults/Cobertura.xml ./TestResults/CoverageResults/coverage.cobertura.xml - # Verificar archivo de cobertura + # Step 9: Verify CoverageResults files - name: Verify CoverageResults files run: ls -l ./TestResults/CoverageResults/ - # Ejecutar análisis con SonarCloud + # Step 10: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 358c5ac31b97da049a836ac331ac6c8996ce1291 Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:21:46 +0100 Subject: [PATCH 33/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 8addc03..76d68f7 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -70,7 +70,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.opencover.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build From 3d4b94323328ee1ba7e7f457097906a71356937c Mon Sep 17 00:00:00 2001 From: vanguille Date: Thu, 26 Dec 2024 15:24:45 +0100 Subject: [PATCH 34/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 76d68f7..d15b434 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -70,7 +70,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="./TestResults/**/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build From 6ebb73689ee6e1e364e077cd825cc84d96cfe52f Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:02:04 +0100 Subject: [PATCH 35/51] test --- .github/workflows/sonarcloud.yml | 23 ++++++++--------------- coverlet.runsettings | 5 ++--- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index d15b434..5b73c9e 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,31 +14,25 @@ jobs: runs-on: ubuntu-latest steps: - # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - # Step 2: Setup .NET SDK - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: '7.0.x' - # Step 3: Install SonarScanner for .NET - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - # Step 4: Install ReportGenerator - name: Install ReportGenerator run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 - # Step 5: Restore dependencies - name: Restore dependencies run: dotnet restore - # Step 6: Run tests with coverage - name: Run tests with coverage run: | dotnet test \ @@ -46,23 +40,22 @@ jobs: --collect:"XPlat Code Coverage" \ --results-directory ./TestResults - # Step 7: Generate coverage report - name: Generate coverage report run: | reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ + -reports:./src/KeyValuePush.Tests/TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ - -reporttypes:cobertura + -reporttypes:Cobertura - # Step 8: Rename report for consistency - - name: Rename cobertura report - run: mv ./TestResults/CoverageResults/Cobertura.xml ./TestResults/CoverageResults/coverage.cobertura.xml + - name: Ensure correct report file path + run: | + if [ -f ./TestResults/CoverageResults/Cobertura.xml ]; then + mv ./TestResults/CoverageResults/Cobertura.xml ./TestResults/CoverageResults/coverage.cobertura.xml + fi - # Step 9: Verify CoverageResults files - name: Verify CoverageResults files run: ls -l ./TestResults/CoverageResults/ - # Step 10: Run SonarCloud analysis - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -70,7 +63,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.cobertura.reportsPaths="./TestResults/**/coverage.cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build diff --git a/coverlet.runsettings b/coverlet.runsettings index b9c0cc4..a998bfd 100644 --- a/coverlet.runsettings +++ b/coverlet.runsettings @@ -1,11 +1,10 @@ - - Cobertura - ./TestResults/ + cobertura + ./TestResults/CoverageResults From adfb722fce6f8f96f11a50c7719e21077d28941f Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:03:53 +0100 Subject: [PATCH 36/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 5b73c9e..0413e0b 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -43,7 +43,7 @@ jobs: - name: Generate coverage report run: | reportgenerator \ - -reports:./src/KeyValuePush.Tests/TestResults/**/coverage.cobertura.xml \ + -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./TestResults/CoverageResults \ -reporttypes:Cobertura From eba5f27158d81b29ce539a6df3f08ac7fc97dd6a Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:10:05 +0100 Subject: [PATCH 37/51] test --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 0413e0b..a5adbcf 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -63,7 +63,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/coverage.cobertura.xml" \ + /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/Cobertura.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build From 0588ce53940afa74a14d29be3d5330cae056387e Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:32:50 +0100 Subject: [PATCH 38/51] test --- .github/workflows/sonarcloud.yml | 30 +++++------------------------- coverlet.runsettings | 12 ------------ 2 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 coverlet.runsettings diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a5adbcf..cf84883 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -27,34 +27,14 @@ jobs: - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - - name: Install ReportGenerator - run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.12 - - - name: Restore dependencies - run: dotnet restore - - name: Run tests with coverage run: | dotnet test \ - --settings ./coverlet.runsettings \ --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults - - - name: Generate coverage report - run: | - reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./TestResults/CoverageResults \ - -reporttypes:Cobertura - - - name: Ensure correct report file path - run: | - if [ -f ./TestResults/CoverageResults/Cobertura.xml ]; then - mv ./TestResults/CoverageResults/Cobertura.xml ./TestResults/CoverageResults/coverage.cobertura.xml - fi - - - name: Verify CoverageResults files - run: ls -l ./TestResults/CoverageResults/ + --results-directory ./TestResults \ + /p:CollectCoverage=true \ + /p:CoverletOutput=./TestResults/Coverage/ \ + /p:CoverletOutputFormat=opencover - name: Run SonarCloud analysis env: @@ -63,7 +43,7 @@ jobs: dotnet sonarscanner begin \ /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ - /d:sonar.cs.cobertura.reportsPaths="./TestResults/CoverageResults/Cobertura.xml" \ + /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build diff --git a/coverlet.runsettings b/coverlet.runsettings deleted file mode 100644 index a998bfd..0000000 --- a/coverlet.runsettings +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - cobertura - ./TestResults/CoverageResults - - - - - From ba86025aba9e0926c739683a9b0c8dccdf04c591 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:46:01 +0100 Subject: [PATCH 39/51] test --- .github/workflows/sonarcloud.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index cf84883..0c26c12 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -27,14 +27,17 @@ jobs: - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner - - name: Run tests with coverage + - name: Install Coverlet.Console + run: dotnet tool install --global coverlet.console + + - name: Run tests with Coverlet run: | - dotnet test \ - --collect:"XPlat Code Coverage" \ - --results-directory ./TestResults \ - /p:CollectCoverage=true \ - /p:CoverletOutput=./TestResults/Coverage/ \ - /p:CoverletOutputFormat=opencover + dotnet build ./src/KeyValuePush.sln + coverlet ./src/KeyValuePush.Tests/bin/Debug/net7.0/KeyValuePush.Tests.dll \ + --target "dotnet" \ + --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build" \ + --output ./TestResults/Coverage/ \ + --format opencover - name: Run SonarCloud analysis env: From e58d4160d1c86b74df888bf83e69f93b3c5aac62 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:48:37 +0100 Subject: [PATCH 40/51] test --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 0c26c12..b64f8b3 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -32,7 +32,7 @@ jobs: - name: Run tests with Coverlet run: | - dotnet build ./src/KeyValuePush.sln + dotnet build AutoGuru.KeyValuePush.sln coverlet ./src/KeyValuePush.Tests/bin/Debug/net7.0/KeyValuePush.Tests.dll \ --target "dotnet" \ --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build" \ @@ -49,5 +49,5 @@ jobs: /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - dotnet build + dotnet build AutoGuru.KeyValuePush.sln dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From f8578b0f67b5606438817ce50b4ccac31c0c33ed Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 14:56:28 +0100 Subject: [PATCH 41/51] test --- .github/workflows/sonarcloud.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index b64f8b3..25092d0 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -48,6 +48,7 @@ jobs: /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ /d:sonar.scanner.skipJreProvisioning=true \ + /d:sonar.scanner.scanAll=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build AutoGuru.KeyValuePush.sln dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From 24ec7ae147b07ff03533e2f45ae6b75a312c9802 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 15:06:14 +0100 Subject: [PATCH 42/51] test --- .github/workflows/sonarcloud.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 25092d0..54f8408 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,9 +1,10 @@ -name: SonarQube Analysis (C#) +name: SonarCloud Analysis (C#) on: push: branches: - main + - feature/* pull_request: branches: - main @@ -30,9 +31,9 @@ jobs: - name: Install Coverlet.Console run: dotnet tool install --global coverlet.console - - name: Run tests with Coverlet + - name: Build and Test with Coverage run: | - dotnet build AutoGuru.KeyValuePush.sln + dotnet build ./AutoGuru.KeyValuePush.sln coverlet ./src/KeyValuePush.Tests/bin/Debug/net7.0/KeyValuePush.Tests.dll \ --target "dotnet" \ --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build" \ @@ -47,8 +48,6 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ - /d:sonar.scanner.skipJreProvisioning=true \ - /d:sonar.scanner.scanAll=true \ - /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - dotnet build AutoGuru.KeyValuePush.sln + /d:sonar.scanner.skipJreProvisioning=true + dotnet build ./AutoGuru.KeyValuePush.sln dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From ceb5cd20077eaf7b214e35c7bca3d93bbaf26ff7 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 15:11:39 +0100 Subject: [PATCH 43/51] test --- .github/workflows/sonarcloud.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 54f8408..59667f1 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -48,6 +48,7 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ - /d:sonar.scanner.skipJreProvisioning=true + /d:sonar.scanner.skipJreProvisioning=true \ + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build ./AutoGuru.KeyValuePush.sln dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From 31eec52623e40f8853da014a63b52e3ef2dd6a16 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 15:15:34 +0100 Subject: [PATCH 44/51] test --- .../AutoGuru.KeyValuePush.Redis.csproj | 25 +++++ src/KeyValuePush.Redis copy/Program.cs | 91 +++++++++++++++++++ .../Properties/launchSettings.json | 8 ++ src/KeyValuePush.Redis copy/RedisPusher.cs | 45 +++++++++ 4 files changed, 169 insertions(+) create mode 100644 src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj create mode 100644 src/KeyValuePush.Redis copy/Program.cs create mode 100644 src/KeyValuePush.Redis copy/Properties/launchSettings.json create mode 100644 src/KeyValuePush.Redis copy/RedisPusher.cs diff --git a/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj b/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj new file mode 100644 index 0000000..1965554 --- /dev/null +++ b/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj @@ -0,0 +1,25 @@ + + + + 2.0.0 + A dotnet global tool for pushing key-value data into redis. + kv-push-redis + Exe + true + true + kv-push-redis + true + embedded + + + + + + + + + + + + + diff --git a/src/KeyValuePush.Redis copy/Program.cs b/src/KeyValuePush.Redis copy/Program.cs new file mode 100644 index 0000000..2f3b91f --- /dev/null +++ b/src/KeyValuePush.Redis copy/Program.cs @@ -0,0 +1,91 @@ +using McMaster.Extensions.CommandLineUtils; +using Microsoft.Extensions.DependencyInjection; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace AutoGuru.KeyValuePush.Redis +{ + public class Program + { + public static async Task Main(string[] args) + { + var services = new ServiceCollection() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .BuildServiceProvider(); + + var app = new CommandLineApplication(); + app.Conventions + .UseDefaultConventions() + .UseConstructorInjection(services); + return await app.ExecuteAsync(args); + } + + [Argument(0, Description = "The path to source data from.")] + [Required] + public string Path { get; set; } + + [Argument(1, + Description = + "The redis configuration to connect to a redis instance with. " + + "Should be parseable by `StackExchange.Redis.ConfigurationOptions.Parse`.")] + [Required] + public string RedisConfiguration { get; set; } + + [Option("-d|--db", Description = "The redis db to use (if any).")] + public int? RedisDb { get; set; } + + [Option("-sp|--search-pattern", + Description = + "The search string to match against the names of files in path. This parameter " + + "can contain a combination of valid literal path and wildcard (* and ?) characters, " + + "but it doesn't support regular expressions. " + + "The default is: \"*\"")] + public string SearchPattern { get; set; } = "*"; + + [Option("-so|--search-option", + Description = + "One of the enumeration values that specifies whether the search operation should " + + "include all subdirectories or only the current directory. " + + "The default is: TopDirectoryOnly")] + public SearchOption SearchOption { get; set; } = SearchOption.TopDirectoryOnly; + + [Option("-rj|--recurse-into-json-files", + Description = + "Whether to recurse into json files. If true, json files are considered to have " + + "key-value pairs in them too (e.g. a top-level object with a single level of kvps) and " + + "these will be crawled, extracted and pushed individually. " + + "The default is: false.")] + public bool RecurseIntoJsonFiles { get; set; } = false; + + private readonly IExecutor _executor; + private readonly RedisPusher _pusher; + +#pragma warning disable CS8618 // Arg properties are always set before use by CommandLineUtils + public Program(IExecutor executor, IPusher pusher) + { + _executor = executor; + _pusher = (RedisPusher)pusher; + } +#pragma warning restore CS8618 + + public async Task OnExecuteAsync( + CommandLineApplication app, + CancellationToken cancellationToken = default) + { + _pusher.Configure( + RedisConfiguration, + RedisDb); + + return await _executor.ExecuteAsync( + Path, + SearchPattern, + SearchOption, + RecurseIntoJsonFiles, + cancellationToken); + } + } +} diff --git a/src/KeyValuePush.Redis copy/Properties/launchSettings.json b/src/KeyValuePush.Redis copy/Properties/launchSettings.json new file mode 100644 index 0000000..fef44a3 --- /dev/null +++ b/src/KeyValuePush.Redis copy/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "AutoGuru.KeyValuePush.Redis": { + "commandName": "Project", + "commandLineArgs": "\"C:\\Users\\benmc\\Desktop\\testkvps\" \"localhost:49153\" -d=3 -rj" + } + } +} \ No newline at end of file diff --git a/src/KeyValuePush.Redis copy/RedisPusher.cs b/src/KeyValuePush.Redis copy/RedisPusher.cs new file mode 100644 index 0000000..b697267 --- /dev/null +++ b/src/KeyValuePush.Redis copy/RedisPusher.cs @@ -0,0 +1,45 @@ +using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AutoGuru.KeyValuePush.Redis +{ + public sealed class RedisPusher : IPusher, IDisposable + { + private ConnectionMultiplexer? _connectionMultiplexer; + private IDatabase? _db; + + public void Configure( + string configuration, + int? db) + { + var configOptions = ConfigurationOptions.Parse(configuration); + _connectionMultiplexer = ConnectionMultiplexer.Connect(configOptions); + _db = db.HasValue + ? _connectionMultiplexer.GetDatabase(db.Value) + : _connectionMultiplexer.GetDatabase(); + } + + public async Task PushAsync( + IDictionary dictionary, + CancellationToken cancellationToken) + { + if (_db is null) + { + throw new Exception($"{nameof(RedisPusher)} wasn't configured yet."); + } + + await _db.StringSetAsync(dictionary + .ToDictionary(kvp => new RedisKey(kvp.Key), kvp => new RedisValue(kvp.Value)) + .ToArray()); + } + + public void Dispose() + { + _connectionMultiplexer?.Dispose(); + } + } +} From b7336a3903942f5a6e5cb927628773db7f013338 Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 15:18:29 +0100 Subject: [PATCH 45/51] test --- .../AutoGuru.KeyValuePush.Redis.csproj | 25 ----- src/KeyValuePush.Redis copy/Program.cs | 91 ------------------- .../Properties/launchSettings.json | 8 -- src/KeyValuePush.Redis copy/RedisPusher.cs | 45 --------- src/KeyValuePush/DefaultDictionaryBuilder2.cs | 70 ++++++++++++++ 5 files changed, 70 insertions(+), 169 deletions(-) delete mode 100644 src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj delete mode 100644 src/KeyValuePush.Redis copy/Program.cs delete mode 100644 src/KeyValuePush.Redis copy/Properties/launchSettings.json delete mode 100644 src/KeyValuePush.Redis copy/RedisPusher.cs create mode 100644 src/KeyValuePush/DefaultDictionaryBuilder2.cs diff --git a/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj b/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj deleted file mode 100644 index 1965554..0000000 --- a/src/KeyValuePush.Redis copy/AutoGuru.KeyValuePush.Redis.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - 2.0.0 - A dotnet global tool for pushing key-value data into redis. - kv-push-redis - Exe - true - true - kv-push-redis - true - embedded - - - - - - - - - - - - - diff --git a/src/KeyValuePush.Redis copy/Program.cs b/src/KeyValuePush.Redis copy/Program.cs deleted file mode 100644 index 2f3b91f..0000000 --- a/src/KeyValuePush.Redis copy/Program.cs +++ /dev/null @@ -1,91 +0,0 @@ -using McMaster.Extensions.CommandLineUtils; -using Microsoft.Extensions.DependencyInjection; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace AutoGuru.KeyValuePush.Redis -{ - public class Program - { - public static async Task Main(string[] args) - { - var services = new ServiceCollection() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .BuildServiceProvider(); - - var app = new CommandLineApplication(); - app.Conventions - .UseDefaultConventions() - .UseConstructorInjection(services); - return await app.ExecuteAsync(args); - } - - [Argument(0, Description = "The path to source data from.")] - [Required] - public string Path { get; set; } - - [Argument(1, - Description = - "The redis configuration to connect to a redis instance with. " + - "Should be parseable by `StackExchange.Redis.ConfigurationOptions.Parse`.")] - [Required] - public string RedisConfiguration { get; set; } - - [Option("-d|--db", Description = "The redis db to use (if any).")] - public int? RedisDb { get; set; } - - [Option("-sp|--search-pattern", - Description = - "The search string to match against the names of files in path. This parameter " + - "can contain a combination of valid literal path and wildcard (* and ?) characters, " + - "but it doesn't support regular expressions. " + - "The default is: \"*\"")] - public string SearchPattern { get; set; } = "*"; - - [Option("-so|--search-option", - Description = - "One of the enumeration values that specifies whether the search operation should " + - "include all subdirectories or only the current directory. " + - "The default is: TopDirectoryOnly")] - public SearchOption SearchOption { get; set; } = SearchOption.TopDirectoryOnly; - - [Option("-rj|--recurse-into-json-files", - Description = - "Whether to recurse into json files. If true, json files are considered to have " + - "key-value pairs in them too (e.g. a top-level object with a single level of kvps) and " + - "these will be crawled, extracted and pushed individually. " + - "The default is: false.")] - public bool RecurseIntoJsonFiles { get; set; } = false; - - private readonly IExecutor _executor; - private readonly RedisPusher _pusher; - -#pragma warning disable CS8618 // Arg properties are always set before use by CommandLineUtils - public Program(IExecutor executor, IPusher pusher) - { - _executor = executor; - _pusher = (RedisPusher)pusher; - } -#pragma warning restore CS8618 - - public async Task OnExecuteAsync( - CommandLineApplication app, - CancellationToken cancellationToken = default) - { - _pusher.Configure( - RedisConfiguration, - RedisDb); - - return await _executor.ExecuteAsync( - Path, - SearchPattern, - SearchOption, - RecurseIntoJsonFiles, - cancellationToken); - } - } -} diff --git a/src/KeyValuePush.Redis copy/Properties/launchSettings.json b/src/KeyValuePush.Redis copy/Properties/launchSettings.json deleted file mode 100644 index fef44a3..0000000 --- a/src/KeyValuePush.Redis copy/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "AutoGuru.KeyValuePush.Redis": { - "commandName": "Project", - "commandLineArgs": "\"C:\\Users\\benmc\\Desktop\\testkvps\" \"localhost:49153\" -d=3 -rj" - } - } -} \ No newline at end of file diff --git a/src/KeyValuePush.Redis copy/RedisPusher.cs b/src/KeyValuePush.Redis copy/RedisPusher.cs deleted file mode 100644 index b697267..0000000 --- a/src/KeyValuePush.Redis copy/RedisPusher.cs +++ /dev/null @@ -1,45 +0,0 @@ -using StackExchange.Redis; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AutoGuru.KeyValuePush.Redis -{ - public sealed class RedisPusher : IPusher, IDisposable - { - private ConnectionMultiplexer? _connectionMultiplexer; - private IDatabase? _db; - - public void Configure( - string configuration, - int? db) - { - var configOptions = ConfigurationOptions.Parse(configuration); - _connectionMultiplexer = ConnectionMultiplexer.Connect(configOptions); - _db = db.HasValue - ? _connectionMultiplexer.GetDatabase(db.Value) - : _connectionMultiplexer.GetDatabase(); - } - - public async Task PushAsync( - IDictionary dictionary, - CancellationToken cancellationToken) - { - if (_db is null) - { - throw new Exception($"{nameof(RedisPusher)} wasn't configured yet."); - } - - await _db.StringSetAsync(dictionary - .ToDictionary(kvp => new RedisKey(kvp.Key), kvp => new RedisValue(kvp.Value)) - .ToArray()); - } - - public void Dispose() - { - _connectionMultiplexer?.Dispose(); - } - } -} diff --git a/src/KeyValuePush/DefaultDictionaryBuilder2.cs b/src/KeyValuePush/DefaultDictionaryBuilder2.cs new file mode 100644 index 0000000..1af1c28 --- /dev/null +++ b/src/KeyValuePush/DefaultDictionaryBuilder2.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace AutoGuru.KeyValuePush +{ + public class DefaultDictionaryBuilder2 : IDictionaryBuilder + { + public async Task> BuildAsync( + string path, + string searchPattern, + SearchOption searchOption, + bool recurseIntoJsonFiles, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + var filePaths = Directory.GetFiles(path, searchPattern, searchOption); + var dict = new Dictionary(filePaths.Length); + + foreach (var filePath in filePaths) + { + cancellationToken.ThrowIfCancellationRequested(); + + if (Path.GetExtension(filePath).Contains(".json") && + recurseIntoJsonFiles) + { + // Read file as JSON and extract kvps + var bytes = await File.ReadAllBytesAsync(filePath, cancellationToken); + var innerDict = JsonSerializer.Deserialize>(bytes); + if (innerDict is null) + { + throw new Exception($"Problem reading {filePath} as dictionary."); + } + + foreach (var kvp in innerDict) + { + TryAdd2(dict, kvp.Key, kvp.Value); + } + } + else + { + var fileName = Path.GetFileNameWithoutExtension(filePath); + var text = await File.ReadAllTextAsync(filePath, cancellationToken); + TryAdd2(dict, fileName, text); + } + } + + return dict; + } + + public static void TryAdd2(IDictionary dict, string key, string value) + { + if (dict.ContainsKey(key)) + { + if (dict[key] == value) + { + return; + } + + throw new Exception($"Duplicate key of '{key}' with a different value detected."); + } + + dict.Add(key, value); + } + } +} From 0fe07b96f29cabe6e4990001504bdcda1764d57d Mon Sep 17 00:00:00 2001 From: vanguille Date: Tue, 31 Dec 2024 15:25:41 +0100 Subject: [PATCH 46/51] test --- .github/workflows/sonarcloud.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 59667f1..eb333ea 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -31,15 +31,26 @@ jobs: - name: Install Coverlet.Console run: dotnet tool install --global coverlet.console - - name: Build and Test with Coverage + - name: Restore dependencies + run: dotnet restore ./AutoGuru.KeyValuePush.sln + + - name: Build solution + run: dotnet build ./AutoGuru.KeyValuePush.sln --no-restore --configuration Debug + + - name: Run tests with coverage run: | - dotnet build ./AutoGuru.KeyValuePush.sln coverlet ./src/KeyValuePush.Tests/bin/Debug/net7.0/KeyValuePush.Tests.dll \ --target "dotnet" \ - --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build" \ + --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build --logger trx --results-directory ./TestResults/" \ --output ./TestResults/Coverage/ \ --format opencover + - name: Upload test results (optional, for visibility in GitHub Actions) + uses: actions/upload-artifact@v3 + with: + name: TestResults + path: ./TestResults/ + - name: Run SonarCloud analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -48,7 +59,10 @@ jobs: /k:"autoguru-au_kv-push" \ /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ + /d:sonar.inclusions="**/*.cs" \ + /d:sonar.exclusions="**/bin/**,**/obj/**" \ /d:sonar.scanner.skipJreProvisioning=true \ + /d:sonar.verbose=true \ /d:sonar.login="${{ secrets.SONAR_TOKEN }}" dotnet build ./AutoGuru.KeyValuePush.sln dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From 9590ac69cb087bb946cc2a66f03539f074a37c35 Mon Sep 17 00:00:00 2001 From: vanguille Date: Mon, 6 Jan 2025 00:48:35 +0100 Subject: [PATCH 47/51] Added test to cover the requisites --- .github/workflows/sonarcloud.yml | 4 +- .../KeyValuePush.Redis.Tests.csproj | 19 +++ .../RedisPusherTests.cs | 29 +++++ .../DefaultDictionaryBuilderTests.cs | 114 ++++++++---------- .../DefaultExecutorTests.cs | 102 ++++++++++++++++ src/KeyValuePush/DefaultDictionaryBuilder2.cs | 70 ----------- 6 files changed, 204 insertions(+), 134 deletions(-) create mode 100644 src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj create mode 100644 src/KeyValuePush.Redis.Tests/RedisPusherTests.cs create mode 100644 src/KeyValuePush.Tests/DefaultExecutorTests.cs delete mode 100644 src/KeyValuePush/DefaultDictionaryBuilder2.cs diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index eb333ea..0847fe6 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -56,8 +56,8 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | dotnet sonarscanner begin \ - /k:"autoguru-au_kv-push" \ - /o:"autoguru-au" \ + /k:"vanguille_kv-push-sonar" \ + /o:"vanguille" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ /d:sonar.inclusions="**/*.cs" \ /d:sonar.exclusions="**/bin/**,**/obj/**" \ diff --git a/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj b/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj new file mode 100644 index 0000000..0c7ba31 --- /dev/null +++ b/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj @@ -0,0 +1,19 @@ + + + net7.0 + false + + + + + + + + + + + + + + + diff --git a/src/KeyValuePush.Redis.Tests/RedisPusherTests.cs b/src/KeyValuePush.Redis.Tests/RedisPusherTests.cs new file mode 100644 index 0000000..fb37c2e --- /dev/null +++ b/src/KeyValuePush.Redis.Tests/RedisPusherTests.cs @@ -0,0 +1,29 @@ +using Moq; +using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace AutoGuru.KeyValuePush.Redis.Tests +{ + public class RedisPusherTests + { + private readonly Mock _mockDatabase; + private readonly RedisPusher _pusher; + + public RedisPusherTests() + { + _mockDatabase = new Mock(); + _pusher = new RedisPusher(); + + // Usamos reflexión para inyectar el mock en el campo privado + var field = typeof(RedisPusher).GetField("_db", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + field?.SetValue(_pusher, _mockDatabase.Object); + } + + + } +} diff --git a/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs index ae9a221..fda68b3 100644 --- a/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs +++ b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs @@ -4,9 +4,10 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using AutoGuru.KeyValuePush; using Xunit; -namespace AutoGuru.KeyValuePush.Tests +namespace KeyValuePush.Tests { public class DefaultDictionaryBuilderTests { @@ -55,61 +56,85 @@ public void TryAdd_ShouldThrowException_WhenKeyExistsWithDifferentValue() } [Fact] - public async Task BuildAsync_ShouldReturnDictionary_WhenFilesAreValid() + public async Task BuildAsync_ShouldThrowException_WhenFileAccessFailsAsync() { - var path = "TestFiles"; + var path = "RestrictedFiles"; Directory.CreateDirectory(path); - File.WriteAllText(Path.Combine(path, "file1.txt"), "Content1"); - File.WriteAllText(Path.Combine(path, "file2.txt"), "Content2"); + var filePath = Path.Combine(path, "file1.txt"); + File.WriteAllText(filePath, "Content1"); - var result = await _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + // Bloquear el archivo para simular acceso denegado + using (var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None)) + { + var exception = await Assert.ThrowsAsync(() => + _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, CancellationToken.None)); - Assert.Equal(2, result.Count); - Assert.Equal("Content1", result["file1"]); - Assert.Equal("Content2", result["file2"]); + Assert.Contains("being used by another process", exception.Message); + } - Directory.Delete(path, true); + File.Delete(filePath); + Directory.Delete(path); } + [Fact] - public async Task BuildAsync_ShouldThrowJsonException_WhenJsonFileIsInvalid() + public async Task BuildAsync_ShouldRespectCancellationTokenAsync() { var path = "TestFiles"; Directory.CreateDirectory(path); - File.WriteAllText(Path.Combine(path, "file1.json"), "Invalid JSON Content"); + File.WriteAllText(Path.Combine(path, "file1.txt"), "Content1"); + + using var cts = new CancellationTokenSource(); + cts.Cancel(); - var exception = await Assert.ThrowsAsync(() => _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, true, CancellationToken.None)); + await Assert.ThrowsAsync(() => + _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, cts.Token)); - Assert.Contains("is an invalid start of a value", exception.Message); Directory.Delete(path, true); } [Fact] - public async Task BuildAsync_ShouldHandleEmptyDirectory() + public async Task BuildAsync_ShouldHandleDuplicateKeysInJsonFiles() { - var path = "EmptyDirectory"; + var path = "TestFiles"; Directory.CreateDirectory(path); - var result = await _builder.BuildAsync(path, "*.*", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + // Crear un archivo JSON con claves únicas + var jsonContent = JsonSerializer.Serialize(new Dictionary + { + { "Key1", "Value1" }, + { "Key2", "Value2" } + }); + File.WriteAllText(Path.Combine(path, "file1.json"), jsonContent); + + var result = await _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, true, CancellationToken.None); + + Assert.Equal(2, result.Count); + Assert.Equal("Value1", result["Key1"]); + Assert.Equal("Value2", result["Key2"]); - Assert.Empty(result); Directory.Delete(path, true); } + [Fact] - public async Task BuildAsync_ShouldReturnEmptyDictionary_WhenNoMatchingFilesFound() + public async Task BuildAsync_ShouldIgnoreFilesWithNonJsonExtensions() { var path = "TestFiles"; Directory.CreateDirectory(path); - var result = await _builder.BuildAsync(path, "*.xml", SearchOption.TopDirectoryOnly, false, CancellationToken.None); + // Crear un archivo con extensión no soportada + File.WriteAllText(Path.Combine(path, "file1.unsupported"), "Unsupported Content"); + + var result = await _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, false, CancellationToken.None); Assert.Empty(result); Directory.Delete(path, true); } + [Fact] - public async Task BuildAsync_ShouldSkipJsonFiles_WhenRecurseIntoJsonFilesIsFalse() + public async Task BuildAsync_ShouldCombineJsonAndTextFiles() { var path = "TestFiles"; Directory.CreateDirectory(path); @@ -119,50 +144,15 @@ public async Task BuildAsync_ShouldSkipJsonFiles_WhenRecurseIntoJsonFilesIsFalse { "Key2", "Value2" } }); File.WriteAllText(Path.Combine(path, "file1.json"), jsonContent); + File.WriteAllText(Path.Combine(path, "file2.txt"), "TextContent"); - var result = await _builder.BuildAsync(path, "*.json", SearchOption.TopDirectoryOnly, false, CancellationToken.None); - - Assert.Single(result); - Assert.Equal(jsonContent, result["file1"]); - - Directory.Delete(path, true); - } - - [Fact] - public async Task BuildAsync_ShouldProcessNestedDirectories_WhenSearchOptionIsAllDirectories() - { - var path = "NestedTestFiles"; - var nestedPath = Path.Combine(path, "SubDirectory"); - Directory.CreateDirectory(nestedPath); - File.WriteAllText(Path.Combine(nestedPath, "file1.txt"), "Content1"); - - var result = await _builder.BuildAsync(path, "*.txt", SearchOption.AllDirectories, false, CancellationToken.None); - - Assert.Single(result); - Assert.Equal("Content1", result["file1"]); + var result = await _builder.BuildAsync(path, "*.*", SearchOption.TopDirectoryOnly, true, CancellationToken.None); + Assert.Equal(3, result.Count); + Assert.Equal("Value1", result["Key1"]); + Assert.Equal("Value2", result["Key2"]); + Assert.Equal("TextContent", result["file2"]); Directory.Delete(path, true); } - - [Fact] -public async Task BuildAsync_ShouldIgnoreUnsupportedExtensions() -{ - // Arrange - var path = "TestFiles"; - Directory.CreateDirectory(path); - File.WriteAllText(Path.Combine(path, "file1.unsupported"), "Unsupported Content"); - - // Act - var result = await _builder.BuildAsync(path, "*.txt", SearchOption.TopDirectoryOnly, false, CancellationToken.None); - - // Assert - Assert.Empty(result); - - // Clean up - Directory.Delete(path, true); -} - } - - } diff --git a/src/KeyValuePush.Tests/DefaultExecutorTests.cs b/src/KeyValuePush.Tests/DefaultExecutorTests.cs new file mode 100644 index 0000000..85e65a7 --- /dev/null +++ b/src/KeyValuePush.Tests/DefaultExecutorTests.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using AutoGuru.KeyValuePush; +using Moq; +using Xunit; + +namespace KeyValuePush.Tests +{ + public class DefaultExecutorTests + { + private readonly Mock _mockDictionaryBuilder; + private readonly Mock _mockPusher; + private readonly DefaultExecutor _executor; + + public DefaultExecutorTests() + { + _mockDictionaryBuilder = new Mock(); + _mockPusher = new Mock(); + _executor = new DefaultExecutor(_mockDictionaryBuilder.Object, _mockPusher.Object); + } + + [Fact] + public async Task ExecuteAsync_ShouldReturnZero_WhenSuccessful() + { + // Arrange + var dict = new Dictionary { { "key1", "value1" } }; + _mockDictionaryBuilder + .Setup(builder => builder.BuildAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(dict); + _mockPusher + .Setup(pusher => pusher.PushAsync(It.IsAny>(), It.IsAny())) + .Returns(Task.CompletedTask); + + // Act + var result = await _executor.ExecuteAsync("path", "*.txt", SearchOption.TopDirectoryOnly, false); + + // Assert + Assert.Equal(0, result); + } + + [Fact] + public async Task ExecuteAsync_ShouldReturnBuilderError_WhenBuildAsyncFails() + { + // Arrange + _mockDictionaryBuilder + .Setup(builder => builder.BuildAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Build error")); + + // Act + var result = await _executor.ExecuteAsync("path", "*.txt", SearchOption.TopDirectoryOnly, false); + + // Assert + Assert.Equal((int)DefaultExecutor.ErrorCode.BuilderError, result); + } + + [Fact] + public async Task ExecuteAsync_ShouldReturnPusherError_WhenPushAsyncFails() + { + // Arrange + var dict = new Dictionary { { "key1", "value1" } }; + _mockDictionaryBuilder + .Setup(builder => builder.BuildAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(dict); + _mockPusher + .Setup(pusher => pusher.PushAsync(It.IsAny>(), It.IsAny())) + .ThrowsAsync(new Exception("Push error")); + + // Act + var result = await _executor.ExecuteAsync("path", "*.txt", SearchOption.TopDirectoryOnly, false); + + // Assert + Assert.Equal((int)DefaultExecutor.ErrorCode.PusherError, result); + } + + [Fact] + public async Task ExecuteAsync_ShouldLogErrorMessage_WhenExceptionOccurs() + { + // Arrange + var dict = new Dictionary { { "key1", "value1" } }; + _mockDictionaryBuilder + .Setup(builder => builder.BuildAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(dict); + _mockPusher + .Setup(pusher => pusher.PushAsync(It.IsAny>(), It.IsAny())) + .ThrowsAsync(new Exception("Push error")); + + using var consoleOutput = new StringWriter(); + Console.SetError(consoleOutput); + + // Act + await _executor.ExecuteAsync("path", "*.txt", SearchOption.TopDirectoryOnly, false); + + // Assert + var output = consoleOutput.ToString(); + Assert.Contains("Unexpected error!", output); + Assert.Contains("Push error", output); + } + } +} diff --git a/src/KeyValuePush/DefaultDictionaryBuilder2.cs b/src/KeyValuePush/DefaultDictionaryBuilder2.cs deleted file mode 100644 index 1af1c28..0000000 --- a/src/KeyValuePush/DefaultDictionaryBuilder2.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; - -namespace AutoGuru.KeyValuePush -{ - public class DefaultDictionaryBuilder2 : IDictionaryBuilder - { - public async Task> BuildAsync( - string path, - string searchPattern, - SearchOption searchOption, - bool recurseIntoJsonFiles, - CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - var filePaths = Directory.GetFiles(path, searchPattern, searchOption); - var dict = new Dictionary(filePaths.Length); - - foreach (var filePath in filePaths) - { - cancellationToken.ThrowIfCancellationRequested(); - - if (Path.GetExtension(filePath).Contains(".json") && - recurseIntoJsonFiles) - { - // Read file as JSON and extract kvps - var bytes = await File.ReadAllBytesAsync(filePath, cancellationToken); - var innerDict = JsonSerializer.Deserialize>(bytes); - if (innerDict is null) - { - throw new Exception($"Problem reading {filePath} as dictionary."); - } - - foreach (var kvp in innerDict) - { - TryAdd2(dict, kvp.Key, kvp.Value); - } - } - else - { - var fileName = Path.GetFileNameWithoutExtension(filePath); - var text = await File.ReadAllTextAsync(filePath, cancellationToken); - TryAdd2(dict, fileName, text); - } - } - - return dict; - } - - public static void TryAdd2(IDictionary dict, string key, string value) - { - if (dict.ContainsKey(key)) - { - if (dict[key] == value) - { - return; - } - - throw new Exception($"Duplicate key of '{key}' with a different value detected."); - } - - dict.Add(key, value); - } - } -} From b6411ed83c3e3e69db42a2550ba2b2e22e0f14be Mon Sep 17 00:00:00 2001 From: vanguille Date: Mon, 6 Jan 2025 00:51:58 +0100 Subject: [PATCH 48/51] test --- src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs | 6 +++--- src/KeyValuePush.Tests/DefaultExecutorTests.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs index fda68b3..7d4df25 100644 --- a/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs +++ b/src/KeyValuePush.Tests/DefaultDictionaryBuilderTests.cs @@ -94,7 +94,7 @@ await Assert.ThrowsAsync(() => } [Fact] - public async Task BuildAsync_ShouldHandleDuplicateKeysInJsonFiles() + public async Task BuildAsync_ShouldHandleDuplicateKeysInJsonFilesAsync() { var path = "TestFiles"; Directory.CreateDirectory(path); @@ -118,7 +118,7 @@ public async Task BuildAsync_ShouldHandleDuplicateKeysInJsonFiles() [Fact] - public async Task BuildAsync_ShouldIgnoreFilesWithNonJsonExtensions() + public async Task BuildAsync_ShouldIgnoreFilesWithNonJsonExtensionsAsync() { var path = "TestFiles"; Directory.CreateDirectory(path); @@ -134,7 +134,7 @@ public async Task BuildAsync_ShouldIgnoreFilesWithNonJsonExtensions() [Fact] - public async Task BuildAsync_ShouldCombineJsonAndTextFiles() + public async Task BuildAsync_ShouldCombineJsonAndTextFilesAsync() { var path = "TestFiles"; Directory.CreateDirectory(path); diff --git a/src/KeyValuePush.Tests/DefaultExecutorTests.cs b/src/KeyValuePush.Tests/DefaultExecutorTests.cs index 85e65a7..14fb93a 100644 --- a/src/KeyValuePush.Tests/DefaultExecutorTests.cs +++ b/src/KeyValuePush.Tests/DefaultExecutorTests.cs @@ -23,7 +23,7 @@ public DefaultExecutorTests() } [Fact] - public async Task ExecuteAsync_ShouldReturnZero_WhenSuccessful() + public async Task ExecuteAsync_ShouldReturnZero_WhenSuccessfulAsync() { // Arrange var dict = new Dictionary { { "key1", "value1" } }; @@ -42,7 +42,7 @@ public async Task ExecuteAsync_ShouldReturnZero_WhenSuccessful() } [Fact] - public async Task ExecuteAsync_ShouldReturnBuilderError_WhenBuildAsyncFails() + public async Task ExecuteAsync_ShouldReturnBuilderError_WhenBuildAsyncFailsAsync() { // Arrange _mockDictionaryBuilder @@ -57,7 +57,7 @@ public async Task ExecuteAsync_ShouldReturnBuilderError_WhenBuildAsyncFails() } [Fact] - public async Task ExecuteAsync_ShouldReturnPusherError_WhenPushAsyncFails() + public async Task ExecuteAsync_ShouldReturnPusherError_WhenPushAsyncFailsAsync() { // Arrange var dict = new Dictionary { { "key1", "value1" } }; @@ -76,7 +76,7 @@ public async Task ExecuteAsync_ShouldReturnPusherError_WhenPushAsyncFails() } [Fact] - public async Task ExecuteAsync_ShouldLogErrorMessage_WhenExceptionOccurs() + public async Task ExecuteAsync_ShouldLogErrorMessage_WhenExceptionOccursAsync() { // Arrange var dict = new Dictionary { { "key1", "value1" } }; From 1a3d1f044377c7cb96b22c695ef98fe88ae18aea Mon Sep 17 00:00:00 2001 From: vanguille Date: Mon, 6 Jan 2025 00:52:43 +0100 Subject: [PATCH 49/51] test --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 0847fe6..eb333ea 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -56,8 +56,8 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | dotnet sonarscanner begin \ - /k:"vanguille_kv-push-sonar" \ - /o:"vanguille" \ + /k:"autoguru-au_kv-push" \ + /o:"autoguru-au" \ /d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ /d:sonar.inclusions="**/*.cs" \ /d:sonar.exclusions="**/bin/**,**/obj/**" \ From 5b3ea4d1804a4913c7958ec6a7e8bc1aa1e9a006 Mon Sep 17 00:00:00 2001 From: vanguille Date: Mon, 6 Jan 2025 00:57:13 +0100 Subject: [PATCH 50/51] Fixed feature trigger --- .github/workflows/sonarcloud.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index eb333ea..38cd0f7 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - feature/* pull_request: branches: - main From bda5c14badc6120c753e17209c07fc693e20a63c Mon Sep 17 00:00:00 2001 From: vanguille Date: Wed, 8 Jan 2025 16:41:52 +0100 Subject: [PATCH 51/51] .net 8.0 --- .github/workflows/sonarcloud.yml | 10 +++++----- Directory.Build.props | 3 ++- .../KeyValuePush.Redis.Tests.csproj | 2 +- src/KeyValuePush.Tests/KeyValuePush.Tests.csproj | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 38cd0f7..1131072 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' - name: Install SonarScanner for .NET run: dotnet tool install --global dotnet-sonarscanner @@ -33,14 +33,14 @@ jobs: - name: Restore dependencies run: dotnet restore ./AutoGuru.KeyValuePush.sln - - name: Build solution - run: dotnet build ./AutoGuru.KeyValuePush.sln --no-restore --configuration Debug + - name: Build tests + run: dotnet build ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --configuration Debug --framework net8.0 - name: Run tests with coverage run: | - coverlet ./src/KeyValuePush.Tests/bin/Debug/net7.0/KeyValuePush.Tests.dll \ + coverlet ./src/KeyValuePush.Tests/bin/Debug/net8.0/KeyValuePush.Tests.dll \ --target "dotnet" \ - --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build --logger trx --results-directory ./TestResults/" \ + --targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build --framework net8.0 --logger trx --results-directory ./TestResults/" \ --output ./TestResults/Coverage/ \ --format opencover diff --git a/Directory.Build.props b/Directory.Build.props index 3567382..a8d2cf2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net7.0 + net6.0;net7.0;net8.0 false Ben McCallum, AutoGuru kv-push @@ -13,6 +13,7 @@ git true true + true enable diff --git a/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj b/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj index 0c7ba31..3356020 100644 --- a/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj +++ b/src/KeyValuePush.Redis.Tests/KeyValuePush.Redis.Tests.csproj @@ -1,6 +1,6 @@ - net7.0 + net8.0 false diff --git a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj index 1c8eaae..f52a5cb 100644 --- a/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj +++ b/src/KeyValuePush.Tests/KeyValuePush.Tests.csproj @@ -1,6 +1,6 @@ - net7.0 + net8.0 false