-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathQueryEntryTestsBase.cs
More file actions
214 lines (194 loc) · 8.41 KB
/
Copy pathQueryEntryTestsBase.cs
File metadata and controls
214 lines (194 loc) · 8.41 KB
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
213
214
namespace MiniLcm.Tests;
public abstract class QueryEntryTestsBase : MiniLcmTestBase
{
private readonly string Apple = "Apple";
private readonly string Peach = "Peach";
private readonly string Banana = "Banana";
private readonly string Kiwi = "Kiwi";
public override async Task InitializeAsync()
{
await base.InitializeAsync();
var nounPos = new PartOfSpeech() { Id = Guid.NewGuid(), Name = { { "en", "Noun" } } };
await Api.CreatePartOfSpeech(nounPos);
var semanticDomain = new SemanticDomain() { Id = Guid.NewGuid(), Name = { { "en", "Fruit" } }, Code = "1. Fruit" };
await Api.CreateSemanticDomain(semanticDomain);
var complexFormType = new ComplexFormType() { Id = Guid.NewGuid(), Name = new() { { "en", "Very complex" } } };
await Api.CreateComplexFormType(complexFormType);
await Api.CreateEntry(new Entry() { LexemeForm = { { "en", Apple } } });
await Api.CreateEntry(new Entry()
{
LexemeForm = { { "en", Peach } },
ComplexFormTypes = [complexFormType],
Senses =
[
new()
{
Definition = { { "en", "Fruit which tapers to a stem, grows from a tree" } }
}
]
});
await Api.CreateEntry(new Entry()
{
LexemeForm = { { "en", Banana } },
Senses =
[
new()
{
Gloss = { { "en", "Fruit" } },
Definition = { { "en", "Fruit, phone shaped" } },
PartOfSpeechId = nounPos.Id,
SemanticDomains = [semanticDomain],
ExampleSentences =
[
new ExampleSentence()
{
Sentence = { { "en", "when a kid hands you a banana phone you answer it" } }
},
new ExampleSentence()
{
Sentence = { { "en", "a banana peel can be slippery" } }
},
]
},
new()
{
Gloss = { { "en", "boat" } },
PartOfSpeechId = nounPos.Id,
SemanticDomains = [semanticDomain],
}
]
});
await Api.CreateEntry(new Entry()
{
LexemeForm = { { "en", Kiwi } },
Senses =
[
new()
{
Gloss = { { "en", "Fruit" } },
Definition = { { "en", "Fruit, fuzzy with green flesh" } },
PartOfSpeechId = nounPos.Id,
SemanticDomains = [semanticDomain],
ExampleSentences =
[
new ExampleSentence()
{
Sentence = { { "en", "I like eating Kiwis, they taste good" } }
},
]
}
]
});
}
[Fact]
public async Task CanFilterToMissingSenses()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
}
[Fact]
public async Task CanFilterToNotMissingSenses()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses!=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Kiwi, Peach, Banana);
}
[Fact]
public async Task CanFilterToMissingPartOfSpeech()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.PartOfSpeechId=null" })).ToArrayAsync();
//does not include entries with no senses
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}
[Fact]
public async Task CanFilterToMissingExamples()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.ExampleSentences=null" })).ToArrayAsync();
//Senses.ExampleSentences=null matches entries which have senses but no examples
//it does not include Apple because it has no senses, to include it a filter Senses=null is needed
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach, Banana);
}
[Fact]
public async Task CanFilterToMissingSemanticDomains()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.SemanticDomains=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}
[Fact]
public async Task CanFilterToMissingSemanticDomainsWithEmptyArray()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.SemanticDomains=[]" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}
[Fact]
public async Task CanFilterSemanticDomainCodeContains()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.SemanticDomains.Code=*Fruit" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
}
[Fact]
public async Task CanFilterToMissingComplexFormTypes()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
}
[Fact]
public async Task CanFilterToMissingComplexFormTypesWithEmptyArray()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "ComplexFormTypes=[]" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana, Kiwi);
}
[Fact]
public async Task CanFilterLexemeForm()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "LexemeForm[en]=Apple" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
}
[Fact]
public async Task CanFilterLexemeFormStartsWith()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "LexemeForm[en]^Ap" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
}
[Fact]
public async Task CanFilterLexemeFormEndsWith()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "LexemeForm[en]$ple" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple);
}
[Fact]
public async Task CanFilterLexemeFormContains()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "LexemeForm[en]=*nan" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
}
[Fact]
public async Task CanFilterGlossNull()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.Gloss[en]=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}
[Fact]
public async Task CanFilterGlossEmpty()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.Gloss[en]=" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Peach);
}
[Fact]
public async Task CanFilterGlossEqualsFruit()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.Gloss[en]=Fruit" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana, Kiwi);
}
[Fact]
public async Task CanFilterLexemeContainsAAndNoComplexFormTypes()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "LexemeForm[en]=*a/i, ComplexFormTypes=null" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Apple, Banana);
}
[Fact]
public async Task CanFilterExampleSentenceText()
{
var results = await Api.GetEntries(new(Filter: new() { GridifyFilter = "Senses.ExampleSentences.Sentence[en]=*phone" })).ToArrayAsync();
results.Select(e => e.LexemeForm["en"]).Should().BeEquivalentTo(Banana);
}
}