@@ -4,19 +4,23 @@ namespace LoadTestToolbox.Tests;
44
55public sealed class WorkerTests
66{
7+ private static HttpRequestMessage GoodResponse ( )
8+ {
9+ Task . Delay ( 1 ) . GetAwaiter ( ) . GetResult ( ) ;
10+ return new HttpRequestMessage ( HttpMethod . Get , new Uri ( "http://localhost" ) ) ;
11+ }
12+
13+ private static HttpRequestMessage BadResponse ( ) => throw new Exception ( ) ;
14+
15+
716 [ Fact ]
817 public void ReportsDurationFromTimer ( )
918 {
1019 //arrange
1120 var http = new HttpClient ( new MockHttpMessageHandler ( ) ) ;
12- HttpRequestMessage NewMessage ( )
13- {
14- Thread . Sleep ( 1 ) ;
15- return new HttpRequestMessage ( HttpMethod . Get , new Uri ( "http://localhost" ) ) ;
16- }
1721
1822 double result = 0 ;
19- var worker = new Worker ( http , NewMessage , ( _ , r ) => result = r . Duration , _ => { } ) ;
23+ var worker = new Worker ( http , GoodResponse , ( _ , r ) => result = r . Duration , _ => { } ) ;
2024
2125 //act
2226 worker . Run ( 0 ) ;
@@ -30,12 +34,11 @@ public void ReportsAndWarnsWhenFailed()
3034 {
3135 //arrange
3236 var http = new HttpClient ( new MockHttpMessageHandler ( ) ) ;
33- HttpRequestMessage NewMessage ( ) => throw new Exception ( ) ;
3437
3538 double result = 0 ;
3639 var warning = string . Empty ;
3740
38- var worker = new Worker ( http , NewMessage , ( _ , r ) => result = r . Duration , s => warning = s ) ;
41+ var worker = new Worker ( http , BadResponse , ( _ , r ) => result = r . Duration , s => warning = s ) ;
3942
4043 //act
4144 worker . Run ( 0 ) ;
0 commit comments