11using System ;
22using System . Threading . Tasks ;
3+ using AwesomeAssertions ;
34using ExpressionCache . Core . Tests . Data ;
4- using FluentAssertions ;
55using Moq ;
66using Xunit ;
77
88namespace ExpressionCache . Core . Tests ;
99
10- public class ExpressionCacheBaseTests : IClassFixture < TestFunctionsFixture >
10+ public class ExpressionCacheBaseTests ( TestFunctionsFixture testFunctions ) : IClassFixture < TestFunctionsFixture >
1111{
12- private readonly TestFunctionsFixture _testFunctions ;
13-
14- public ExpressionCacheBaseTests ( TestFunctionsFixture testFunctions )
15- {
16- _testFunctions = testFunctions ;
17- }
18-
1912 [ Fact ]
2013 public void GetKey_FunctionWithoutParameters_ShouldReturnCacheKeyString ( )
2114 {
2215 using var fixture = new ExpressionCacheBaseFixture ( ) ;
23- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
24- var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
16+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
17+ var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
2518
2619 key . Should ( ) . Be ( CacheKeyHelper . Prefix (
27- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
28- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithoutParameters ) ) ) ) ;
20+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
21+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithoutParameters ) ) ) ) ;
2922 asyncKey . Should ( ) . Be ( CacheKeyHelper . Prefix (
30- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
31- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithoutParametersAsync ) ) ) ) ;
23+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
24+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithoutParametersAsync ) ) ) ) ;
3225 }
3326
3427 [ Fact ]
@@ -37,16 +30,16 @@ public void GetKey_FunctionWithOneParameter_ShouldReturnCacheKeyString()
3730 const int parameter = 1 ;
3831
3932 using var fixture = new ExpressionCacheBaseFixture ( ) ;
40- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithOneParameter ( parameter ) ) ;
41- var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithOneParameterAsync ( parameter ) ) ;
33+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithOneParameter ( parameter ) ) ;
34+ var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithOneParameterAsync ( parameter ) ) ;
4235
4336 key . Should ( ) . Be ( CacheKeyHelper . Prefix (
44- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
45- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithOneParameter ) ) +
37+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
38+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithOneParameter ) ) +
4639 CacheKeyHelper . Format ( parameter ) ) ) ;
4740 asyncKey . Should ( ) . Be ( CacheKeyHelper . Prefix (
48- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
49- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithOneParameterAsync ) ) +
41+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
42+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithOneParameterAsync ) ) +
5043 CacheKeyHelper . Format ( parameter ) ) ) ;
5144 }
5245
@@ -57,25 +50,25 @@ public void GetKey_FunctionWithTwoParameters_ShouldReturnCacheKeyString()
5750 const string parameterTwo = "Testing" ;
5851
5952 using var fixture = new ExpressionCacheBaseFixture ( ) ;
60- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithTwoParameters ( parameterOne , parameterTwo ) ) ;
61- var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithTwoParametersAsync ( parameterOne , parameterTwo ) ) ;
53+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithTwoParameters ( parameterOne , parameterTwo ) ) ;
54+ var asyncKey = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithTwoParametersAsync ( parameterOne , parameterTwo ) ) ;
6255
6356 key . Should ( ) . Be ( CacheKeyHelper . Prefix (
64- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
65- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithTwoParameters ) ) +
57+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
58+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithTwoParameters ) ) +
6659 CacheKeyHelper . Format ( parameterOne ) +
6760 CacheKeyHelper . Format ( parameterTwo ) ) ) ;
6861 asyncKey . Should ( ) . Be ( CacheKeyHelper . Prefix (
69- CacheKeyHelper . Format ( _testFunctions . ClassName ) +
70- CacheKeyHelper . Format ( nameof ( _testFunctions . FunctionWithTwoParametersAsync ) ) +
62+ CacheKeyHelper . Format ( testFunctions . ClassName ) +
63+ CacheKeyHelper . Format ( nameof ( testFunctions . FunctionWithTwoParametersAsync ) ) +
7164 CacheKeyHelper . Format ( parameterOne ) +
7265 CacheKeyHelper . Format ( parameterTwo ) ) ) ;
7366 }
7467
7568 [ Fact ]
7669 public void GetKey_NonFunction_ShouldThrowArgumentException ( )
7770 {
78- Action act = ( ) =>
71+ var act = ( ) =>
7972 {
8073 using var fixture = new ExpressionCacheBaseFixture ( ) ;
8174 fixture . ExpressionCacheBase . GetKey ( ( ) => 1 + 2 ) ;
@@ -89,9 +82,9 @@ public void InvokeCache_ResultInCache_ShouldReturnCachedResult()
8982 {
9083 using var fixture = new ExpressionCacheBaseFixture ( ) ;
9184 fixture . SetCacheProviderGetSuccess ( ) ;
92- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
85+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
9386
94- var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => _testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
87+ var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
9588
9689 result . Should ( ) . Be ( ExpressionCacheBaseFixture . CachedResult ) ;
9790 fixture . CacheProviderMock . Verify ( m => m . Get < string > ( key ) , Times . Once ) ;
@@ -103,9 +96,9 @@ public async Task InvokeCacheAsync_ResultInCache_ShouldReturnCachedResult()
10396 {
10497 using var fixture = new ExpressionCacheBaseFixture ( ) ;
10598 fixture . SetCacheProviderGetAsyncSuccess ( ) ;
106- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
99+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
107100
108- var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
101+ var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
109102
110103 result . Should ( ) . Be ( ExpressionCacheBaseFixture . CachedResult ) ;
111104 fixture . CacheProviderMock . Verify ( m => m . GetAsync < string > ( key ) , Times . Once ) ;
@@ -117,9 +110,9 @@ public void InvokeCache_ResultNotInCache_ShouldCacheAndReturnResult()
117110 {
118111 using var fixture = new ExpressionCacheBaseFixture ( ) ;
119112 fixture . SetCacheProviderGetFailure ( ) ;
120- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
113+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
121114
122- var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => _testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
115+ var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
123116
124117 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
125118 fixture . CacheProviderMock . Verify ( m => m . Get < string > ( key ) , Times . Once ) ;
@@ -131,9 +124,9 @@ public async Task InvokeCacheAsync_ResultNotInCache_ShouldCacheAndReturnResult()
131124 {
132125 using var fixture = new ExpressionCacheBaseFixture ( ) ;
133126 fixture . SetCacheProviderGetAsyncFailure ( ) ;
134- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
127+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
135128
136- var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
129+ var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
137130
138131 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
139132 fixture . CacheProviderMock . Verify ( m => m . GetAsync < string > ( key ) , Times . Once ) ;
@@ -145,9 +138,9 @@ public void InvokeCache_NullFunction_ShouldNotCacheNull()
145138 {
146139 using var fixture = new ExpressionCacheBaseFixture ( ) ;
147140 fixture . SetCacheProviderGetFailure ( ) ;
148- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
141+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
149142
150- var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => _testFunctions . NullFunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
143+ var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => testFunctions . NullFunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
151144
152145 result . Should ( ) . BeNull ( ) ;
153146 fixture . CacheProviderMock . Verify ( m => m . Get < string > ( key ) , Times . Never ) ;
@@ -159,9 +152,9 @@ public async Task InvokeCacheAsync_NullFunction_ShouldNotCacheNull()
159152 {
160153 using var fixture = new ExpressionCacheBaseFixture ( ) ;
161154 fixture . SetCacheProviderGetAsyncFailure ( ) ;
162- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
155+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
163156
164- var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => _testFunctions . NullFunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
157+ var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => testFunctions . NullFunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Invoke ) ;
165158
166159 result . Should ( ) . BeNull ( ) ;
167160 fixture . CacheProviderMock . Verify ( m => m . GetAsync < string > ( key ) , Times . Never ) ;
@@ -173,9 +166,9 @@ public void InvokeCache_Overwrite_ShouldReturnNewValueAndCache()
173166 {
174167 using var fixture = new ExpressionCacheBaseFixture ( ) ;
175168 fixture . SetCacheProviderGetSuccess ( ) ;
176- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
169+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
177170
178- var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => _testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Overwrite ) ;
171+ var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Overwrite ) ;
179172
180173 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
181174 fixture . CacheProviderMock . Verify ( m => m . Get < string > ( key ) , Times . Never ) ;
@@ -187,9 +180,9 @@ public async Task InvokeCacheAsync_Overwrite_ShouldReturnNewValueAndCache()
187180 {
188181 using var fixture = new ExpressionCacheBaseFixture ( ) ;
189182 fixture . SetCacheProviderGetAsyncSuccess ( ) ;
190- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
183+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
191184
192- var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Overwrite ) ;
185+ var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Overwrite ) ;
193186
194187 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
195188 fixture . CacheProviderMock . Verify ( m => m . GetAsync < string > ( key ) , Times . Never ) ;
@@ -201,9 +194,9 @@ public void InvokeCache_Bypass_ShouldReturnNewValueAndCache()
201194 {
202195 using var fixture = new ExpressionCacheBaseFixture ( ) ;
203196 fixture . SetCacheProviderGetSuccess ( ) ;
204- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParameters ( ) ) ;
197+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParameters ( ) ) ;
205198
206- var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => _testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Bypass ) ;
199+ var result = fixture . ExpressionCacheBase . InvokeCache ( ( ) => testFunctions . FunctionWithoutParameters ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Bypass ) ;
207200
208201 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
209202 fixture . CacheProviderMock . Verify ( m => m . Get < string > ( key ) , Times . Never ) ;
@@ -215,9 +208,9 @@ public async Task InvokeCacheAsync_Bypass_ShouldReturnNewValueAndCache()
215208 {
216209 using var fixture = new ExpressionCacheBaseFixture ( ) ;
217210 fixture . SetCacheProviderGetAsyncSuccess ( ) ;
218- var key = fixture . ExpressionCacheBase . GetKey ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) ) ;
211+ var key = fixture . ExpressionCacheBase . GetKey ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) ) ;
219212
220- var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => _testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Bypass ) ;
213+ var result = await fixture . ExpressionCacheBase . InvokeCacheAsync ( ( ) => testFunctions . FunctionWithoutParametersAsync ( ) , ExpressionCacheBaseFixture . TimeSpan , CacheAction . Bypass ) ;
221214
222215 result . Should ( ) . Be ( TestFunctionsFixture . ReturnResult ) ;
223216 fixture . CacheProviderMock . Verify ( m => m . GetAsync < string > ( key ) , Times . Never ) ;
0 commit comments