-
Notifications
You must be signed in to change notification settings - Fork 9
feat(tests): add coverage settings and new unit tests #77
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright © https://myCSharp.de - all rights reserved | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using MyCSharp.HttpUserAgentParser.AspNetCore; | ||
using MyCSharp.HttpUserAgentParser.Providers; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests; | ||
|
||
public class HttpContextExtensionsTests | ||
{ | ||
[Fact] | ||
public void GetUserAgentString_Returns_Value_When_Present() | ||
{ | ||
HttpContext ctx = HttpContextTestHelpers.GetHttpContext("UA"); | ||
Assert.Equal("UA", ctx.GetUserAgentString()); | ||
} | ||
|
||
[Fact] | ||
public void GetUserAgentString_Returns_Null_When_Absent() | ||
{ | ||
DefaultHttpContext ctx = new(); | ||
Assert.Null(ctx.GetUserAgentString()); | ||
} | ||
|
||
[Fact] | ||
public void Accessor_Get_Returns_Null_When_Header_Missing() | ||
{ | ||
var provider = Substitute.For<IHttpUserAgentParserProvider>(); | ||
HttpUserAgentParserAccessor accessor = new(provider); | ||
DefaultHttpContext ctx = new(); | ||
|
||
Assert.Null(accessor.Get(ctx)); | ||
provider.DidNotReceiveWithAnyArgs().Parse(default!); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...entParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright © https://myCSharp.de - all rights reserved | ||
|
||
using Microsoft.Extensions.Caching.Memory; | ||
using Xunit; | ||
|
||
namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; | ||
|
||
public class HttpUserAgentParserMemoryCachedProviderAdditionalTests | ||
{ | ||
[Fact] | ||
public void Options_Defaults_Are_Set() | ||
{ | ||
HttpUserAgentParserMemoryCachedProviderOptions options = new(); | ||
Assert.NotNull(options.CacheOptions); | ||
Assert.NotNull(options.CacheEntryOptions); | ||
Assert.True(options.CacheOptions.SizeLimit is null || options.CacheOptions.SizeLimit >= 0); | ||
Assert.NotEqual(default, options.CacheEntryOptions.SlidingExpiration); | ||
} | ||
|
||
[Fact] | ||
public void Provider_Caches_Entries_And_Resolves_Twice() | ||
{ | ||
HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions(new MemoryCacheOptions { SizeLimit = 10 })); | ||
string ua = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36"; | ||
HttpUserAgentInformation a = provider.Parse(ua); | ||
HttpUserAgentInformation b = provider.Parse(ua); | ||
|
||
Assert.Equal(a.Name, b.Name); | ||
Assert.Equal(a.Version, b.Version); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[nitpick] A 100% line coverage threshold may be too strict and could encourage writing tests just to meet coverage rather than testing meaningful behavior. Consider using a more practical threshold like 90-95% to allow for reasonable exceptions.
Copilot uses AI. Check for mistakes.