-
Notifications
You must be signed in to change notification settings - Fork 0
Add Unit Tests for Mock Logger and Options Classes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ClientBuilder Co-authored-by: Genie <genie@cosine.sh>
WalkthroughA new test project for the StoneAge.TestUtils library has been established, including multiple test classes to validate core utility components such as logging, options snapshots, and HTTP client behaviors. The solution and project files were updated to incorporate this test project and ensure compatibility with .NET 6.0 and xUnit. Changes
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
StoneAge.TestUtils.Tests/MockLoggerTests.cs(1 hunks)StoneAge.TestUtils.Tests/MockOptionsSnapshotTests.cs(1 hunks)StoneAge.TestUtils.Tests/MockOptionsTests.cs(1 hunks)StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj(1 hunks)StoneAge.TestUtils.Tests/TestHttpClientBuilderTests.cs(1 hunks)StoneAge.TestUtils.Tests/TestHttpMessageHandlerTests.cs(1 hunks)TestUtils.sln(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
StoneAge.TestUtils.Tests/MockLoggerTests.cs (1)
TestUtils/MockLogger.cs (2)
Log(17-29)IsEnabled(36-39)
🔇 Additional comments (13)
TestUtils.sln (1)
6-8: LGTM! Test project integration looks correct.The new test project has been properly added to the solution with appropriate GUID and project reference structure.
StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj (1)
1-18: LGTM! Standard test project configuration.The project file follows .NET testing conventions correctly with appropriate target framework, test dependencies, and project references.
StoneAge.TestUtils.Tests/MockOptionsTests.cs (1)
1-23: LGTM! Well-structured unit test.The test follows excellent practices:
- Clear, descriptive test method name
- Simple test data setup with nested Settings class
- Comprehensive assertions testing both property value and reference equality
- Proper use of xUnit assertions
StoneAge.TestUtils.Tests/MockOptionsSnapshotTests.cs (1)
1-33: LGTM! Comprehensive test coverage.Excellent test implementation that covers both positive and negative scenarios:
- Tests the
Valueproperty returns the correct injected instance- Verifies the
Getmethod throwsNotImplementedExceptionas expected- Uses descriptive test method names and clear assertions
- Proper use of xUnit testing patterns
StoneAge.TestUtils.Tests/MockLoggerTests.cs (4)
11-18: LGTM! Well-structured test for basic logging functionality.The test correctly verifies that log entries are added to the appropriate log level collection. The use of a lambda formatter
(s, e) => sis appropriate for testing purposes.
20-26: LGTM! Good coverage of the IsEnabled behavior.The test correctly verifies that the MockLogger always returns true for IsEnabled, testing multiple log levels to ensure consistency with the implementation shown in the relevant code snippets.
28-37: LGTM! Comprehensive test for entry retrieval functionality.The test properly verifies that the
Fetch_Entries_Formethod returns the correct entries for a specific log level. UsingAssert.SingleandAssert.Equalwithentries.First()provides good validation of both the count and content.
39-44: LGTM! Proper testing of unimplemented functionality.The test correctly verifies that
BeginScopethrowsNotImplementedException, which is appropriate for a mock implementation that doesn't need to support scoped logging.StoneAge.TestUtils.Tests/TestHttpClientBuilderTests.cs (2)
10-22: LGTM! Comprehensive test for custom payload functionality.The test effectively verifies that the builder creates a client that returns the specified payload and properly captures request information. The URI assertion on line 21 shows the expected behavior where HttpClient normalizes "http://test" to "http://test/" by adding a trailing slash.
24-34: LGTM! Good test for default behavior.The test correctly verifies that when no payload is specified, the client returns the default empty JSON object "{}". This establishes the expected fallback behavior.
StoneAge.TestUtils.Tests/TestHttpMessageHandlerTests.cs (3)
10-27: LGTM! Excellent test for payload sequencing.The test thoroughly verifies that multiple payloads are returned in the correct order when multiple requests are made. The fluent API usage with chained
With_Payloadcalls is clean and readable.
29-39: LGTM! Good coverage of default behavior.The test correctly verifies that when no payloads are configured, the handler returns the default empty JSON object "{}". This ensures consistent behavior across the utility classes.
41-52: LGTM! Comprehensive test for request message capturing.The test effectively verifies that the handler captures and exposes the
HttpRequestMessagethat was sent through it. The URI assertion on line 51 correctly shows the expected HttpClient behavior of normalizing "http://foo" to "http://foo/" with a trailing slash.
| {D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {D9E0C5BB-8D84-4D5B-90A6-7B091938E6C9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| EndGlobalSection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra EndGlobalSection statement.
There's an extra EndGlobalSection statement that doesn't correspond to any opening GlobalSection. This could cause parsing issues in Visual Studio.
Apply this diff to fix the structural issue:
-EndGlobalSectionCommittable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In TestUtils.sln at line 25, there is an extra EndGlobalSection statement
without a matching opening GlobalSection. Remove this extra EndGlobalSection
line to fix the structural issue and prevent parsing errors in Visual Studio.
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" /> | ||
| <PackageReference Include="xunit" Version="2.4.2" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify package versions for currency and security.
Ensure the test package versions are current and free from known vulnerabilities.
🌐 Web query:
What are the latest versions of Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio NuGet packages for .NET 6.0 projects?
💡 Result:
For .NET 6.0 projects, the latest stable versions of the specified NuGet packages are:
- Microsoft.NET.Test.Sdk: 17.13.0
- xunit: 2.9.3
- xunit.runner.visualstudio: 2.8.2
These versions are compatible with .NET 6.0 and are recommended for use in your testing projects.
To include these packages in your project, you can add the following to your .csproj file:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>Ensure that your project file targets the correct framework:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>After updating your project file, restore the packages using the following command:
dotnet restoreThis will download and install the specified versions of the packages, making them available for your testing project.
🏁 Script executed:
#!/bin/bash
# Verify the target framework in the test project
grep -R "<TargetFramework>" -n StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj || echo "No <TargetFramework> tag found in the project file."Length of output: 137
Update test project package versions to latest stable releases
The test project targets net6.0 (verified), but currently references older package versions. Please update the following in StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj:
• Microsoft.NET.Test.Sdk: 17.6.3 → 17.13.0
• xunit: 2.4.2 → 2.9.3
• xunit.runner.visualstudio: 2.4.5 → 2.8.2
Proposed diff:
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
- <PackageReference Include="xunit" Version="2.4.2" />
+ <PackageReference Include="xunit" Version="2.9.3" />
- <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>After updating, run:
dotnet restoreto install the new package versions.
🤖 Prompt for AI Agents
In StoneAge.TestUtils.Tests/StoneAge.TestUtils.Tests.csproj around lines 9 to
11, update the package versions to the latest stable releases compatible with
.NET 6.0. Change Microsoft.NET.Test.Sdk from 17.6.3 to 17.13.0, xunit from 2.4.2
to 2.9.3, and xunit.runner.visualstudio from 2.4.5 to 2.8.2. After modifying
these versions, run 'dotnet restore' to download and install the updated
packages.
This pull request introduces a comprehensive suite of unit tests for the
MockLogger,MockOptions, andMockOptionsSnapshotclasses in theStoneAge.TestUtilslibrary. The following changes have been made:MockOptionsSnapshotreturns the injected instance correctly and throws aNotImplementedExceptionfor theGetmethod.MockOptionsclass returns the correct injected instance.TestHttpClientBuilderwhen creating clients with specified and default payloads.TestHttpMessageHandlerreturns specified payloads in order and sets the request message correctly.These changes enhance the test coverage of the
StoneAge.TestUtilslibrary, ensuring better reliability and maintainability.Original Task: DotNetCoreTestUtils/1xf6kjvb55l5
Author: Travis Frisinger
Summary by CodeRabbit
New Features
Chores