Skip to content

Commit 1ad39a3

Browse files
authored
Merge pull request #14 from kuzzleio/fix-optional-parameters-design
Fix optional parameters design
2 parents d51799c + 6372c3b commit 1ad39a3

File tree

8 files changed

+139
-195
lines changed

8 files changed

+139
-195
lines changed

Kuzzle.Tests/API/Controllers/CollectionControllerTest.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public CollectionControllerTest() {
1717
_collectionController = new CollectionController(_api.MockedObject);
1818
}
1919

20+
public static IEnumerable<object[]> GenerateListOptions() {
21+
yield return new object[] { null, null, null };
22+
yield return new object[] { null, null, "stored" };
23+
yield return new object[] { -10, 42, "realtime" };
24+
yield return new object[] { 12, null, null };
25+
}
26+
2027
[Theory]
2128
[
2229
MemberData(nameof(MockGenerators.GenerateMappings),
@@ -128,24 +135,23 @@ public async void GetSpecificationsAsyncTest() {
128135
}
129136

130137
[Theory]
131-
[
132-
MemberData(nameof(MockGenerators.GenerateListOptions),
133-
MemberType = typeof(MockGenerators))
134-
]
135-
public async void ListAsyncTest(ListOptions opts) {
138+
[MemberData(nameof(GenerateListOptions))]
139+
public async void ListAsyncTest(int? from, int? size, string type) {
136140
_api.SetResult(@"{result: {foo: 123}}");
137141

138-
JObject result = await _collectionController.ListAsync("foo", opts);
142+
JObject result = await _collectionController.ListAsync(
143+
"foo", from, size, type
144+
);
139145

140146
var expected = new JObject {
141147
{ "controller", "collection" },
142148
{ "action", "list" },
143149
{ "index", "foo" }
144150
};
145151

146-
if (opts != null) {
147-
expected.Merge(JObject.FromObject(opts));
148-
}
152+
if (from != null) expected.Add("from", from);
153+
if (size != null) expected.Add("size", size);
154+
if (type != null) expected.Add("type", type);
149155

150156
_api.Verify(expected);
151157

Kuzzle.Tests/API/MockGenerators.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,6 @@ public static IEnumerable<object[]> GenerateMappings() {
1010
yield return new object[] { new JObject { { "foo", "bar" } } };
1111
}
1212

13-
public static IEnumerable<object[]> GenerateListOptions() {
14-
yield return new object[] { null };
15-
yield return new object[] {
16-
JsonConvert.DeserializeObject<ListOptions>(@"{
17-
from: null,
18-
size: null,
19-
type: 'stored'
20-
}")
21-
};
22-
yield return new object[] {
23-
JsonConvert.DeserializeObject<ListOptions>(@"{
24-
from: -10,
25-
size: 42,
26-
type: 'realtime'
27-
}")
28-
};
29-
yield return new object[] {
30-
JsonConvert.DeserializeObject<ListOptions>(@"{
31-
from: 12,
32-
size: null,
33-
type: null
34-
}")
35-
};
36-
}
37-
3813
public static IEnumerable<object[]> GenerateSearchOptions() {
3914
yield return new object[] { null };
4015
yield return new object[] {

Kuzzle/API/Controllers/CollectionController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ public async Task<JObject> GetSpecificationsAsync(
9393
/// The returned list is sorted in alphanumerical order.
9494
/// </summary>
9595
public async Task<JObject> ListAsync(
96-
string index,
97-
Options.ListOptions options = null) {
96+
string index, int? from = null, int? size = null, string type = null
97+
) {
9898
var request = new JObject {
9999
{ "controller", "collection" },
100100
{ "action", "list" },
101101
{ "index", index }
102102
};
103103

104-
if (options != null) {
105-
request.Merge(JObject.FromObject(options));
106-
}
104+
if (from != null) request.Add("from", from);
105+
if (size != null) request.Add("size", size);
106+
if (type != null) request.Add("type", type);
107107

108108
Response response = await api.QueryAsync(request);
109109

0 commit comments

Comments
 (0)