-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88b850e
commit a36c813
Showing
8 changed files
with
131 additions
and
22 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using CacheDrive.Configuration; | ||
using CacheDrive.Services; | ||
using CacheDrive.Tests.Helpers; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace CacheDrive.Tests; | ||
|
||
public class MemoryAndFileHashKeyWithSaltTests | ||
{ | ||
[Test, Order(1)] | ||
public async Task CacheShouldBeSavedCorrectly() | ||
{ | ||
// Arrange | ||
ServiceProvider serviceProvider = TestHelper.CreateServiceProvider( | ||
dateNow: DateTime.Now, cacheEnabled: true, cacheExpirationType: CacheExpirationType.Hours, | ||
cacheExpiration: 2, cacheType: CacheType.MemoryAndFile, hashSalt: "Secret123"); | ||
|
||
ICacheService cacheService = serviceProvider.GetRequiredService<ICacheService>(); | ||
|
||
// Act | ||
string key = "name"; | ||
|
||
await cacheService.SetAsync(key, "John", hashKey: true); | ||
|
||
// Assert | ||
if (cacheService.TryGetValue(key, hashKey: true, out string cachedValue)) | ||
{ | ||
cachedValue.Should().Be("John"); | ||
await cacheService.FlushAsync(); | ||
} | ||
else | ||
{ | ||
await cacheService.FlushAsync(); | ||
Assert.Fail(); | ||
} | ||
|
||
await cacheService.FlushAsync(); | ||
} | ||
|
||
[Test, Order(2)] | ||
public async Task CacheShouldBeLoadCorrectly() | ||
{ | ||
// Arrange | ||
ServiceProvider serviceProvider = TestHelper.CreateServiceProvider( | ||
dateNow: DateTime.Now, cacheEnabled: true, cacheExpirationType: CacheExpirationType.Hours, | ||
cacheExpiration: 2, cacheType: CacheType.MemoryAndFile, hashSalt: "Secret123"); | ||
|
||
ICacheService cacheService = serviceProvider.GetRequiredService<ICacheService>(); | ||
|
||
string key = "name"; | ||
|
||
// Assert | ||
if (cacheService.TryGetValue(key, hashKey: true, out string cachedValue)) | ||
{ | ||
cachedValue.Should().Be("John"); | ||
await cacheService.FlushAsync(); | ||
} | ||
else | ||
{ | ||
await cacheService.FlushAsync(); | ||
Assert.Fail(); | ||
} | ||
} | ||
|
||
[Test, Order(3)] | ||
public async Task CacheShouldExpired() | ||
{ | ||
// Arrange | ||
ServiceProvider serviceProvider = TestHelper.CreateServiceProvider( | ||
dateNow: DateTime.Now.AddHours(3), cacheEnabled: true, cacheExpirationType: CacheExpirationType.Hours, | ||
cacheExpiration: 2, cacheType: CacheType.MemoryAndFile, hashSalt: "Secret123"); | ||
|
||
ICacheService cacheService = serviceProvider.GetRequiredService<ICacheService>(); | ||
|
||
string key = "name"; | ||
|
||
// Assert | ||
if (!cacheService.TryGetValue(key, hashKey: true, out string _)) | ||
{ | ||
await cacheService.FlushAsync(); | ||
Assert.Pass(); | ||
} | ||
else | ||
{ | ||
await cacheService.FlushAsync(); | ||
Assert.Fail(); | ||
} | ||
} | ||
} |
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
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