11using System ;
2- using System . Collections . Generic ;
32using System . IO ;
4- using System . Linq ;
5- using System . Text ;
63using System . Threading . Tasks ;
7- using Autofac ;
84using Autofac . Extras . FakeItEasy ;
95using Elasticsearch . Net . Connection ;
106using Elasticsearch . Net . Exceptions ;
11- using Elasticsearch . Net . Providers ;
127using Elasticsearch . Net . Tests . Unit . Stubs ;
138using FakeItEasy ;
149using FluentAssertions ;
@@ -36,45 +31,38 @@ public void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes()
3631
3732 var getCall = FakeCalls . GetSyncCall ( fake ) ;
3833 getCall . Throws < Exception > ( ) ;
39-
34+
4035 var client = fake . Resolve < ElasticsearchClient > ( ) ;
4136
4237 client . Settings . MaxRetries . Should ( ) . Be ( _retries ) ;
4338
44- Assert . Throws < MaxRetryException > ( ( ) => client . Info ( ) ) ;
39+ Assert . Throws < MaxRetryException > ( ( ) => client . Info ( ) ) ;
4540 getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
4641
4742 }
4843 }
49-
44+
5045 [ Test ]
51- public async void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async ( )
46+ public void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async ( )
5247 {
5348 using ( var fake = new AutoFake ( callsDoNothing : true ) )
5449 {
5550 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
5651 FakeCalls . ProvideDefaultTransport ( fake ) ;
57- var getCall = FakeCalls . GetCall ( fake ) ;
52+ var getCall = FakeCalls . GetCall ( fake ) ;
5853
5954 //return a started task that throws
6055 Func < ElasticsearchResponse < Stream > > badTask = ( ) => { throw new Exception ( ) ; } ;
6156 var t = new Task < ElasticsearchResponse < Stream > > ( badTask ) ;
6257 t . Start ( ) ;
6358 getCall . Returns ( t ) ;
64-
59+
6560 var client = fake . Resolve < ElasticsearchClient > ( ) ;
6661
6762 client . Settings . MaxRetries . Should ( ) . Be ( _retries ) ;
68- try
69- {
70- var result = await client . InfoAsync ( ) ;
71- }
72- catch ( MaxRetryException e )
73- {
74- Assert . AreEqual ( typeof ( MaxRetryException ) , e . GetType ( ) ) ;
75- }
76- getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
7763
64+ Assert . Throws < MaxRetryException > ( async ( ) => await client . InfoAsync ( ) ) ;
65+ getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
7866 }
7967 }
8068
@@ -86,35 +74,37 @@ public void ShouldNotRetryOn400()
8674 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
8775 FakeCalls . ProvideDefaultTransport ( fake ) ;
8876
89- var getCall = FakeCalls . GetSyncCall ( fake ) ;
77+ var getCall = FakeCalls . GetSyncCall ( fake ) ;
9078 getCall . Returns ( FakeResponse . Any ( _connectionConfig , 400 ) ) ;
91-
79+
9280 var client = fake . Resolve < ElasticsearchClient > ( ) ;
9381
94- Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
82+ Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
9583 getCall . MustHaveHappened ( Repeated . Exactly . Once ) ;
9684
9785 }
9886 }
87+
9988 [ Test ]
10089 public async void ShouldNotRetryOn400_Async ( )
10190 {
10291 using ( var fake = new AutoFake ( callsDoNothing : true ) )
10392 {
10493 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
10594 FakeCalls . ProvideDefaultTransport ( fake ) ;
106-
95+
10796 var getCall = FakeCalls . GetCall ( fake ) ;
10897 var task = Task . FromResult ( FakeResponse . Any ( _connectionConfig , 400 ) ) ;
10998 getCall . Returns ( task ) ;
110-
99+
111100 var client = fake . Resolve < ElasticsearchClient > ( ) ;
112101
113102 var result = await client . InfoAsync ( ) ;
114103 getCall . MustHaveHappened ( Repeated . Exactly . Once ) ;
115104
116105 }
117106 }
107+
118108 [ Test ]
119109 public void ShouldNotRetryOn500 ( )
120110 {
@@ -124,77 +114,71 @@ public void ShouldNotRetryOn500()
124114 FakeCalls . ProvideDefaultTransport ( fake ) ;
125115
126116 var getCall = FakeCalls . GetSyncCall ( fake ) ;
127- getCall . Returns ( FakeResponse . Any ( _connectionConfig , 400 ) ) ;
128-
117+ getCall . Returns ( FakeResponse . Any ( _connectionConfig , 500 ) ) ;
118+
129119 var client = fake . Resolve < ElasticsearchClient > ( ) ;
130120
131- Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
121+ Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
132122 getCall . MustHaveHappened ( Repeated . Exactly . Once ) ;
133123
134124 }
135125 }
136-
126+
137127 [ Test ]
138128 public void ShouldNotRetryOn201 ( )
139129 {
140130 using ( var fake = new AutoFake ( callsDoNothing : true ) )
141131 {
142132 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
143133 FakeCalls . ProvideDefaultTransport ( fake ) ;
144-
134+
145135 var getCall = FakeCalls . GetSyncCall ( fake ) ;
146136 getCall . Returns ( FakeResponse . Any ( _connectionConfig , 201 ) ) ;
147-
137+
148138 var client = fake . Resolve < ElasticsearchClient > ( ) ;
149139
150- Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
140+ Assert . DoesNotThrow ( ( ) => client . Info ( ) ) ;
151141 getCall . MustHaveHappened ( Repeated . Exactly . Once ) ;
152142
153143 }
154144 }
155-
145+
156146 [ Test ]
157147 public void ShouldRetryOn503 ( )
158148 {
159149 using ( var fake = new AutoFake ( callsDoNothing : true ) )
160150 {
161151 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
162152 FakeCalls . ProvideDefaultTransport ( fake ) ;
163-
153+
164154 var getCall = FakeCalls . GetSyncCall ( fake ) ;
165155 getCall . Returns ( FakeResponse . Bad ( _connectionConfig ) ) ;
166-
156+
167157 var client = fake . Resolve < ElasticsearchClient > ( ) ;
168158
169- Assert . Throws < MaxRetryException > ( ( ) => client . Info ( ) ) ;
159+ Assert . Throws < MaxRetryException > ( ( ) => client . Info ( ) ) ;
170160 getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
171161
172162 }
173163 }
174-
164+
175165 [ Test ]
176- public async void ShouldRetryOn503_Async ( )
166+ public void ShouldRetryOn503_Async ( )
177167 {
178168 using ( var fake = new AutoFake ( callsDoNothing : true ) )
179169 {
180170 fake . Provide < IConnectionConfigurationValues > ( _connectionConfig ) ;
181171 FakeCalls . ProvideDefaultTransport ( fake ) ;
182-
172+
183173 var getCall = FakeCalls . GetCall ( fake ) ;
184174 getCall . Returns ( Task . FromResult ( FakeResponse . Bad ( _connectionConfig ) ) ) ;
185-
175+
186176 var client = fake . Resolve < ElasticsearchClient > ( ) ;
187- try
188- {
189- var result = await client . InfoAsync ( ) ;
190- }
191- catch ( MaxRetryException e )
192- {
193- Assert . AreEqual ( e . GetType ( ) , typeof ( MaxRetryException ) ) ;
194- }
195- getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
196177
178+ Assert . Throws < MaxRetryException > ( async ( ) => await client . InfoAsync ( ) ) ;
179+ getCall . MustHaveHappened ( Repeated . Exactly . Times ( _retries + 1 ) ) ;
197180 }
198181 }
182+
199183 }
200184}
0 commit comments