|
@@ -0,0 +1,208 @@
|
|
1
|
+using System.Collections.Generic;
|
|
2
|
+using Luticate2.Utils.Dbo.Filter;
|
|
3
|
+using Luticate2.Utils.Dbo.Result;
|
|
4
|
+using Xunit;
|
|
5
|
+
|
|
6
|
+namespace TestUtils.Binders
|
|
7
|
+{
|
|
8
|
+ public class LuFilterBinderTest
|
|
9
|
+ {
|
|
10
|
+ [Fact]
|
|
11
|
+ public void Test1()
|
|
12
|
+ {
|
|
13
|
+ var res = LuFilterBinder.FromString("");
|
|
14
|
+ Assert.NotNull(res);
|
|
15
|
+ Assert.NotNull(res.Data);
|
|
16
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
17
|
+ Assert.Equal("", res.Data.Query);
|
|
18
|
+ Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ [Fact]
|
|
22
|
+ public void Test2()
|
|
23
|
+ {
|
|
24
|
+ var res = LuFilterBinder.FromString("test");
|
|
25
|
+ Assert.NotNull(res);
|
|
26
|
+ Assert.NotNull(res.Data);
|
|
27
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
28
|
+ Assert.Equal("test", res.Data.Query);
|
|
29
|
+ Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ [Fact]
|
|
33
|
+ public void Test3()
|
|
34
|
+ {
|
|
35
|
+ var res = LuFilterBinder.FromString(" Test.42 24 ");
|
|
36
|
+ Assert.NotNull(res);
|
|
37
|
+ Assert.NotNull(res.Data);
|
|
38
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
39
|
+ Assert.Equal("Test.42 24", res.Data.Query);
|
|
40
|
+ Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ [Fact]
|
|
44
|
+ public void Test4()
|
|
45
|
+ {
|
|
46
|
+ var res = LuFilterBinder.FromString(" test: 42");
|
|
47
|
+ Assert.NotNull(res);
|
|
48
|
+ Assert.NotNull(res.Data);
|
|
49
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
50
|
+ Assert.Equal("test: 42", res.Data.Query);
|
|
51
|
+ Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ [Fact]
|
|
55
|
+ public void Test5()
|
|
56
|
+ {
|
|
57
|
+ var res = LuFilterBinder.FromString("test: 42");
|
|
58
|
+ Assert.NotNull(res);
|
|
59
|
+ Assert.NotNull(res.Data);
|
|
60
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
61
|
+ Assert.Equal("", res.Data.Query);
|
|
62
|
+ Assert.Equal(new Dictionary<string, string>{{"test", "42"}}, res.Data.Filters);
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ [Fact]
|
|
66
|
+ public void Test6()
|
|
67
|
+ {
|
|
68
|
+ var res = LuFilterBinder.FromString("test: 42 a filter value");
|
|
69
|
+ Assert.NotNull(res);
|
|
70
|
+ Assert.NotNull(res.Data);
|
|
71
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
72
|
+ Assert.Equal("a filter value", res.Data.Query);
|
|
73
|
+ Assert.Equal(new Dictionary<string, string>{{"test", "42"}}, res.Data.Filters);
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ [Fact]
|
|
77
|
+ public void Test7()
|
|
78
|
+ {
|
|
79
|
+ var res = LuFilterBinder.FromString("test: \"42 a filter value\"");
|
|
80
|
+ Assert.NotNull(res);
|
|
81
|
+ Assert.NotNull(res.Data);
|
|
82
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
83
|
+ Assert.Equal("", res.Data.Query);
|
|
84
|
+ Assert.Equal(new Dictionary<string, string>{{"test", "42 a filter value"}}, res.Data.Filters);
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ [Fact]
|
|
88
|
+ public void Test8()
|
|
89
|
+ {
|
|
90
|
+ var res = LuFilterBinder.FromString("test: \'42 a filter value\'");
|
|
91
|
+ Assert.NotNull(res);
|
|
92
|
+ Assert.NotNull(res.Data);
|
|
93
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
94
|
+ Assert.Equal("", res.Data.Query);
|
|
95
|
+ Assert.Equal(new Dictionary<string, string>{{"test", "42 a filter value"}}, res.Data.Filters);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ [Fact]
|
|
99
|
+ public void Test9()
|
|
100
|
+ {
|
|
101
|
+ var res = LuFilterBinder.FromString("test: \'42 a filter value\' some text");
|
|
102
|
+ Assert.NotNull(res);
|
|
103
|
+ Assert.NotNull(res.Data);
|
|
104
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
105
|
+ Assert.Equal("some text", res.Data.Query);
|
|
106
|
+ Assert.Equal(new Dictionary<string, string>{{"test", "42 a filter value"}}, res.Data.Filters);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ [Fact]
|
|
110
|
+ public void Test10()
|
|
111
|
+ {
|
|
112
|
+ var res = LuFilterBinder.FromString("test: \'42 a filter value\' test-2 : \'another value\' some text");
|
|
113
|
+ Assert.NotNull(res);
|
|
114
|
+ Assert.NotNull(res.Data);
|
|
115
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
116
|
+ Assert.Equal("some text", res.Data.Query);
|
|
117
|
+ Assert.Equal(new Dictionary<string, string>
|
|
118
|
+ {
|
|
119
|
+ {"test", "42 a filter value"},
|
|
120
|
+ {"test-2", "another value"}
|
|
121
|
+ }, res.Data.Filters);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ [Fact]
|
|
125
|
+ public void TestBool()
|
|
126
|
+ {
|
|
127
|
+ var res = LuFilterBinder.FromString("test: true test-2 : \'false\' fail: 42 some text");
|
|
128
|
+ Assert.NotNull(res);
|
|
129
|
+ Assert.NotNull(res.Data);
|
|
130
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
131
|
+ Assert.Equal("some text", res.Data.Query);
|
|
132
|
+ Assert.Equal(new Dictionary<string, string>
|
|
133
|
+ {
|
|
134
|
+ {"test", "true"},
|
|
135
|
+ {"test-2", "false"},
|
|
136
|
+ {"fail", "42"}
|
|
137
|
+ }, res.Data.Filters);
|
|
138
|
+ Assert.True(res.Data.GetFilterBool("test", false));
|
|
139
|
+ Assert.True(res.Data.GetFilterBool("test", true));
|
|
140
|
+ Assert.False(res.Data.GetFilterBool("test-2", false));
|
|
141
|
+ Assert.False(res.Data.GetFilterBool("test-2", true));
|
|
142
|
+ Assert.False(res.Data.GetFilterBool("fail", false));
|
|
143
|
+ Assert.True(res.Data.GetFilterBool("fail", true));
|
|
144
|
+ Assert.False(res.Data.GetFilterBool("nx", false));
|
|
145
|
+ Assert.True(res.Data.GetFilterBool("nx", true));
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ [Fact]
|
|
149
|
+ public void TestString()
|
|
150
|
+ {
|
|
151
|
+ var res = LuFilterBinder.FromString("test: 42 test-2 : \'24\' fail: test some text");
|
|
152
|
+ Assert.NotNull(res);
|
|
153
|
+ Assert.NotNull(res.Data);
|
|
154
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
155
|
+ Assert.Equal("some text", res.Data.Query);
|
|
156
|
+ Assert.Equal(new Dictionary<string, string>
|
|
157
|
+ {
|
|
158
|
+ {"test", "42"},
|
|
159
|
+ {"test-2", "24"},
|
|
160
|
+ {"fail", "test"}
|
|
161
|
+ }, res.Data.Filters);
|
|
162
|
+ Assert.Equal("42", res.Data.GetFilterString("test", ""));
|
|
163
|
+ Assert.Equal("24", res.Data.GetFilterString("test-2", ""));
|
|
164
|
+ Assert.Equal("test", res.Data.GetFilterString("fail", "azerty"));
|
|
165
|
+ Assert.Equal("qwerty", res.Data.GetFilterString("nx", "qwerty"));
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ [Fact]
|
|
169
|
+ public void TestInt()
|
|
170
|
+ {
|
|
171
|
+ var res = LuFilterBinder.FromString("test: 42 test-2 : \'24\' fail: test some text");
|
|
172
|
+ Assert.NotNull(res);
|
|
173
|
+ Assert.NotNull(res.Data);
|
|
174
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
175
|
+ Assert.Equal("some text", res.Data.Query);
|
|
176
|
+ Assert.Equal(new Dictionary<string, string>
|
|
177
|
+ {
|
|
178
|
+ {"test", "42"},
|
|
179
|
+ {"test-2", "24"},
|
|
180
|
+ {"fail", "test"}
|
|
181
|
+ }, res.Data.Filters);
|
|
182
|
+ Assert.Equal(42, res.Data.GetFilterInt("test", 0));
|
|
183
|
+ Assert.Equal(24, res.Data.GetFilterInt("test-2", 0));
|
|
184
|
+ Assert.Equal(2424, res.Data.GetFilterInt("fail", 2424));
|
|
185
|
+ Assert.Equal(4242, res.Data.GetFilterInt("nx", 4242));
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ [Fact]
|
|
189
|
+ public void TestFloat()
|
|
190
|
+ {
|
|
191
|
+ var res = LuFilterBinder.FromString("test: 42.24 test-2 : \'24.42\' fail:test some text");
|
|
192
|
+ Assert.NotNull(res);
|
|
193
|
+ Assert.NotNull(res.Data);
|
|
194
|
+ Assert.Equal(LuStatus.Success, res.Status);
|
|
195
|
+ Assert.Equal("some text", res.Data.Query);
|
|
196
|
+ Assert.Equal(new Dictionary<string, string>
|
|
197
|
+ {
|
|
198
|
+ {"test", "42.24"},
|
|
199
|
+ {"test-2", "24.42"},
|
|
200
|
+ {"fail", "test"}
|
|
201
|
+ }, res.Data.Filters);
|
|
202
|
+ Assert.Equal(42.24, res.Data.GetFilterFloat("test", 0));
|
|
203
|
+ Assert.Equal(24.42, res.Data.GetFilterFloat("test-2", 0));
|
|
204
|
+ Assert.Equal(2424.4242, res.Data.GetFilterFloat("fail", 2424.4242));
|
|
205
|
+ Assert.Equal(4242.2424, res.Data.GetFilterFloat("nx", 4242.2424));
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+}
|