From 36d2985cd8b50a606ae8cedc87d7746ca0343813 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Tue, 9 Dec 2025 18:03:26 +0000 Subject: [PATCH 01/21] Change .Net version --- BPCalculator/BPCalculator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BPCalculator/BPCalculator.csproj b/BPCalculator/BPCalculator.csproj index 3cd1336..5e4881f 100644 --- a/BPCalculator/BPCalculator.csproj +++ b/BPCalculator/BPCalculator.csproj @@ -1,7 +1,7 @@ - net9.0 + net8.0 From 5631e8b4ad9e0552195ed0797a4ecda9346f2371 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Tue, 9 Dec 2025 18:11:59 +0000 Subject: [PATCH 02/21] Updated the git ignore file --- .gitignore | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/.gitignore b/.gitignore index 3c4efe2..a7d4e90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,53 @@ +# Build outputs +bin/ +obj/ + +# User-specific files +.vs/ +.vscode/ +.idea/ +*.user +*.swp +*.swo + +# OS files +.DS_Store +Thumbs.db + +# NuGet +*.nupkg +*.snupkg +**/packages/** +*.nuget.props +*.nuget.targets + +# Logs +*.log +logs/ + +# Tooling caches +.dotnet/ +.templateengine/ + +# Test results & coverage +TestResults/ +coverage/ + +# Generated files +*.generated.cs +*.g.cs +*.g.i.cs + +# Publish output +wwwroot/lib/ + +# Rider / JetBrains +.fleet/ +.idea/ +.ionide/ + +# Azure functions local settings +local.settings.json ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. From 4ac89e81320389dbd803a6e5e65040b4b54d5e73 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Tue, 9 Dec 2025 18:27:22 +0000 Subject: [PATCH 03/21] Add blood pressure category logic and unit tests --- BPCalculator.sln | 6 +++++ BPCalculator/BloodPressure.cs | 19 ++++++++++--- .../BPCalculator.Tests.csproj | 27 +++++++++++++++++++ .../BloodPressureCategoryTests.cs | 21 +++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/BPCalculator.Tests/BPCalculator.Tests.csproj create mode 100644 tests/BPCalculator.Tests/BloodPressureCategoryTests.cs diff --git a/BPCalculator.sln b/BPCalculator.sln index 652d73a..050f486 100644 --- a/BPCalculator.sln +++ b/BPCalculator.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30002.166 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPCalculator", "BPCalculator\BPCalculator.csproj", "{5966DA6C-819D-4303-ADC7-425B8541EC84}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPCalculator.Tests", "tests\BPCalculator.Tests\BPCalculator.Tests.csproj", "{A74C6C1D-7E2B-4A9A-B2F6-022F8D4AB9AF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {5966DA6C-819D-4303-ADC7-425B8541EC84}.Debug|Any CPU.Build.0 = Debug|Any CPU {5966DA6C-819D-4303-ADC7-425B8541EC84}.Release|Any CPU.ActiveCfg = Release|Any CPU {5966DA6C-819D-4303-ADC7-425B8541EC84}.Release|Any CPU.Build.0 = Release|Any CPU + {A74C6C1D-7E2B-4A9A-B2F6-022F8D4AB9AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A74C6C1D-7E2B-4A9A-B2F6-022F8D4AB9AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A74C6C1D-7E2B-4A9A-B2F6-022F8D4AB9AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A74C6C1D-7E2B-4A9A-B2F6-022F8D4AB9AF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BPCalculator/BloodPressure.cs b/BPCalculator/BloodPressure.cs index 3e8fee9..ebebdfb 100644 --- a/BPCalculator/BloodPressure.cs +++ b/BPCalculator/BloodPressure.cs @@ -31,9 +31,22 @@ public BPCategory Category { get { - // implement as part of project - //throw new NotImplementedException("not implemented yet"); - return new BPCategory(); // replace this + if (Systolic >= 140 || Diastolic >= 90) + { + return BPCategory.High; + } + + if (Systolic >= 120 || Diastolic >= 80) + { + return BPCategory.PreHigh; + } + + if (Systolic >= 90 && Diastolic >= 60) + { + return BPCategory.Ideal; + } + + return BPCategory.Low; } } } diff --git a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj new file mode 100644 index 0000000..2f21f70 --- /dev/null +++ b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + enable + enable + false + true + + + + + + + + + + + + + + + + + + + diff --git a/tests/BPCalculator.Tests/BloodPressureCategoryTests.cs b/tests/BPCalculator.Tests/BloodPressureCategoryTests.cs new file mode 100644 index 0000000..4f55c36 --- /dev/null +++ b/tests/BPCalculator.Tests/BloodPressureCategoryTests.cs @@ -0,0 +1,21 @@ +using BPCalculator; + +namespace BPCalculator.Tests; + +public class BloodPressureCategoryTests +{ + [Theory] + [InlineData(140, 60, BPCategory.High)] + [InlineData(120, 90, BPCategory.High)] + [InlineData(139, 89, BPCategory.PreHigh)] + [InlineData(120, 79, BPCategory.PreHigh)] + [InlineData(119, 79, BPCategory.Ideal)] + [InlineData(90, 60, BPCategory.Ideal)] + [InlineData(89, 59, BPCategory.Low)] + public void Category_Computes_As_Expected(int sys, int dia, BPCategory expected) + { + var bp = new BloodPressure { Systolic = sys, Diastolic = dia }; + Assert.Equal(expected, bp.Category); + } +} + From 648cdb3981e77efd3fce953cfc00c1f488ae2bc4 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Tue, 9 Dec 2025 18:34:54 +0000 Subject: [PATCH 04/21] Add telemetry tracking for BP calculations --- BPCalculator/Pages/Index.cshtml.cs | 13 +++++++ BPCalculator/Services/TelemetryService.cs | 39 +++++++++++++++++++ BPCalculator/Startup.cs | 2 + .../TelemetryServiceTests.cs | 30 ++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 BPCalculator/Services/TelemetryService.cs create mode 100644 tests/BPCalculator.Tests/TelemetryServiceTests.cs diff --git a/BPCalculator/Pages/Index.cshtml.cs b/BPCalculator/Pages/Index.cshtml.cs index f96dc16..a9bd325 100644 --- a/BPCalculator/Pages/Index.cshtml.cs +++ b/BPCalculator/Pages/Index.cshtml.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using BPCalculator.Services; // page model @@ -7,6 +8,13 @@ namespace BPCalculator.Pages { public class BloodPressureModel : PageModel { + private readonly ITelemetryService _telemetry; + + public BloodPressureModel(ITelemetryService telemetry) + { + _telemetry = telemetry; + } + [BindProperty] // bound on POST public BloodPressure BP { get; set; } @@ -24,6 +32,11 @@ public IActionResult OnPost() { ModelState.AddModelError("", "Systolic must be greater than Diastolic"); } + + if (ModelState.IsValid) + { + _telemetry.TrackCalculation(BP); + } return Page(); } } diff --git a/BPCalculator/Services/TelemetryService.cs b/BPCalculator/Services/TelemetryService.cs new file mode 100644 index 0000000..0d02370 --- /dev/null +++ b/BPCalculator/Services/TelemetryService.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using Microsoft.Extensions.Logging; + +namespace BPCalculator.Services +{ + public interface ITelemetryService + { + void TrackCalculation(BloodPressure reading); + } + + public sealed class TelemetryService : ITelemetryService + { + private static readonly ActivitySource ActivitySource = new("BPCalculator.Telemetry"); + private readonly ILogger _logger; + + public TelemetryService(ILogger logger) + { + _logger = logger; + } + + public void TrackCalculation(BloodPressure reading) + { + if (reading == null) + { + return; + } + + var category = reading.Category; + + using var activity = ActivitySource.StartActivity("BloodPressureCalculation"); + activity?.SetTag("bp.systolic", reading.Systolic); + activity?.SetTag("bp.diastolic", reading.Diastolic); + activity?.SetTag("bp.category", category.ToString()); + + _logger.LogInformation("Telemetry: {Systolic}/{Diastolic} => {Category}", reading.Systolic, reading.Diastolic, category); + } + } +} + diff --git a/BPCalculator/Startup.cs b/BPCalculator/Startup.cs index 14ab241..2f52a86 100644 --- a/BPCalculator/Startup.cs +++ b/BPCalculator/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using BPCalculator.Services; namespace BPCalculator { @@ -22,6 +23,7 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddSingleton(); services.AddRazorPages(); } diff --git a/tests/BPCalculator.Tests/TelemetryServiceTests.cs b/tests/BPCalculator.Tests/TelemetryServiceTests.cs new file mode 100644 index 0000000..dfd04fd --- /dev/null +++ b/tests/BPCalculator.Tests/TelemetryServiceTests.cs @@ -0,0 +1,30 @@ +using BPCalculator; +using BPCalculator.Services; +using Microsoft.Extensions.Logging; + +namespace BPCalculator.Tests; + +public class TelemetryServiceTests +{ + private static ILogger CreateLogger() => + LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Information)) + .CreateLogger(); + + [Fact] + public void TrackCalculation_Ignores_Null() + { + var telemetry = new TelemetryService(CreateLogger()); + + telemetry.TrackCalculation(null); + } + + [Fact] + public void TrackCalculation_Works_For_Valid_Reading() + { + var telemetry = new TelemetryService(CreateLogger()); + var reading = new BloodPressure { Systolic = 120, Diastolic = 80 }; + + telemetry.TrackCalculation(reading); + } +} + From 9c4f5a99a4df186186ac4f3169d12cab8601f017 Mon Sep 17 00:00:00 2001 From: Ubaid Ali <73285333+ubaidali247@users.noreply.github.com> Date: Thu, 11 Dec 2025 00:53:25 +0000 Subject: [PATCH 05/21] Create ci-sonarcloud.yml Created Sonarqube --- .github/workflows/ci-sonarcloud.yml | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/ci-sonarcloud.yml diff --git a/.github/workflows/ci-sonarcloud.yml b/.github/workflows/ci-sonarcloud.yml new file mode 100644 index 0000000..e5a4675 --- /dev/null +++ b/.github/workflows/ci-sonarcloud.yml @@ -0,0 +1,57 @@ +name: CI - Build, Test, SonarCloud + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + +jobs: + build-and-analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # REQUIRED for SonarCloud + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "9.0.x" + + - name: Restore dependencies + run: dotnet restore + + - name: Install SonarScanner + run: | + dotnet tool install --global dotnet-sonarscanner --version 5.14.0 || true + echo "$HOME/.dotnet/tools" >> $GITHUB_PATH + + - name: SonarCloud - Begin Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet sonarscanner begin \ + /k:"ubaidali247_bp" \ + /o:"ubaidali247" \ + /d:sonar.login="${SONAR_TOKEN}" \ + /d:sonar.host.url="https://sonarcloud.io" \ + /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + + - name: Build + run: dotnet build --configuration Release --no-restore + + - name: Test and Generate Coverage + run: | + dotnet test --no-build --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=./coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover + + - name: SonarCloud - End Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" From 9853489bbde5e270b8c8de38fbbba4d7e1fd76e7 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 01:19:21 +0000 Subject: [PATCH 06/21] Add SonarCloud CI workflow --- .github/workflows/sonarcloud.yml | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 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..cac2e20 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,57 @@ +name: CI - Build, Test, SonarCloud + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ master, develop ] + +jobs: + build-and-analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "9.0.x" + + - name: Restore dependencies + run: dotnet restore + + - name: Install SonarScanner + run: | + dotnet tool install --global dotnet-sonarscanner --version 5.14.0 || true + echo "$HOME/.dotnet/tools" >> $GITHUB_PATH + + - name: SonarCloud - Begin Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet sonarscanner begin \ + /k:"ubaidali247_bp" \ + /o:"ubaidali247" \ + /d:sonar.login="${SONAR_TOKEN}" \ + /d:sonar.host.url="https://sonarcloud.io" \ + /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + + - name: Build + run: dotnet build --configuration Release --no-restore + + - name: Test and Generate Coverage + run: | + dotnet test --no-build --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=./coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover + + - name: SonarCloud - End Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" From ffc77014a8f7e8729395ad5e7f40a8e7d2d8a6d0 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 01:42:53 +0000 Subject: [PATCH 07/21] Fix test path to use .csproj --- .github/workflows/sonarcloud.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index cac2e20..bb5df3a 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -44,11 +44,13 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test and Generate Coverage - run: | - dotnet test --no-build --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=./coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover + run: | + dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ + --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=./coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover + - name: SonarCloud - End Analysis env: From 850b6d9d073b340e3afc37bd024d16ef1ecd18d4 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 02:11:20 +0000 Subject: [PATCH 08/21] Fix test path for .NET 9 and generate coverage --- tests/BPCalculator.Tests/BPCalculator.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj index 2f21f70..956b0bb 100644 --- a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj +++ b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable false From 32326e3307e022cb36dccf4f9629623a87359caf Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 12:25:18 +0000 Subject: [PATCH 09/21] Update branch names in SonarCloud workflow and simplify test command --- .github/workflows/sonarcloud.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index bb5df3a..529f705 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -2,9 +2,9 @@ name: CI - Build, Test, SonarCloud on: push: - branches: [ master, develop ] + branches: [ main, develop ] pull_request: - branches: [ master, develop ] + branches: [ main, develop ] jobs: build-and-analyze: @@ -14,7 +14,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 # Required for SonarCloud - name: Setup .NET uses: actions/setup-dotnet@v3 @@ -44,16 +44,9 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test and Generate Coverage - run: | - dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ - --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=./coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover - + run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=coverage.opencover.xml /p:CoverletOutputFormat=opencover - name: SonarCloud - End Analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" + run: dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" From 214c913165a4c53323eb0109ff9da4bf3b2ada3c Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 12:39:20 +0000 Subject: [PATCH 10/21] fixed version issue --- BPCalculator/BPCalculator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BPCalculator/BPCalculator.csproj b/BPCalculator/BPCalculator.csproj index 5e4881f..3cd1336 100644 --- a/BPCalculator/BPCalculator.csproj +++ b/BPCalculator/BPCalculator.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 From dbdcf959a0ef4a1b0b5cdd31ff350ec3987e46e6 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 12:51:02 +0000 Subject: [PATCH 11/21] Removed duplication --- .github/workflows/ci-sonarcloud.yml | 57 ----------------------------- 1 file changed, 57 deletions(-) delete mode 100644 .github/workflows/ci-sonarcloud.yml diff --git a/.github/workflows/ci-sonarcloud.yml b/.github/workflows/ci-sonarcloud.yml deleted file mode 100644 index e5a4675..0000000 --- a/.github/workflows/ci-sonarcloud.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: CI - Build, Test, SonarCloud - -on: - push: - branches: [ main, develop ] - pull_request: - branches: [ main, develop ] - -jobs: - build-and-analyze: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # REQUIRED for SonarCloud - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: "9.0.x" - - - name: Restore dependencies - run: dotnet restore - - - name: Install SonarScanner - run: | - dotnet tool install --global dotnet-sonarscanner --version 5.14.0 || true - echo "$HOME/.dotnet/tools" >> $GITHUB_PATH - - - name: SonarCloud - Begin Analysis - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - dotnet sonarscanner begin \ - /k:"ubaidali247_bp" \ - /o:"ubaidali247" \ - /d:sonar.login="${SONAR_TOKEN}" \ - /d:sonar.host.url="https://sonarcloud.io" \ - /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" - - - name: Build - run: dotnet build --configuration Release --no-restore - - - name: Test and Generate Coverage - run: | - dotnet test --no-build --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=./coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover - - - name: SonarCloud - End Analysis - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" From beed7aaf2dac2a0679cf67ea1046fcfdaefc5027 Mon Sep 17 00:00:00 2001 From: Ubaid Date: Thu, 11 Dec 2025 13:22:22 +0000 Subject: [PATCH 12/21] Fix SonarCloud workflow: update test path and .NET version --- .github/workflows/sonarcloud.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 529f705..a57f020 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -14,7 +14,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 # Required for SonarCloud + fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v3 @@ -40,11 +40,18 @@ jobs: /d:sonar.host.url="https://sonarcloud.io" \ /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + - name: Clean + run: dotnet clean + - name: Build run: dotnet build --configuration Release --no-restore - name: Test and Generate Coverage - run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=coverage.opencover.xml /p:CoverletOutputFormat=opencover + run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ + --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover - name: SonarCloud - End Analysis env: From af32be665714fc5db915cd80a574676a8a21a55c Mon Sep 17 00:00:00 2001 From: Ubaid Ali <73285333+ubaidali247@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:10:36 +0000 Subject: [PATCH 13/21] Correct step name for test and coverage generation Fix typo in step name for testing and coverage generation. --- .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 a57f020..a8b3a73 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -46,7 +46,7 @@ jobs: - name: Build run: dotnet build --configuration Release --no-restore - - name: Test and Generate Coverage + - name: Test and Generate Coveragee run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ --verbosity normal \ /p:CollectCoverage=true \ From 244fc4831af26ed7944c551cf464cdcb9090e154 Mon Sep 17 00:00:00 2001 From: Ubaid Ali <73285333+ubaidali247@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:14:29 +0000 Subject: [PATCH 14/21] Add CI workflow for build, test, and SonarCloud analysis --- .github/workflows/main.yml | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a8b3a73 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,59 @@ +name: CI - Build, Test, SonarCloud + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + +jobs: + build-and-analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "9.0.x" + + - name: Restore dependencies + run: dotnet restore + + - name: Install SonarScanner + run: | + dotnet tool install --global dotnet-sonarscanner --version 5.14.0 || true + echo "$HOME/.dotnet/tools" >> $GITHUB_PATH + + - name: SonarCloud - Begin Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + dotnet sonarscanner begin \ + /k:"ubaidali247_bp" \ + /o:"ubaidali247" \ + /d:sonar.login="${SONAR_TOKEN}" \ + /d:sonar.host.url="https://sonarcloud.io" \ + /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + + - name: Clean + run: dotnet clean + + - name: Build + run: dotnet build --configuration Release --no-restore + + - name: Test and Generate Coveragee + run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ + --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover + + - name: SonarCloud - End Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" From 665d2161dc63b31f3e679b3035da3c556fa5ed9c Mon Sep 17 00:00:00 2001 From: Ubaid Ali <73285333+ubaidali247@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:18:56 +0000 Subject: [PATCH 15/21] Update CI workflow to trigger on feature branch --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8b3a73..b358c85 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,9 @@ name: CI - Build, Test, SonarCloud on: push: - branches: [ main, develop ] + branches: [ feature/sonarcloud-integration ] pull_request: - branches: [ main, develop ] + branches: [ feature/sonarcloud-integration ] jobs: build-and-analyze: From ee8e8bfd617604a6f0b9587760570c501d919f68 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:24:26 +0000 Subject: [PATCH 16/21] handle backslashes with spaces --- .github/workflows/sonarcloud.yml | 13 +++++++------ tests/BPCalculator.Tests/BPCalculator.Tests.csproj | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a8b3a73..f88ca31 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -46,12 +46,13 @@ jobs: - name: Build run: dotnet build --configuration Release --no-restore - - name: Test and Generate Coveragee - run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ - --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover + - name: Test and Generate Coverage + run: | + dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ + --verbosity normal \ + /p:CollectCoverage=true \ + /p:CoverletOutput=coverage.opencover.xml \ + /p:CoverletOutputFormat=opencover - name: SonarCloud - End Analysis env: diff --git a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj index 956b0bb..164ad4a 100644 --- a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj +++ b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj @@ -10,6 +10,7 @@ + From c39c60474fdc7614a2e30a3c11d6767d5df8fbd6 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:26:38 +0000 Subject: [PATCH 17/21] minor fix --- .github/workflows/sonarcloud.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index f88ca31..ba6cf86 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -47,12 +47,7 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test and Generate Coverage - run: | - dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ - --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover + run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=coverage.opencover.xml /p:CoverletOutputFormat=opencover - name: SonarCloud - End Analysis env: From fe8120e4881583bf33a2f658968b5632c98f123d Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:32:23 +0000 Subject: [PATCH 18/21] Change .net version --- BPCalculator/BPCalculator.csproj | 2 +- .../BPCalculator.Tests.csproj | 2 +- .../BPCalculator.Tests/coverage.opencover.xml | 550 ++++++++++++++++++ 3 files changed, 552 insertions(+), 2 deletions(-) create mode 100644 tests/BPCalculator.Tests/coverage.opencover.xml diff --git a/BPCalculator/BPCalculator.csproj b/BPCalculator/BPCalculator.csproj index 3cd1336..5e4881f 100644 --- a/BPCalculator/BPCalculator.csproj +++ b/BPCalculator/BPCalculator.csproj @@ -1,7 +1,7 @@ - net9.0 + net8.0 diff --git a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj index 164ad4a..7c4ce8f 100644 --- a/tests/BPCalculator.Tests/BPCalculator.Tests.csproj +++ b/tests/BPCalculator.Tests/BPCalculator.Tests.csproj @@ -1,7 +1,7 @@ - net9.0 + net8.0 enable enable false diff --git a/tests/BPCalculator.Tests/coverage.opencover.xml b/tests/BPCalculator.Tests/coverage.opencover.xml new file mode 100644 index 0000000..b36c4bf --- /dev/null +++ b/tests/BPCalculator.Tests/coverage.opencover.xml @@ -0,0 +1,550 @@ + + + + + + BPCalculator.dll + 2025-12-11T02:31:59 + BPCalculator + + + + + + + + + + + + + + + + + BPCalculator.BloodPressure + + + + + System.Int32 BPCalculator.BloodPressure::get_Systolic() + + + + + + + + + + + System.Int32 BPCalculator.BloodPressure::get_Diastolic() + + + + + + + + + + + BPCalculator.BPCategory BPCalculator.BloodPressure::get_Category() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BPCalculator.Program + + + + + System.Void BPCalculator.Program::Main(System.String[]) + + + + + + + + + + + + + Microsoft.Extensions.Hosting.IHostBuilder BPCalculator.Program::CreateHostBuilder(System.String[]) + + + + + + + + + + + + + + + + BPCalculator.Startup + + + + + Microsoft.Extensions.Configuration.IConfiguration BPCalculator.Startup::get_Configuration() + + + + + + + + + + + System.Void BPCalculator.Startup::ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection) + + + + + + + + + + + + + + System.Void BPCalculator.Startup::Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder,Microsoft.AspNetCore.Hosting.IWebHostEnvironment) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + System.Void BPCalculator.Startup::.ctor(Microsoft.Extensions.Configuration.IConfiguration) + + + + + + + + + + + + + + + BPCalculator.Services.TelemetryService + + + + + System.Void BPCalculator.Services.TelemetryService::TrackCalculation(BPCalculator.BloodPressure) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + System.Void BPCalculator.Services.TelemetryService::.ctor(Microsoft.Extensions.Logging.ILogger`1<BPCalculator.Services.TelemetryService>) + + + + + + + + + + + + + + System.Void BPCalculator.Services.TelemetryService::.cctor() + + + + + + + + + + + + BPCalculator.Pages.ErrorModel + + + + + System.String BPCalculator.Pages.ErrorModel::get_RequestId() + + + + + + + + + + + System.Boolean BPCalculator.Pages.ErrorModel::get_ShowRequestId() + + + + + + + + + + + System.Void BPCalculator.Pages.ErrorModel::OnGet() + + + + + + + + + + + + + + + + + + System.Void BPCalculator.Pages.ErrorModel::.ctor(Microsoft.Extensions.Logging.ILogger`1<BPCalculator.Pages.ErrorModel>) + + + + + + + + + + + + + + + BPCalculator.Pages.BloodPressureModel + + + + + BPCalculator.BloodPressure BPCalculator.Pages.BloodPressureModel::get_BP() + + + + + + + + + + + System.Void BPCalculator.Pages.BloodPressureModel::OnGet() + + + + + + + + + + + + + Microsoft.AspNetCore.Mvc.IActionResult BPCalculator.Pages.BloodPressureModel::OnPost() + + + + + + + + + + + + + + + + + + + + + + + + + + System.Void BPCalculator.Pages.BloodPressureModel::.ctor(BPCalculator.Services.ITelemetryService) + + + + + + + + + + + + + + + BPCalculator.Pages.PrivacyModel + + + + + System.Void BPCalculator.Pages.PrivacyModel::OnGet() + + + + + + + + + + + + System.Void BPCalculator.Pages.PrivacyModel::.ctor(Microsoft.Extensions.Logging.ILogger`1<BPCalculator.Pages.PrivacyModel>) + + + + + + + + + + + + + + + BPCalculator.Pages.Pages_Error/<ExecuteAsync>d__0 + + + + + System.Void BPCalculator.Pages.Pages_Error/<ExecuteAsync>d__0::MoveNext() + + + + + + + + + + + + + + + + + + BPCalculator.Pages.Pages_Index/<<ExecuteAsync>b__17_0>d + + + + + System.Void BPCalculator.Pages.Pages_Index/<<ExecuteAsync>b__17_0>d::MoveNext() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BPCalculator.Pages.Pages_Index/<<ExecuteAsync>b__17_1>d + + + + + System.Void BPCalculator.Pages.Pages_Index/<<ExecuteAsync>b__17_1>d::MoveNext() + + + + + + + + + + + + BPCalculator.Pages.Pages_Index/<ExecuteAsync>d__17 + + + + + System.Void BPCalculator.Pages.Pages_Index/<ExecuteAsync>d__17::MoveNext() + + + + + + + + + + + + + + + BPCalculator.Pages.Pages_Privacy/<ExecuteAsync>d__0 + + + + + System.Void BPCalculator.Pages.Pages_Privacy/<ExecuteAsync>d__0::MoveNext() + + + + + + + + + + + + BPCalculator.Pages.Pages__ViewStart/<ExecuteAsync>d__0 + + + + + System.Void BPCalculator.Pages.Pages__ViewStart/<ExecuteAsync>d__0::MoveNext() + + + + + + + + + + + + + \ No newline at end of file From 499c993c91f8852d46e8c54224bfaa1d4037671d Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:36:30 +0000 Subject: [PATCH 19/21] Update .NET SDK version to 8.0.x to match project target framework --- .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 ba6cf86..2bf584c 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: "9.0.x" + dotnet-version: "8.0.x" - name: Restore dependencies run: dotnet restore From 448e6f0778279dd55aed6422cd4e85bd26daf410 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:41:31 +0000 Subject: [PATCH 20/21] main.yml file --- .github/workflows/main.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b358c85..adffe9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: "9.0.x" + dotnet-version: "8.0.x" - name: Restore dependencies run: dotnet restore @@ -46,12 +46,8 @@ jobs: - name: Build run: dotnet build --configuration Release --no-restore - - name: Test and Generate Coveragee - run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj \ - --verbosity normal \ - /p:CollectCoverage=true \ - /p:CoverletOutput=coverage.opencover.xml \ - /p:CoverletOutputFormat=opencover + - name: Test and Generate Coverage + run: dotnet test tests/BPCalculator.Tests/BPCalculator.Tests.csproj --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=coverage.opencover.xml /p:CoverletOutputFormat=opencover - name: SonarCloud - End Analysis env: From 63544c64eed2bb3a9d12d0b0c405ddedfb193466 Mon Sep 17 00:00:00 2001 From: Ubaid Ali Date: Thu, 11 Dec 2025 14:53:43 +0000 Subject: [PATCH 21/21] Add Master branch --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index adffe9d..f394285 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,9 @@ name: CI - Build, Test, SonarCloud on: push: - branches: [ feature/sonarcloud-integration ] + branches: [ feature/sonarcloud-integration, master ] pull_request: - branches: [ feature/sonarcloud-integration ] + branches: [ feature/sonarcloud-integration, master ] jobs: build-and-analyze: