@@ -37,22 +37,14 @@ public void Task_Handles_Non_Existent_Domain()
37
37
Method = Method . GET
38
38
} ;
39
39
40
- AggregateException agg = Assert . Throws < AggregateException > (
41
- delegate
42
- {
43
- var response = client . ExecuteTaskAsync < StupidClass > ( request ) ;
40
+ var task = client . ExecuteTaskAsync < StupidClass > ( request ) ;
41
+ task . Wait ( ) ;
44
42
45
- response . Wait ( ) ;
46
- } ) ;
43
+ var response = task . Result ;
47
44
48
- Assert . IsType ( typeof ( WebException ) , agg . InnerException ) ;
49
- Assert . Equal ( "Unable to connect to the remote server" , agg . InnerException . Message ) ;
50
-
51
- //var client = new RestClient("http://nonexistantdomainimguessing.org");
52
- //var request = new RestRequest("foo");
53
- //var response = client.ExecuteTaskAsync(request);
54
-
55
- //Assert.Equal(ResponseStatus.Error, response.Result.ResponseStatus);
45
+ Assert . IsType ( typeof ( WebException ) , response . ErrorException ) ;
46
+ Assert . Equal ( "Unable to connect to the remote server" , response . ErrorException . Message ) ;
47
+ Assert . Equal ( ResponseStatus . Error , response . ResponseStatus ) ;
56
48
}
57
49
58
50
/// <summary>
@@ -73,14 +65,11 @@ public void Handles_Server_Timeout_Error()
73
65
74
66
Assert . NotNull ( response . ErrorException ) ;
75
67
Assert . IsAssignableFrom ( typeof ( WebException ) , response . ErrorException ) ;
76
- Assert . Equal ( "The operation has timed out" , response . ErrorException . Message ) ;
68
+ Assert . Contains ( "The operation has timed out" , response . ErrorException . Message ) ;
77
69
}
78
70
}
79
71
80
72
[ Fact ]
81
- // The asserts get trapped by a catch block and then added to the response.
82
- // Then the second assert is hit and it just hangs indefinitely.
83
- // Not sure why it can't break out.
84
73
public void Handles_Server_Timeout_Error_Async ( )
85
74
{
86
75
const string baseUrl = "http://localhost:8888/" ;
@@ -102,10 +91,31 @@ public void Handles_Server_Timeout_Error_Async()
102
91
103
92
Assert . NotNull ( response ) ;
104
93
Assert . Equal ( response . ResponseStatus , ResponseStatus . TimedOut ) ;
94
+ Assert . NotNull ( response . ErrorException ) ;
95
+ Assert . IsAssignableFrom ( typeof ( WebException ) , response . ErrorException ) ;
96
+ Assert . Equal ( response . ErrorException . Message , "The request timed-out." ) ;
97
+ }
98
+ }
99
+
100
+ [ Fact ]
101
+ public void Handles_Server_Timeout_Error_AsyncTask ( )
102
+ {
103
+ const string baseUrl = "http://localhost:8888/" ;
105
104
106
- //Assert.NotNull(response.ErrorException);
107
- //Assert.IsAssignableFrom(typeof(WebException), response.ErrorException);
108
- //Assert.Equal(response.ErrorException.Message, "The operation has timed out");
105
+ using ( SimpleServer . Create ( baseUrl , TimeoutHandler ) )
106
+ {
107
+ var client = new RestClient ( baseUrl ) ;
108
+ var request = new RestRequest ( "404" ) { Timeout = 500 } ;
109
+
110
+ var task = client . ExecuteTaskAsync ( request ) ;
111
+ task . Wait ( ) ;
112
+ IRestResponse response = task . Result ;
113
+ Assert . NotNull ( response ) ;
114
+ Assert . Equal ( response . ResponseStatus , ResponseStatus . TimedOut ) ;
115
+
116
+ Assert . NotNull ( response . ErrorException ) ;
117
+ Assert . IsAssignableFrom ( typeof ( WebException ) , response . ErrorException ) ;
118
+ Assert . Equal ( response . ErrorException . Message , "The request timed-out." ) ;
109
119
}
110
120
}
111
121
@@ -128,7 +138,7 @@ public void Handles_Server_Timeout_Error_With_Deserializer()
128
138
Assert . Null ( response . Data ) ;
129
139
Assert . NotNull ( response . ErrorException ) ;
130
140
Assert . IsAssignableFrom ( typeof ( WebException ) , response . ErrorException ) ;
131
- Assert . Equal ( "The operation has timed out" , response . ErrorException . Message ) ;
141
+ Assert . Contains ( "The operation has timed out" , response . ErrorException . Message ) ;
132
142
}
133
143
}
134
144
0 commit comments