@@ -19,152 +19,184 @@ public IndexControllerTest() {
1919
2020 [ Fact ]
2121 public async void CreateAsyncTest ( ) {
22- var expected = JObject . Parse ( @"
23- {
24- acknowledged: true,
25- shards_acknowledged: true
26- } " ) ;
22+ _api . SetResult ( @"
23+ {
24+ result: {
25+ acknowledged: true,
26+ shards_acknowledged: true
27+ }
28+ }
29+ " ) ;
2730
28- _api . SetResult ( new JObject { { "result" , expected } } ) ;
29-
30- JObject result = await _indexController . CreateAsync ( "foo" ) ;
31+ Assert . Equal (
32+ new JObject {
33+ { "acknowledged" , true } ,
34+ { "shards_acknowledged" , true }
35+ } , await _indexController . CreateAsync ( "foo" )
36+ ) ;
37+
3138 _api . Verify ( new JObject {
3239 { "controller" , "index" } ,
3340 { "action" , "create" } ,
3441 { "index" , "foo" }
3542 } ) ;
36-
37- Assert . Equal ( expected , result ) ;
38- }
43+ }
3944
4045 [ Fact ]
4146 public async void DeleteAsyncTest ( ) {
42- _api . SetResult ( @"{result: {acknowledged: true} }" ) ;
47+ _api . SetResult ( @"
48+ {
49+ result: {
50+ acknowledged: true
51+ }
52+ }
53+ " ) ;
54+
4355 await _indexController . DeleteAsync ( "foo" ) ;
4456
4557 _api . Verify ( new JObject {
4658 { "controller" , "index" } ,
4759 { "action" , "delete" } ,
4860 { "index" , "foo" }
4961 } ) ;
50- }
62+ }
5163
52- [ Fact ]
53- public async void ExistsAsyncTest ( ) {
54- _api . SetResult ( @"{result: true}" ) ;
55- bool result = await _indexController . ExistsAsync ( "foo" ) ;
64+ [ Theory ]
65+ [ InlineData ( true ) ]
66+ [ InlineData ( false ) ]
67+ public async void ExistsAsyncTest ( bool result ) {
68+ _api . SetResult ( $ "{{result:{ result . ToString ( ) . ToLower ( ) } }}") ;
69+
70+ Assert . Equal (
71+ result ,
72+ await _indexController . ExistsAsync ( "foo" )
73+ ) ;
5674
5775 _api . Verify ( new JObject {
5876 { "controller" , "index" } ,
5977 { "action" , "exists" } ,
6078 { "index" , "foo" }
6179 } ) ;
62- Assert . True ( result ) ;
63- }
80+ }
6481
65- [ Fact ]
66- public async void GetAutoRefreshAsyncTest ( ) {
67- _api . SetResult ( @"{result: true}" ) ;
68- bool result = await _indexController . GetAutoRefreshAsync ( "foo" ) ;
82+ [ Theory ]
83+ [ InlineData ( true ) ]
84+ [ InlineData ( false ) ]
85+ public async void GetAutoRefreshAsyncTest ( bool result ) {
86+ _api . SetResult ( $ "{{result:{ result . ToString ( ) . ToLower ( ) } }}") ;
87+
88+ Assert . Equal (
89+ result ,
90+ await _indexController . GetAutoRefreshAsync ( "foo" )
91+ ) ;
6992
7093 _api . Verify ( new JObject {
7194 { "controller" , "index" } ,
7295 { "action" , "getAutoRefresh" } ,
7396 { "index" , "foo" }
7497 } ) ;
75- Assert . True ( result ) ;
76- }
98+ }
7799
78100 [ Fact ]
79101 public async void ListAsyncTest ( ) {
80- _api . SetResult ( @"{result: { indexes: ['foo', 'bar', 'zoo'] } }" ) ;
81- JArray result = await _indexController . ListAsync ( ) ;
102+ var indexes = new JArray { "foo" , "bar" , "zoo" } ;
103+ _api . SetResult ( $ "{{result:{{indexes:{ indexes . ToString ( ) . ToLower ( ) } }}}}") ;
104+
105+ Assert . Equal (
106+ indexes ,
107+ await _indexController . ListAsync ( ) ,
108+ new JTokenEqualityComparer ( )
109+ ) ;
82110
83111 _api . Verify ( new JObject {
84112 { "controller" , "index" } ,
85113 { "action" , "list" } ,
86114 } ) ;
87-
88- Assert . Equal (
89- new JArray { "foo" , "bar" , "zoo" } ,
90- result ,
91- new JTokenEqualityComparer ( ) ) ;
92- }
115+ }
93116
94117 [ Fact ]
95118 public async void MDeleteAsyncTest ( ) {
96- var indexes = new JArray { "foo" , "bar" , "zoo" } ;
97- _api . SetResult ( @"{result: { indexes: ['foo', 'bar', 'zoo'] } }" ) ;
119+ var indexes = new JArray { "foo" , "bar" , "zoo" } ;
120+ _api . SetResult (
121+ $ "{{result:{{indexes:{ indexes . ToString ( ) . ToLower ( ) } }}}}") ;
98122
99- JArray result = await _indexController . MDeleteAsync ( indexes ) ;
123+ Assert . Equal (
124+ indexes ,
125+ await _indexController . MDeleteAsync ( indexes ) ,
126+ new JTokenEqualityComparer ( )
127+ ) ;
100128
101- var expected = new JObject {
102- { "controller" , "index" } ,
129+ _api . Verify ( new JObject {
130+ { "controller" , "index" } ,
103131 { "action" , "mDelete" } ,
104- } ;
105-
106- expected . Add ( "body" , new JObject ( ) ) ;
107- ( ( JObject ) expected [ "body" ] ) . Add ( "indexes" , indexes ) ;
132+ { "body" , new JObject { { "indexes" , indexes } } }
133+ } ) ;
134+ }
108135
109- _api . Verify ( expected ) ;
136+ [ Fact ]
137+ public async void RefreshAsyncTest ( ) {
138+ _api . SetResult ( @"
139+ {
140+ result: {
141+ _shards: {
142+ failed: 0,
143+ successful: 5,
144+ total: 10
145+ }
146+ }
147+ }
148+ " ) ;
110149
111150 Assert . Equal (
112- indexes ,
113- result ,
114- new JTokenEqualityComparer ( ) ) ;
115- }
151+ new JObject {
152+ { "failed" , 0 } ,
153+ { "successful" , 5 } ,
154+ { "total" , 10 }
155+ } , await _indexController . RefreshAsync ( "foo" )
156+ ) ;
116157
117- [ Fact ]
118- public async void RefreshAsyncTest ( ) {
119- var expected = JObject . Parse ( @"
120- {
121- _shards: {
122- failed: 0,
123- succressful: 5,
124- total: 10
125- }
126- } " ) ;
127-
128- _api . SetResult ( new JObject { { "result" , expected } } ) ;
129-
130- JObject result = await _indexController . RefreshAsync ( "foo" ) ;
131158 _api . Verify ( new JObject {
132159 { "controller" , "index" } ,
133160 { "action" , "refresh" } ,
134161 { "index" , "foo" }
135162 } ) ;
136-
137- Assert . Equal ( expected , result ) ;
138- }
163+ }
139164
140165 [ Fact ]
141166 public async void RefreshInternalAsyncTest ( ) {
142- _api . SetResult ( @"{result: { acknowledged: true }}" ) ;
143- bool result = await _indexController . RefreshInternalAsync ( ) ;
167+ _api . SetResult ( @"
168+ {
169+ result: {
170+ acknowledged: true
171+ }
172+ }
173+ " ) ;
174+
175+ await _indexController . RefreshInternalAsync ( ) ;
144176
145177 _api . Verify ( new JObject {
146178 { "controller" , "index" } ,
147179 { "action" , "refreshInternal" } ,
148180 } ) ;
149- Assert . True ( result ) ;
150- }
151-
152- [ Fact ]
153- public async void SetAutoRefreshAsyncTest ( ) {
154- _api . SetResult ( @"{result: { response: true } }" ) ;
155- var expected = new JObject {
156- { "controller" , "index" } ,
157- { "action" , "setAutoRefresh" } ,
158- { "index" , "foo" }
159- } ;
181+ }
160182
161- expected . Add ( "body" , new JObject ( ) ) ;
162- ( ( JObject ) expected [ "body" ] ) . Add ( "autoRefresh" , true ) ;
183+ [ Theory ]
184+ [ InlineData ( true ) ]
185+ [ InlineData ( false ) ]
186+ public async void SetAutoRefreshAsyncTest ( bool result ) {
187+ _api . SetResult ( $ "{{result:{{response:{ result . ToString ( ) . ToLower ( ) } }}}}") ;
163188
164- bool result = await _indexController . SetAutoRefreshAsync ( "foo" , true ) ;
189+ Assert . Equal (
190+ result ,
191+ await _indexController . SetAutoRefreshAsync ( "foo" , result )
192+ ) ;
165193
166- _api . Verify ( expected ) ;
167- Assert . True ( result ) ;
168- }
194+ _api . Verify ( new JObject {
195+ { "controller" , "index" } ,
196+ { "action" , "setAutoRefresh" } ,
197+ { "index" , "foo" } ,
198+ { "body" , new JObject { { "autoRefresh" , result } } }
199+ } ) ;
200+ }
169201 }
170202}
0 commit comments