1
- using System ;
2
1
using System . Collections . Generic ;
3
- using System . Collections . Immutable ;
4
- using System . Threading ;
2
+ using System . Diagnostics . CodeAnalysis ;
5
3
using OpenFeature . Constant ;
6
4
using OpenFeature . Error ;
7
5
using OpenFeature . Model ;
8
6
using OpenFeature . Providers . Memory ;
9
7
using Xunit ;
10
8
11
- namespace OpenFeature . Tests
9
+ namespace OpenFeature . Tests . Providers . Memory
12
10
{
11
+ [ SuppressMessage ( "Reliability" , "CA2007:Consider calling ConfigureAwait on the awaited task" ) ]
13
12
public class InMemoryProviderTests
14
13
{
15
14
private FeatureProvider commonProvider ;
@@ -112,7 +111,7 @@ public InMemoryProviderTests()
112
111
[ Fact ]
113
112
public async void GetBoolean_ShouldEvaluateWithReasonAndVariant ( )
114
113
{
115
- ResolutionDetails < bool > details = await this . commonProvider . ResolveBooleanValue ( "boolean-flag" , false , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
114
+ ResolutionDetails < bool > details = await this . commonProvider . ResolveBooleanValue ( "boolean-flag" , false , EvaluationContext . Empty ) ;
116
115
Assert . True ( details . Value ) ;
117
116
Assert . Equal ( Reason . Static , details . Reason ) ;
118
117
Assert . Equal ( "on" , details . Variant ) ;
@@ -121,7 +120,7 @@ public async void GetBoolean_ShouldEvaluateWithReasonAndVariant()
121
120
[ Fact ]
122
121
public async void GetString_ShouldEvaluateWithReasonAndVariant ( )
123
122
{
124
- ResolutionDetails < string > details = await this . commonProvider . ResolveStringValue ( "string-flag" , "nope" , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
123
+ ResolutionDetails < string > details = await this . commonProvider . ResolveStringValue ( "string-flag" , "nope" , EvaluationContext . Empty ) ;
125
124
Assert . Equal ( "hi" , details . Value ) ;
126
125
Assert . Equal ( Reason . Static , details . Reason ) ;
127
126
Assert . Equal ( "greeting" , details . Variant ) ;
@@ -130,7 +129,7 @@ public async void GetString_ShouldEvaluateWithReasonAndVariant()
130
129
[ Fact ]
131
130
public async void GetInt_ShouldEvaluateWithReasonAndVariant ( )
132
131
{
133
- ResolutionDetails < int > details = await this . commonProvider . ResolveIntegerValue ( "integer-flag" , 13 , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
132
+ ResolutionDetails < int > details = await this . commonProvider . ResolveIntegerValue ( "integer-flag" , 13 , EvaluationContext . Empty ) ;
134
133
Assert . Equal ( 10 , details . Value ) ;
135
134
Assert . Equal ( Reason . Static , details . Reason ) ;
136
135
Assert . Equal ( "ten" , details . Variant ) ;
@@ -139,7 +138,7 @@ public async void GetInt_ShouldEvaluateWithReasonAndVariant()
139
138
[ Fact ]
140
139
public async void GetDouble_ShouldEvaluateWithReasonAndVariant ( )
141
140
{
142
- ResolutionDetails < double > details = await this . commonProvider . ResolveDoubleValue ( "float-flag" , 13 , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
141
+ ResolutionDetails < double > details = await this . commonProvider . ResolveDoubleValue ( "float-flag" , 13 , EvaluationContext . Empty ) ;
143
142
Assert . Equal ( 0.5 , details . Value ) ;
144
143
Assert . Equal ( Reason . Static , details . Reason ) ;
145
144
Assert . Equal ( "half" , details . Variant ) ;
@@ -148,7 +147,7 @@ public async void GetDouble_ShouldEvaluateWithReasonAndVariant()
148
147
[ Fact ]
149
148
public async void GetStruct_ShouldEvaluateWithReasonAndVariant ( )
150
149
{
151
- ResolutionDetails < Value > details = await this . commonProvider . ResolveStructureValue ( "object-flag" , new Value ( ) , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
150
+ ResolutionDetails < Value > details = await this . commonProvider . ResolveStructureValue ( "object-flag" , new Value ( ) , EvaluationContext . Empty ) ;
152
151
Assert . Equal ( true , details . Value . AsStructure [ "showImages" ] . AsBoolean ) ;
153
152
Assert . Equal ( "Check out these pics!" , details . Value . AsStructure [ "title" ] . AsString ) ;
154
153
Assert . Equal ( 100 , details . Value . AsStructure [ "imagesPerPage" ] . AsInteger ) ;
@@ -160,7 +159,7 @@ public async void GetStruct_ShouldEvaluateWithReasonAndVariant()
160
159
public async void GetString_ContextSensitive_ShouldEvaluateWithReasonAndVariant ( )
161
160
{
162
161
EvaluationContext context = EvaluationContext . Builder ( ) . Set ( "email" , "[email protected] " ) . Build ( ) ;
163
- ResolutionDetails < string > details = await this . commonProvider . ResolveStringValue ( "context-aware" , "nope" , context ) . ConfigureAwait ( false ) ;
162
+ ResolutionDetails < string > details = await this . commonProvider . ResolveStringValue ( "context-aware" , "nope" , context ) ;
164
163
Assert . Equal ( "INTERNAL" , details . Value ) ;
165
164
Assert . Equal ( Reason . TargetingMatch , details . Reason ) ;
166
165
Assert . Equal ( "internal" , details . Variant ) ;
@@ -170,32 +169,32 @@ public async void GetString_ContextSensitive_ShouldEvaluateWithReasonAndVariant(
170
169
public async void EmptyFlags_ShouldWork ( )
171
170
{
172
171
var provider = new InMemoryProvider ( ) ;
173
- await provider . UpdateFlags ( ) . ConfigureAwait ( false ) ;
172
+ await provider . UpdateFlags ( ) ;
174
173
Assert . Equal ( "InMemory" , provider . GetMetadata ( ) . Name ) ;
175
174
}
176
175
177
176
[ Fact ]
178
177
public async void MissingFlag_ShouldThrow ( )
179
178
{
180
- await Assert . ThrowsAsync < FlagNotFoundException > ( ( ) => commonProvider . ResolveBooleanValue ( "missing-flag" , false , EvaluationContext . Empty ) ) . ConfigureAwait ( false ) ;
179
+ await Assert . ThrowsAsync < FlagNotFoundException > ( ( ) => this . commonProvider . ResolveBooleanValue ( "missing-flag" , false , EvaluationContext . Empty ) ) ;
181
180
}
182
181
183
182
[ Fact ]
184
183
public async void MismatchedFlag_ShouldThrow ( )
185
184
{
186
- await Assert . ThrowsAsync < TypeMismatchException > ( ( ) => commonProvider . ResolveStringValue ( "boolean-flag" , "nope" , EvaluationContext . Empty ) ) . ConfigureAwait ( false ) ;
185
+ await Assert . ThrowsAsync < TypeMismatchException > ( ( ) => this . commonProvider . ResolveStringValue ( "boolean-flag" , "nope" , EvaluationContext . Empty ) ) ;
187
186
}
188
187
189
188
[ Fact ]
190
189
public async void MissingDefaultVariant_ShouldThrow ( )
191
190
{
192
- await Assert . ThrowsAsync < GeneralException > ( ( ) => commonProvider . ResolveBooleanValue ( "invalid-flag" , false , EvaluationContext . Empty ) ) . ConfigureAwait ( false ) ;
191
+ await Assert . ThrowsAsync < GeneralException > ( ( ) => this . commonProvider . ResolveBooleanValue ( "invalid-flag" , false , EvaluationContext . Empty ) ) ;
193
192
}
194
193
195
194
[ Fact ]
196
195
public async void MissingEvaluatedVariant_ShouldThrow ( )
197
196
{
198
- await Assert . ThrowsAsync < GeneralException > ( ( ) => commonProvider . ResolveBooleanValue ( "invalid-evaluator-flag" , false , EvaluationContext . Empty ) ) . ConfigureAwait ( false ) ;
197
+ await Assert . ThrowsAsync < GeneralException > ( ( ) => this . commonProvider . ResolveBooleanValue ( "invalid-evaluator-flag" , false , EvaluationContext . Empty ) ) ;
199
198
}
200
199
201
200
[ Fact ]
@@ -212,7 +211,7 @@ public async void PutConfiguration_shouldUpdateConfigAndRunHandlers()
212
211
)
213
212
} } ) ;
214
213
215
- ResolutionDetails < bool > details = await provider . ResolveBooleanValue ( "old-flag" , false , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
214
+ ResolutionDetails < bool > details = await provider . ResolveBooleanValue ( "old-flag" , false , EvaluationContext . Empty ) ;
216
215
Assert . True ( details . Value ) ;
217
216
218
217
// update flags
@@ -225,15 +224,15 @@ await provider.UpdateFlags(new Dictionary<string, Flag>(){
225
224
} ,
226
225
defaultVariant : "greeting"
227
226
)
228
- } } ) . ConfigureAwait ( false ) ;
227
+ } } ) ;
229
228
230
- var res = await provider . GetEventChannel ( ) . Reader . ReadAsync ( ) . ConfigureAwait ( false ) as ProviderEventPayload ;
229
+ var res = await provider . GetEventChannel ( ) . Reader . ReadAsync ( ) as ProviderEventPayload ;
231
230
Assert . Equal ( ProviderEventTypes . ProviderConfigurationChanged , res . Type ) ;
232
231
233
- await Assert . ThrowsAsync < FlagNotFoundException > ( ( ) => provider . ResolveBooleanValue ( "old-flag" , false , EvaluationContext . Empty ) ) . ConfigureAwait ( false ) ;
232
+ await Assert . ThrowsAsync < FlagNotFoundException > ( ( ) => provider . ResolveBooleanValue ( "old-flag" , false , EvaluationContext . Empty ) ) ;
234
233
235
234
// new flag should be present, old gone (defaults), handler run.
236
- ResolutionDetails < string > detailsAfter = await provider . ResolveStringValue ( "new-flag" , "nope" , EvaluationContext . Empty ) . ConfigureAwait ( false ) ;
235
+ ResolutionDetails < string > detailsAfter = await provider . ResolveStringValue ( "new-flag" , "nope" , EvaluationContext . Empty ) ;
237
236
Assert . True ( details . Value ) ;
238
237
Assert . Equal ( "hi" , detailsAfter . Value ) ;
239
238
}
0 commit comments