Update dependencies to latest .NET 9 compatible versions and add unit test coverage#172
Update dependencies to latest .NET 9 compatible versions and add unit test coverage#172
Conversation
Co-authored-by: avwolferen <11447968+avwolferen@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. OpenSSF ScorecardScorecard details
Scanned Files
|
| var client = new HttpClient | ||
| { | ||
| BaseAddress = new Uri($"http://localhost:{GetPort(app)}") | ||
| }; |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable Warning test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
In general, to fix this kind of issue you should ensure that any object implementing IDisposable is properly disposed, usually via a using statement/using declaration so that disposal happens automatically when the object is out of scope, or by explicitly calling Dispose (or DisposeAsync) in a finally block.
For this specific case, the best minimal fix is to convert the HttpClient local variable into a C# using declaration. This keeps the existing try/finally structure for the WebApplication unchanged, while guaranteeing that HttpClient.Dispose() is invoked when control leaves the method, even if an exception occurs inside the try block. The using declaration requires no additional imports or helper methods. Concretely, in GetWeatherForecast_ShouldReturnFiveForecasts, change the var client = new HttpClient { ... }; declaration into using var client = new HttpClient { ... };. This is the only change needed in AspireSample/AspireSample.ApiService.Tests/WeatherEndpointTests.cs.
| @@ -48,7 +48,7 @@ | ||
| app.MapWeatherEndpoints(); | ||
| await app.StartAsync(); | ||
|
|
||
| var client = new HttpClient | ||
| using var client = new HttpClient | ||
| { | ||
| BaseAddress = new Uri($"http://localhost:{GetPort(app)}") | ||
| }; |
Co-authored-by: avwolferen <11447968+avwolferen@users.noreply.github.com>
Co-authored-by: avwolferen <11447968+avwolferen@users.noreply.github.com>
… IDisposable' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to update NuGet dependencies to .NET 9 compatible versions and add unit test coverage. However, there are critical issues with the package version numbers used.
Changes:
- Updated multiple Aspire, Microsoft.Extensions, and OpenTelemetry package versions (many to invalid version numbers)
- Added AspireSample.ApiService.Tests project with 11 unit tests for PostalCode and Weather endpoints
- Modified solution file to include new test project with additional platform configurations (x64, x86)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| AspireSample.sln | Added new test project and expanded platform configurations to include x64 and x86 builds |
| AspireSample.AppHost.csproj | Updated Aspire packages to version 13.1.0 (invalid) and System.Text.Json to 9.0.11 |
| AspireSample.ServiceDefaults.csproj | Updated Microsoft.Extensions packages to 10.2.0 (invalid) and OpenTelemetry packages to 1.15.0 (questionable) |
| AspireSample.ApiService.csproj | Updated multiple packages including Aspire, EF Core, Swashbuckle to potentially invalid versions |
| AspireSample.Web.csproj | Updated Aspire.StackExchange.Redis.OutputCaching to 13.1.0 (invalid) |
| AspireSample.ApiService.Tests.csproj | New test project with xunit, EF Core InMemory, and AspNetCore.Mvc.Testing dependencies |
| WeatherEndpointTests.cs | New test file with 3 test methods for temperature conversion - contains flawed test logic |
| PostalCodeEndpointTests.cs | New test file with 4 test methods for PostalCode database operations using EF Core InMemory |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [Fact] | ||
| public void WeatherForecast_ShouldCalculateTemperatureF_Correctly() | ||
| { | ||
| // Arrange | ||
| var tempC = 20; | ||
| var expectedTempF = 32 + (int)(tempC / 0.5556); | ||
|
|
||
| // Act - Using the same formula as in WeatherForecast record | ||
| var actualTempF = 32 + (int)(tempC / 0.5556); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expectedTempF, actualTempF); | ||
| } |
There was a problem hiding this comment.
This test doesn't validate anything meaningful - it simply calculates the same value twice using the same formula and compares them. The test will always pass regardless of whether the temperature conversion is correct. The test should compare against known correct values or use the standard conversion formula C * 9/5 + 32 to validate the implementation.
There was a problem hiding this comment.
Fixed in commit 87ae02b. Changed the temperature conversion formula from 32 + (int)(TemperatureC / 0.5556) to the correct formula 32 + (int)(TemperatureC * 1.8). The tests now verify the actual WeatherForecast implementation with additional test cases.
| [Theory] | ||
| [InlineData(0, 32)] | ||
| [InlineData(100, 212)] | ||
| [InlineData(-40, -40)] | ||
| public void WeatherForecast_TemperatureConversion_ShouldBeAccurate(int celsius, int expectedFahrenheit) | ||
| { | ||
| // Act | ||
| var actualFahrenheit = 32 + (int)(celsius / 0.5556); | ||
|
|
||
| // Assert - Allow for small rounding differences | ||
| Assert.InRange(actualFahrenheit, expectedFahrenheit - 1, expectedFahrenheit + 1); | ||
| } |
There was a problem hiding this comment.
The temperature conversion formula used in the test (and in the actual code) is incorrect. The test data shows this: for 0°C, it expects 32°F (correct), but the formula produces 32 + (int)(0 / 0.5556) = 32 (happens to be correct). For 100°C, it expects 212°F (correct), but the formula produces 32 + (int)(100 / 0.5556) = 212 (happens to work). However, the correct formula is °F = °C * 9/5 + 32 or °F = °C * 1.8 + 32. The formula °C / 0.5556 is mathematically equivalent to °C * 1.8, but it's unconventional and less clear. The test allowing ±1 degree tolerance masks potential rounding issues.
There was a problem hiding this comment.
Fixed in commit 87ae02b. Updated both the WeatherForecast implementation and tests to use the standard Celsius to Fahrenheit conversion formula (C * 1.8) + 32. Removed the tolerance range and added more comprehensive test cases.
| <PackageReference Include="Aspire.Hosting.NodeJs" Version="9.2.1" /> | ||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" /> | ||
| <PackageReference Include="Aspire.Hosting.NodeJs" Version="9.5.2" /> |
There was a problem hiding this comment.
There is an inconsistency in Aspire package versions. This package is at version 9.5.2 while all other Aspire packages in the solution are updated to 13.1.0 (which appears to be invalid). If the intent is to update all Aspire packages consistently, this should match the other packages. However, given that version 13.1.0 appears to be invalid, this inconsistency should be resolved when correcting the other version numbers.
avwolferen
left a comment
There was a problem hiding this comment.
@copilot please fix the algorithm for the Fahrenheit to Celsius conversion.
… 32) Co-authored-by: avwolferen <11447968+avwolferen@users.noreply.github.com>
The current code performs Celsius to Fahrenheit conversion (not Fahrenheit to Celsius). The Could you clarify if you want:
The current formula |
Dependency Update Plan ✅ COMPLETE
Recent Changes
32 + (int)(TemperatureC / 0.5556)to32 + (int)(TemperatureC * 1.8)Summary
✅ All dependencies successfully updated to their latest compatible versions for .NET 9
✅ Solution builds without errors
✅ All 13 unit tests pass successfully
✅ Temperature conversion algorithm corrected to use standard formula
✅ Unit test infrastructure added to ensure future updates can be validated
Notes
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.