-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(unit-tests): increase code coverage
This commit adds: - Improvements to existing unit test code - Improvements to existing unit test naming - Unit tests for `EFCacheKeyPrefixProvider` class - Unit tests for `EFCacheKeyProvider` class - Unit tests for `EFCacheKey` class - Unit tests for `EFCacheServiceCheck` class - Unit tests for `EFDataReaderLoader` class - Unit tests for `EFDebugLogger` class - Unit tests for `EFServiceCollectionExtensions` class - Unit tests for `LockProvider` class - Unit tests for `StringExtensions` class - Unit tests for `TableEntityInfo` class - Unit tests for `XxHash64Unsafe` class
- Loading branch information
1 parent
f08a7e2
commit ea968f5
Showing
19 changed files
with
2,900 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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
60 changes: 60 additions & 0 deletions
60
src/Tests/EFCoreSecondLevelCacheInterceptor.UnitTests/EFCacheKeyPrefixProviderTests.cs
This file contains 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,60 @@ | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
|
||
namespace EFCoreSecondLevelCacheInterceptor.UnitTests; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class EFCacheKeyPrefixProviderTests | ||
{ | ||
[Fact] | ||
public void Constructor_ThrowsArgumentNullException_WhenCacheSettingsIsNull() | ||
{ | ||
// Arrange | ||
var serviceProvider = new Mock<IServiceProvider>().Object; | ||
|
||
// ReSharper disable once ObjectCreationAsStatement | ||
void Act() => new EFCacheKeyPrefixProvider(serviceProvider, null!); | ||
|
||
// Act && Assert | ||
Assert.Throws<ArgumentNullException>("cacheSettings", Act); | ||
} | ||
|
||
[Fact] | ||
public void GetCacheKeyPrefix_ReturnsCacheKeyPrefixSelectorResult_WhenSelectorIsNotNull() | ||
{ | ||
// Arrange | ||
var serviceProvider = new Mock<IServiceProvider>().Object; | ||
var cacheSettings = Options.Create(new EFCoreSecondLevelCacheSettings | ||
{ | ||
CacheKeyPrefixSelector = _ => "CustomPrefix" | ||
}); | ||
|
||
var provider = new EFCacheKeyPrefixProvider(serviceProvider, cacheSettings); | ||
|
||
// Act | ||
var actual = provider.GetCacheKeyPrefix(); | ||
|
||
// Assert | ||
Assert.Equal("CustomPrefix", actual); | ||
} | ||
|
||
[Fact] | ||
public void GetCacheKeyPrefix_ReturnsCacheKeyPrefix_WhenSelectorIsNull() | ||
{ | ||
// Arrange | ||
var serviceProvider = new Mock<IServiceProvider>().Object; | ||
var cacheSettings = Options.Create(new EFCoreSecondLevelCacheSettings | ||
{ | ||
CacheKeyPrefix = "DefaultPrefix", | ||
CacheKeyPrefixSelector = null | ||
}); | ||
|
||
var provider = new EFCacheKeyPrefixProvider(serviceProvider, cacheSettings); | ||
|
||
// Act | ||
var actual = provider.GetCacheKeyPrefix(); | ||
|
||
// Assert | ||
Assert.Equal("DefaultPrefix", actual); | ||
} | ||
} |
Oops, something went wrong.