-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathInlineCount.cs
212 lines (131 loc) · 12.6 KB
/
InlineCount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
namespace LinqToQueryString.UnitTests
{
using System.Collections.Generic;
using System.Linq;
using LinqToQueryString.Tests;
using LinqToQuerystring;
using Machine.Specifications;
public class InlineCount : Projection
{
protected static Dictionary<string, object> inlineCountResult;
protected static IQueryable<ConcreteClass> concreteResult;
protected static IQueryable<ConcreteClass> GetWrappedResults()
{
return (inlineCountResult["Results"] as IQueryable<ConcreteClass>);
}
protected static IQueryable<Dictionary<string, object>> GetWrappedProjectedResults()
{
return (inlineCountResult["Results"] as IQueryable<Dictionary<string, object>>);
}
}
public class When_requesting_inline_count_none : InlineCount
{
Because of = () => concreteResult = concreteCollection.AsQueryable().LinqToQuerystring("?$inlinecount=none");
private It should_return_all_the_records_normally = () => concreteResult.Count().ShouldEqual(5);
private It should_return_the_first_record = () => concreteResult.ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(0).Name);
private It should_then_be_followed_by_the_second = () => concreteResult.ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_then_be_followed_by_the_third = () => concreteResult.ElementAt(2).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_fourth = () => concreteResult.ElementAt(3).Name.ShouldEqual(concreteCollection.ElementAt(3).Name);
private It should_then_be_followed_by_the_fifth = () => concreteResult.ElementAt(4).Name.ShouldEqual(concreteCollection.ElementAt(4).Name);
}
public class When_requesting_inline_count_on_an_unfiltered_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(5);
private It should_return_the_first_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(0).Name);
private It should_then_be_followed_by_the_second = () => GetWrappedResults().ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_then_be_followed_by_the_third = () => GetWrappedResults().ElementAt(2).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_fourth = () => GetWrappedResults().ElementAt(3).Name.ShouldEqual(concreteCollection.ElementAt(3).Name);
private It should_then_be_followed_by_the_fifth = () => GetWrappedResults().ElementAt(4).Name.ShouldEqual(concreteCollection.ElementAt(4).Name);
}
public class When_requesting_inline_count_on_a_projected_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$select=Name,Age&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedProjectedResults().Count().ShouldEqual(5);
private It should_project_the_name_and_age_properties_into_the_dictionary =
() => GetWrappedProjectedResults().ShouldEachConformTo(
r => r.ContainsKey("Name") && r.ContainsKey("Age"));
private It should_only_have_projected_two_properties =
() => GetWrappedProjectedResults().ShouldEachConformTo(r => r.Count == 2);
private It should_project_the_right_name_for_the_first_record = () => GetWrappedProjectedResults().ElementAt(0)["Age"].ShouldEqual(concreteCollection.ElementAt(0).Age);
private It should_project_the_right_name_for_the_second_record = () => GetWrappedProjectedResults().ElementAt(1)["Age"].ShouldEqual(concreteCollection.ElementAt(1).Age);
private It should_project_the_right_name_for_the_third_record = () => GetWrappedProjectedResults().ElementAt(2)["Age"].ShouldEqual(concreteCollection.ElementAt(2).Age);
private It should_project_the_right_name_for_the_fourth_record = () => GetWrappedProjectedResults().ElementAt(3)["Age"].ShouldEqual(concreteCollection.ElementAt(3).Age);
private It sshould_project_the_right_name_for_the_fifth_record = () => GetWrappedProjectedResults().ElementAt(4)["Age"].ShouldEqual(concreteCollection.ElementAt(4).Age);
private It should_project_the_right_age_for_the_first_record = () => GetWrappedProjectedResults().ElementAt(0)["Name"].ShouldEqual(concreteCollection.ElementAt(0).Name);
private It should_project_the_right_age_for_the_second_record = () => GetWrappedProjectedResults().ElementAt(1)["Name"].ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_project_the_right_age_for_the_third_record = () => GetWrappedProjectedResults().ElementAt(2)["Name"].ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_project_the_right_age_for_the_fourth_record = () => GetWrappedProjectedResults().ElementAt(3)["Name"].ShouldEqual(concreteCollection.ElementAt(3).Name);
private It should_project_the_right_age_for_the_fifth_record = () => GetWrappedProjectedResults().ElementAt(4)["Name"].ShouldEqual(concreteCollection.ElementAt(4).Name);
}
public class When_requesting_inline_count_on_a_filtered_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$filter=Age ge 3&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(3);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(3);
private It should_return_third_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_fourth = () => GetWrappedResults().ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(3).Name);
private It should_then_be_followed_by_the_fifth = () => GetWrappedResults().ElementAt(2).Name.ShouldEqual(concreteCollection.ElementAt(4).Name);
}
public class When_requesting_inline_count_on_an_ordered_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$orderby=Age desc&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(5);
private It should_return_the_fifth_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(4).Name);
private It should_then_be_followed_by_the_fourth = () => GetWrappedResults().ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(3).Name);
private It should_then_be_followed_by_the_third = () => GetWrappedResults().ElementAt(2).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_second = () => GetWrappedResults().ElementAt(3).Name.ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_then_be_followed_by_the_first = () => GetWrappedResults().ElementAt(4).Name.ShouldEqual(concreteCollection.ElementAt(0).Name);
}
public class When_requesting_inline_count_on_a_top_limited_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$top=3&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(3);
private It should_return_the_first_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(0).Name);
private It should_then_be_followed_by_the_second = () => GetWrappedResults().ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_then_be_followed_by_the_third = () => GetWrappedResults().ElementAt(2).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
}
public class When_requesting_inline_count_on_a_top_limited_projected_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$top=3&$select=Name,Age&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedProjectedResults().Count().ShouldEqual(3);
private It should_return_the_first_record = () => GetWrappedProjectedResults().ElementAt(0)["Name"].ShouldEqual(concreteCollection.ElementAt(0).Name);
private It should_then_be_followed_by_the_second = () => GetWrappedProjectedResults().ElementAt(1)["Name"].ShouldEqual(concreteCollection.ElementAt(1).Name);
private It should_then_be_followed_by_the_third = () => GetWrappedProjectedResults().ElementAt(2)["Name"].ShouldEqual(concreteCollection.ElementAt(2).Name);
}
public class When_requesting_inline_count_on_a_paged_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$skip=2&$top=2&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(2);
private It should_return_the_third_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_fourth = () => GetWrappedResults().ElementAt(1).Name.ShouldEqual(concreteCollection.ElementAt(3).Name);
}
public class When_requesting_inline_count_on_a_paged_projected_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$skip=2&$top=2&$select=Name,Age&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(5);
private It should_return_the_response_within_a_wrapper = () => GetWrappedProjectedResults().Count().ShouldEqual(2);
private It should_return_the_third_record = () => GetWrappedProjectedResults().ElementAt(0)["Name"].ShouldEqual(concreteCollection.ElementAt(2).Name);
private It should_then_be_followed_by_the_fourth = () => GetWrappedProjectedResults().ElementAt(1)["Name"].ShouldEqual(concreteCollection.ElementAt(3).Name);
}
public class When_requesting_inline_count_on_a_filtered_paged_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$filter=Age ge 3&$skip=2&$top=2&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(3);
private It should_return_the_response_within_a_wrapper = () => GetWrappedResults().Count().ShouldEqual(1);
private It should_return_the_fifth_record = () => GetWrappedResults().ElementAt(0).Name.ShouldEqual(concreteCollection.ElementAt(4).Name);
}
public class When_requesting_inline_count_on_a_filtered_paged_projected_query : InlineCount
{
Because of = () => inlineCountResult = concreteCollection.AsQueryable().LinqToQuerystring<ConcreteClass, Dictionary<string, object>>("?$filter=Age ge 3&$skip=2&$top=2&$select=Name,Age&$inlinecount=allpages");
private It should_return_the_correct_count = () => inlineCountResult["Count"].ShouldEqual(3);
private It should_return_the_response_within_a_wrapper = () => GetWrappedProjectedResults().Count().ShouldEqual(1);
private It should_return_the_fifth_record = () => GetWrappedProjectedResults().ElementAt(0)["Name"].ShouldEqual(concreteCollection.ElementAt(4).Name);
}
}