From cb0f5064bbdab797edb7b917920f89a34c772715 Mon Sep 17 00:00:00 2001 From: 0gis0 Date: Sun, 29 Dec 2024 00:16:10 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Update=20Dockerfile=20to=20use=20.NET=209.0?= =?UTF-8?q?=20and=20improve=20test=20coverage=20reporting=20in=20CI=20work?= =?UTF-8?q?flow=20=F0=9F=9B=A0=EF=B8=8F=20This=20commit=20message=20was=20?= =?UTF-8?q?generated=20by=20GitHub=20Copilot=20=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/Dockerfile | 2 +- .github/workflows/ci.yml | 6 +++--- tests/HeroControllerTests.cs | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1d820c2..eb3c55f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/devcontainers/dotnet:8.0 +FROM mcr.microsoft.com/devcontainers/dotnet:9.0 # Install SQL Tools: SQLPackage and sqlcmd COPY mssql/installSQLtools.sh installSQLtools.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b85257..2e5a924 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,14 +31,14 @@ jobs: - name: Install coverlet run: dotnet tool install --global coverlet.console - - name: Run tests with coverage - run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura + - name: Run tests with coverage + run: dotnet test --collect:"XPlat Code Coverage" - name: Upload coverage report uses: actions/upload-artifact@v3 with: name: coverage-report - path: src/coverage.cobertura.xml + path: tests/TestResults/**/coverage.cobertura.xml - name: Generate coverage summary run: | diff --git a/tests/HeroControllerTests.cs b/tests/HeroControllerTests.cs index b89db73..2a2cd4d 100644 --- a/tests/HeroControllerTests.cs +++ b/tests/HeroControllerTests.cs @@ -1,19 +1,20 @@ -using System.Collections.Generic; using Moq; -using Xunit; using tour_of_heroes_api.Controllers; using tour_of_heroes_api.Models; using Microsoft.AspNetCore.Mvc; public class HeroControllerTests { - private readonly Mock _mockRepo; + /// + /// Mock repository for the IHeroRepository interface used for testing purposes. + /// + private readonly Mock _mockHeroRepository; private readonly HeroController _controller; public HeroControllerTests() { - _mockRepo = new Mock(); - _controller = new HeroController(_mockRepo.Object); + _mockHeroRepository = new Mock(); + _controller = new HeroController(_mockHeroRepository.Object); } [Fact] @@ -25,7 +26,7 @@ public void GetHeroes_ReturnsOkResult_WithListOfHeroes() new Hero("Superman", "Clark Kent"), new Hero("Batman", "Bruce Wayne") }; - _mockRepo.Setup(repo => repo.GetAll()).Returns(heroes); + _mockHeroRepository.Setup(repo => repo.GetAll()).Returns(heroes); // Act var result = _controller.GetHeroes(); @@ -41,7 +42,7 @@ public void GetHero_ReturnsOkResult_WithHero() { // Arrange var hero = new Hero("Superman", "Clark Kent"); - _mockRepo.Setup(repo => repo.GetById(1)).Returns(hero); + _mockHeroRepository.Setup(repo => repo.GetById(1)).Returns(hero); // Act var result = _controller.GetHero(1); @@ -56,7 +57,7 @@ public void GetHero_ReturnsOkResult_WithHero() public void GetHero_ReturnsNotFoundResult_WhenHeroNotFound() { // Arrange - _mockRepo.Setup(repo => repo.GetById(1)).Returns((Hero)null); + _mockHeroRepository.Setup(repo => repo.GetById(1)).Returns((Hero)null); // Act var result = _controller.GetHero(1); @@ -85,7 +86,7 @@ public void PutHero_ReturnsNoContentResult_WhenHeroUpdated() { // Arrange var hero = new Hero("Superman", "Clark Kent"); - _mockRepo.Setup(repo => repo.GetById(1)).Returns(hero); + _mockHeroRepository.Setup(repo => repo.GetById(1)).Returns(hero); // Act var result = _controller.PutHero(1, new Hero("Batman", "Bruce Wayne")); @@ -98,7 +99,7 @@ public void PutHero_ReturnsNoContentResult_WhenHeroUpdated() public void PutHero_ReturnsNotFoundResult_WhenHeroNotFound() { // Arrange - _mockRepo.Setup(repo => repo.GetById(1)).Returns((Hero)null); + _mockHeroRepository.Setup(repo => repo.GetById(1)).Returns((Hero)null); // Act var result = _controller.PutHero(1, new Hero("Batman", "Bruce Wayne")); @@ -112,7 +113,7 @@ public void DeleteHero_ReturnsNoContentResult_WhenHeroDeleted() { // Arrange var hero = new Hero("Superman", "Clark Kent"); - _mockRepo.Setup(repo => repo.GetById(1)).Returns(hero); + _mockHeroRepository.Setup(repo => repo.GetById(1)).Returns(hero); // Act var result = _controller.DeleteHero(1); From dd67e93615d3289ec087d6988ee46e73355788cd Mon Sep 17 00:00:00 2001 From: 0gis0 Date: Sun, 29 Dec 2024 00:17:44 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Update=20CI=20workflow=20to=20include=20cov?= =?UTF-8?q?erage=20report=20from=20test=20results=20=F0=9F=93=8A=20This=20?= =?UTF-8?q?commit=20message=20was=20generated=20by=20GitHub=20Copilot=20?= =?UTF-8?q?=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e5a924..5e758c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,5 +44,5 @@ jobs: run: | echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - cat src/coverage.cobertura.xml >> $GITHUB_STEP_SUMMARY + cat tests/TestResults/**/coverage.cobertura.xml >> $GITHUB_STEP_SUMMARY echo "\`\`\`" >> $GITHUB_STEP_SUMMARY \ No newline at end of file