Skip to content

Commit 14f5b4e

Browse files
Apply @scottinet requested changes
1 parent 4655af0 commit 14f5b4e

File tree

2 files changed

+273
-244
lines changed

2 files changed

+273
-244
lines changed

Kuzzle.Tests/API/Controllers/IndexControllerTest.cs

Lines changed: 170 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -8,163 +8,195 @@
88
using Xunit;
99

1010
namespace Kuzzle.Tests.API.Controllers {
11-
public class IndexControllerTest {
12-
private readonly IndexController _indexController;
13-
private readonly KuzzleApiMock _api;
14-
15-
public IndexControllerTest() {
16-
_api = new KuzzleApiMock();
17-
_indexController = new IndexController(_api.MockedObject);
18-
}
19-
20-
[Fact]
21-
public async void CreateAsyncTest() {
22-
var expected = JObject.Parse(@"
23-
{
24-
acknowledged: true,
25-
shards_acknowledged: true
26-
} ");
27-
28-
_api.SetResult(new JObject { { "result", expected } });
29-
30-
JObject result = await _indexController.CreateAsync("foo");
31-
_api.Verify(new JObject {
32-
{ "controller", "index" },
33-
{ "action", "create" },
34-
{ "index", "foo" }
35-
});
36-
37-
Assert.Equal(expected, result);
38-
}
39-
40-
[Fact]
41-
public async void DeleteAsyncTest() {
42-
_api.SetResult(@"{result: {acknowledged: true} }");
43-
await _indexController.DeleteAsync("foo");
44-
45-
_api.Verify(new JObject {
46-
{ "controller", "index" },
47-
{ "action", "delete" },
48-
{ "index", "foo" }
49-
});
50-
}
11+
public class IndexControllerTest {
12+
private readonly IndexController _indexController;
13+
private readonly KuzzleApiMock _api;
5114

52-
[Fact]
53-
public async void ExistsAsyncTest() {
54-
_api.SetResult(@"{result: true}");
55-
bool result = await _indexController.ExistsAsync("foo");
56-
57-
_api.Verify(new JObject {
58-
{ "controller", "index" },
59-
{ "action", "exists" },
60-
{ "index", "foo" }
61-
});
62-
Assert.True(result);
15+
public IndexControllerTest() {
16+
_api = new KuzzleApiMock();
17+
_indexController = new IndexController(_api.MockedObject);
6318
}
6419

65-
[Fact]
66-
public async void GetAutoRefreshAsyncTest() {
67-
_api.SetResult(@"{result: true}");
68-
bool result = await _indexController.GetAutoRefreshAsync("foo");
69-
70-
_api.Verify(new JObject {
71-
{ "controller", "index" },
72-
{ "action", "getAutoRefresh" },
73-
{ "index", "foo" }
74-
});
75-
Assert.True(result);
20+
[Fact]
21+
public async void CreateAsyncTest() {
22+
_api.SetResult(@"
23+
{
24+
result: {
25+
acknowledged: true,
26+
shards_acknowledged: true
27+
}
28+
}
29+
");
30+
31+
Assert.Equal(
32+
new JObject {
33+
{ "acknowledged", true },
34+
{ "shards_acknowledged", true }
35+
}, await _indexController.CreateAsync("foo")
36+
);
37+
38+
_api.Verify(new JObject {
39+
{ "controller", "index" },
40+
{ "action", "create" },
41+
{ "index", "foo" }
42+
});
7643
}
7744

78-
[Fact]
79-
public async void ListAsyncTest() {
80-
_api.SetResult(@"{result: { indexes: ['foo', 'bar', 'zoo'] } }");
81-
JArray result = await _indexController.ListAsync();
45+
[Fact]
46+
public async void DeleteAsyncTest() {
47+
_api.SetResult(@"
48+
{
49+
result: {
50+
acknowledged: true
51+
}
52+
}
53+
");
8254

83-
_api.Verify(new JObject {
84-
{ "controller", "index" },
85-
{ "action", "list" },
86-
});
55+
await _indexController.DeleteAsync("foo");
8756

88-
Assert.Equal(
89-
new JArray { "foo", "bar", "zoo" },
90-
result,
91-
new JTokenEqualityComparer());
57+
_api.Verify(new JObject {
58+
{ "controller", "index" },
59+
{ "action", "delete" },
60+
{ "index", "foo" }
61+
});
9262
}
9363

94-
[Fact]
95-
public async void MDeleteAsyncTest() {
96-
var indexes = new JArray { "foo", "bar", "zoo" };
97-
_api.SetResult(@"{result: { indexes: ['foo', 'bar', 'zoo'] } }");
98-
99-
JArray result = await _indexController.MDeleteAsync(indexes);
100-
101-
var expected = new JObject {
102-
{ "controller", "index" },
103-
{ "action", "mDelete" },
104-
};
105-
106-
expected.Add("body", new JObject());
107-
((JObject)expected["body"]).Add("indexes", indexes);
108-
109-
_api.Verify(expected);
110-
111-
Assert.Equal(
112-
indexes,
113-
result,
114-
new JTokenEqualityComparer());
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+
);
74+
75+
_api.Verify(new JObject {
76+
{ "controller", "index" },
77+
{ "action", "exists" },
78+
{ "index", "foo" }
79+
});
11580
}
11681

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");
131-
_api.Verify(new JObject {
132-
{ "controller", "index" },
133-
{ "action", "refresh" },
134-
{ "index", "foo" }
135-
});
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+
);
92+
93+
_api.Verify(new JObject {
94+
{ "controller", "index" },
95+
{ "action", "getAutoRefresh" },
96+
{ "index", "foo" }
97+
});
98+
}
13699

137-
Assert.Equal(expected, result);
100+
[Fact]
101+
public async void ListAsyncTest() {
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+
);
110+
111+
_api.Verify(new JObject {
112+
{ "controller", "index" },
113+
{ "action", "list" },
114+
});
138115
}
139116

140-
[Fact]
141-
public async void RefreshInternalAsyncTest() {
142-
_api.SetResult(@"{result: { acknowledged: true }}");
143-
bool result = await _indexController.RefreshInternalAsync();
117+
[Fact]
118+
public async void MDeleteAsyncTest() {
119+
var indexes = new JArray { "foo", "bar", "zoo" };
120+
_api.SetResult(
121+
$"{{result:{{indexes:{indexes.ToString().ToLower()}}}}}");
122+
123+
Assert.Equal(
124+
indexes,
125+
await _indexController.MDeleteAsync(indexes),
126+
new JTokenEqualityComparer()
127+
);
128+
129+
_api.Verify(new JObject {
130+
{ "controller", "index" },
131+
{ "action", "mDelete" },
132+
{ "body", new JObject { { "indexes", indexes } } }
133+
});
134+
}
144135

145-
_api.Verify(new JObject {
146-
{ "controller", "index" },
147-
{ "action", "refreshInternal" },
148-
});
149-
Assert.True(result);
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+
");
149+
150+
Assert.Equal(
151+
new JObject {
152+
{ "failed", 0 },
153+
{ "successful", 5 },
154+
{ "total", 10 }
155+
}, await _indexController.RefreshAsync("foo")
156+
);
157+
158+
_api.Verify(new JObject {
159+
{ "controller", "index" },
160+
{ "action", "refresh" },
161+
{ "index", "foo" }
162+
});
150163
}
151164

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-
};
165+
[Fact]
166+
public async void RefreshInternalAsyncTest() {
167+
_api.SetResult(@"
168+
{
169+
result: {
170+
acknowledged: true
171+
}
172+
}
173+
");
160174

161-
expected.Add("body", new JObject());
162-
((JObject)expected["body"]).Add("autoRefresh", true);
175+
await _indexController.RefreshInternalAsync();
163176

164-
bool result = await _indexController.SetAutoRefreshAsync("foo", true);
177+
_api.Verify(new JObject {
178+
{ "controller", "index" },
179+
{ "action", "refreshInternal" },
180+
});
181+
}
165182

166-
_api.Verify(expected);
167-
Assert.True(result);
183+
[Theory]
184+
[InlineData(true)]
185+
[InlineData(false)]
186+
public async void SetAutoRefreshAsyncTest(bool result) {
187+
_api.SetResult($"{{result:{{response:{result.ToString().ToLower()}}}}}");
188+
189+
Assert.Equal(
190+
result,
191+
await _indexController.SetAutoRefreshAsync("foo", result)
192+
);
193+
194+
_api.Verify(new JObject {
195+
{ "controller", "index" },
196+
{ "action", "setAutoRefresh" },
197+
{ "index", "foo" },
198+
{ "body", new JObject { { "autoRefresh", result } } }
199+
});
168200
}
169-
}
201+
}
170202
}

0 commit comments

Comments
 (0)