@@ -65,6 +65,8 @@ internal async Task InitializeProxySettingsAsync()
65
65
catch ( RequestFailedException ex )
66
66
when ( ex . Status == 404 )
67
67
{
68
+ // We don't throw the exception here because Playback only tests that are testing the
69
+ // recording infrastructure itself will not have session records.
68
70
MismatchException = new TestRecordingMismatchException ( ex . Message , ex ) ;
69
71
return ;
70
72
}
@@ -180,6 +182,7 @@ public TestRandom Random
180
182
_random = new TestRandom ( Mode , seed ) ;
181
183
break ;
182
184
case RecordedTestMode . Playback :
185
+ ValidateVariables ( ) ;
183
186
_random = new TestRandom ( Mode , int . Parse ( Variables [ RandomSeedVariableKey ] ) ) ;
184
187
break ;
185
188
default :
@@ -325,17 +328,25 @@ public string GetVariable(string variableName, string defaultValue, Func<string,
325
328
case RecordedTestMode . Live :
326
329
return defaultValue ;
327
330
case RecordedTestMode . Playback :
328
- if ( Variables . Count == 0 )
329
- {
330
- throw new TestRecordingMismatchException ( "The recording contains no variables." ) ;
331
- }
331
+ ValidateVariables ( ) ;
332
332
Variables . TryGetValue ( variableName , out string value ) ;
333
333
return value ;
334
334
default :
335
335
throw new ArgumentOutOfRangeException ( ) ;
336
336
}
337
337
}
338
338
339
+ private void ValidateVariables ( )
340
+ {
341
+ if ( Variables . Count == 0 )
342
+ {
343
+ throw new TestRecordingMismatchException (
344
+ "The record session does not exist or is missing the Variables section. If the test is " +
345
+ "attributed with 'RecordedTest', it will be recorded automatically. Otherwise, set the " +
346
+ "RecordedTestMode to 'Record' and attempt to record the test." ) ;
347
+ }
348
+ }
349
+
339
350
public void SetVariable ( string variableName , string value , Func < string , string > sanitizer = default )
340
351
{
341
352
switch ( Mode )
0 commit comments