-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Showing
2 changed files
with
45 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
// See the LICENSE file in the project root for more information. | ||
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace UnitTest.Extensions; | ||
|
||
public class ICacheEntryExtensionsTest : BootstrapBlazorTestBase | ||
|
@@ -16,7 +19,42 @@ public void GetLastAccessed_Ok() | |
}); | ||
|
||
Assert.True(Cache.TryGetCacheEntry("test_01", out var entry)); | ||
var v = entry.GetLastAccessed(); | ||
var v = entry.GetLastAccessed(true); | ||
Assert.NotNull(v); | ||
} | ||
|
||
[Fact] | ||
public void GetLastAccessed_Null() | ||
{ | ||
var mock = new MockCacheEntry(); | ||
var v = mock.GetLastAccessed(true); | ||
Assert.Null(v); | ||
} | ||
|
||
class MockCacheEntry : ICacheEntry | ||
{ | ||
public object Key { get; } | ||
public object? Value { get; set; } | ||
public DateTimeOffset? AbsoluteExpiration { get; set; } | ||
public TimeSpan? AbsoluteExpirationRelativeToNow { get; set; } | ||
public TimeSpan? SlidingExpiration { get; set; } | ||
public IList<IChangeToken> ExpirationTokens { get; } | ||
public IList<PostEvictionCallbackRegistration> PostEvictionCallbacks { get; } | ||
public CacheItemPriority Priority { get; set; } | ||
public long? Size { get; set; } | ||
|
||
private int LastAccessed { get; set; } | ||
|
||
public MockCacheEntry() | ||
{ | ||
Key = "_test"; | ||
ExpirationTokens = []; | ||
PostEvictionCallbacks = []; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |