File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
LinkDotNet.Blog.Infrastructure/Persistence
LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public async Task<IPagedList<T>> GetAllAsync(
48
48
int page = 1 ,
49
49
int pageSize = int . MaxValue )
50
50
{
51
- var key = $ "{ filter ? . Body } -{ orderBy ? . Body } -{ descending } -{ page } -{ pageSize } ";
51
+ var key = $ "{ filter ? . GetHashCode ( ) } -{ orderBy ? . GetHashCode ( ) } -{ descending } -{ page } -{ pageSize } ";
52
52
return await memoryCache . GetOrCreate ( key , async e =>
53
53
{
54
54
e . SetOptions ( Options ) ;
Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using System . Threading . Tasks ;
3
+ using FluentAssertions ;
4
+ using LinkDotNet . Blog . Domain ;
5
+ using LinkDotNet . Blog . Infrastructure . Persistence ;
6
+ using LinkDotNet . Blog . TestUtilities ;
7
+ using Microsoft . Extensions . Caching . Memory ;
8
+ using Xunit ;
9
+
10
+ namespace LinkDotNet . Blog . IntegrationTests . Infrastructure . Persistence
11
+ {
12
+ public class CachedRepositoryTests : SqlDatabaseTestBase < BlogPost >
13
+ {
14
+ [ Fact ]
15
+ public async Task ShouldNotCacheWhenDifferentQueries ( )
16
+ {
17
+ var bp1 = new BlogPostBuilder ( ) . WithTags ( "tag 1" ) . Build ( ) ;
18
+ var bp2 = new BlogPostBuilder ( ) . WithTags ( "tag 2" ) . Build ( ) ;
19
+ var bp3 = new BlogPostBuilder ( ) . WithTags ( "tag 1" ) . Build ( ) ;
20
+ await Repository . StoreAsync ( bp1 ) ;
21
+ await Repository . StoreAsync ( bp2 ) ;
22
+ await Repository . StoreAsync ( bp3 ) ;
23
+ var searchTerm = "tag 1" ;
24
+ var sut = new CachedRepository < BlogPost > ( Repository , new MemoryCache ( new MemoryCacheOptions ( ) ) ) ;
25
+ await sut . GetAllAsync ( f => f . Tags . Any ( t => t . Content == searchTerm ) ) ;
26
+ searchTerm = "tag 2" ;
27
+
28
+ var allWithTag2 = await sut . GetAllAsync ( f => f . Tags . Any ( t => t . Content == searchTerm ) ) ;
29
+
30
+ allWithTag2 . Count . Should ( ) . Be ( 1 ) ;
31
+ allWithTag2 . Single ( ) . Tags . Single ( ) . Content . Should ( ) . Be ( "tag 2" ) ;
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments