C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_LossFilter.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4using AnalyzeRe;
10
11#if MSTEST
12using Microsoft.VisualStudio.TestTools.UnitTesting;
13#elif NUNIT
14using TestClass = NUnit.Framework.TestFixtureAttribute;
15using TestMethod = NUnit.Framework.TestAttribute;
16using TestCategory = NUnit.Framework.CategoryAttribute;
17#endif
18
20{
21 [TestClass]
23 {
25 protected override bool PUT_Allowed => false;
26
30 public static void TestFilterInLayerView<T>(T filter) where T : LossFilter
31 {
32 ILayerView<Filter> withFilter = Samples.GetInjectableLayerView(
33 Samples.Layer_Filter.Unposted.Change(l => l.filters,
34 new List<IReference<LossFilter>> { filter.ToReference() })).Unposted;
35 GenericTest.POST_ThenDoAction(withFilter,
36 TestSuite_APIResourceView.TestMetricsRetrievable);
37 }
38 }
39
40 #region LossFilter Derived Types
41 [TestClass]
43 {
44 #region Set Up and Configuration
45 private const string TypeName = "AndFilter";
48 #endregion Set Up and Configuration
49 }
50
51 [TestClass]
53 {
54 #region Set Up and Configuration
55 private const string TypeName = "AnyFilter";
58 #endregion Set Up and Configuration
59 }
60
61 [TestClass]
63 {
64 #region Set Up and Configuration
65 private const string TypeName = "AnyOfFilter";
68 #endregion Set Up and Configuration
69
70 #region POST
71 #region values
72 [TestMethod, TestCategory(TypeName)]
74 {
75 POST_Attribute_Null(e => e.values);
76 }
77 [TestMethod, TestCategory(TypeName)]
79 {
80 POST_ListAttribute_Empty(e => e.values);
81 }
82 [TestMethod, TestCategory(TypeName)]
84 {
85 POST_ListAttribute_Duplicates(e => e.values, "Duplicate", true);
86 }
87 [TestMethod, TestCategory(TypeName), TestCategory("Skipped")]
89 {
90 Skip.UntilRelease.Validation("Bug ARE-3378: " +
91 "Possible to POST and PUT AnyOfFilter with Mixed types.");
92 POST_WithValue(e => e.values, new List<object> { "Modified 1", 2 }, false);
93 }
94 #endregion values
95 #endregion POST
96 }
97
98 [TestClass]
99 public sealed class TestSuite_LossFilter_RecordTypeAnyOfFilter : TestSuite_LossFilter<RecordTypeAnyOfFilter>
100 {
101 #region Set Up and Configuration
102 private const string TypeName = "RecordTypeAnyOfFilter";
105 #endregion Set Up and Configuration
106
107 #region POST
108 #region values
109 [TestMethod, TestCategory(TypeName)]
111 {
112 POST_Attribute_Null(e => e.values);
113 }
114 [TestMethod, TestCategory(TypeName)]
119 [TestMethod, TestCategory(TypeName)]
121 {
122 POST_ListAttribute_Duplicates(e => e.values, RecordType.SlidingScaleCommission, true);
123 }
124 #endregion values
125 #endregion POST
126 }
127
128
129 [TestClass]
131 {
132 #region Set Up and Configuration
133 private const string TypeName = "GTFilter";
136 #endregion Set Up and Configuration
137 }
138
139 [TestClass]
141 {
142 #region Set Up and Configuration
143 private const string TypeName = "LTFilter";
146 #endregion Set Up and Configuration
147 }
148
149 [TestClass]
151 {
152 #region Set Up and Configuration
153 private const string TypeName = "OrFilter";
156 #endregion Set Up and Configuration
157 }
158
159 [TestClass]
161 {
162 #region Set Up and Configuration
163 private const string TypeName = "RangeFilter";
166 #endregion Set Up and Configuration
167
168 #region POST
169 #region begin_value
170 [TestMethod, TestCategory(TypeName)]
172 {
173 // Will fail because this will make begin_value > end_value
174 POST_WithValue(l => l.begin_value, Double.MaxValue, false);
175 }
176 [TestMethod, TestCategory(TypeName)]
178 {
179 POST_WithValue(l => l.begin_value, Double.MinValue, true);
180 }
181 [TestMethod, TestCategory(TypeName)]
183 {
184 POST_WithValue(l => l.begin_value, Double.NaN, false);
185 }
186 [TestMethod, TestCategory(TypeName)]
188 {
189 POST_WithValue(l => l.begin_value, Double.PositiveInfinity, false);
190 }
191 [TestMethod, TestCategory(TypeName)]
193 {
194 POST_WithValue(l => l.begin_value, Double.NegativeInfinity, false);
195 }
196 [TestMethod, TestCategory(TypeName)]
198 {
199 POST_WithValue(l => l.begin_value, Math.PI / 1E12, true);
200 }
201 #endregion begin_value
202
203 #region begin_inclusive
204 // Nothing to test on post, Booleans are pretty simple
205 #endregion begin_inclusive
206
207 #region end_value
208 [TestMethod, TestCategory(TypeName)]
210 {
211 POST_WithValue(l => l.end_value, Double.MaxValue, true);
212 }
213 [TestMethod, TestCategory(TypeName)]
215 {
216 // Will fail because it will make end_value < begin_value
217 POST_WithValue(l => l.end_value, Double.MinValue, false);
218 }
219 [TestMethod, TestCategory(TypeName)]
221 {
222 POST_WithValue(l => l.end_value, Double.NaN, false);
223 }
224 [TestMethod, TestCategory(TypeName)]
226 {
227 POST_WithValue(l => l.end_value, Double.PositiveInfinity, false);
228 }
229 [TestMethod, TestCategory(TypeName)]
231 {
232 POST_WithValue(l => l.end_value, Double.NegativeInfinity, false);
233 }
234 [TestMethod, TestCategory(TypeName)]
236 {
237 double newEndValue = TestResource.begin_value + Math.PI / 1E12;
238 POST_WithValue(l => l.end_value, newEndValue, true);
239 }
240 #endregion end_value
241
242 #region end_inclusive
243 // Nothing to test on post, Booleans are pretty simple
244 #endregion end_inclusive
245 #endregion POST
246 }
247 #endregion LossFilter Derived Types
248
249 #region Abstract Base LossFilter Tests
251 [TestClass]
253 {
254 private const string TypeName = "ExpressionFilter";
255
256 #region POST
257 #region expressions
258 [TestMethod, TestCategory(TypeName)]
260 {
261 POST_Attribute_Null(l => l.expressions);
262 }
263 [TestMethod, TestCategory(TypeName)]
265 {
266 POST_ListAttribute_Empty(l => l.expressions);
267 }
268 [TestMethod, TestCategory(TypeName)]
274 [TestMethod, TestCategory(TypeName)]
276 {
277 POST_ReferenceList_NonExistantId(a => a.expressions);
278 }
279 #endregion expressions
280 #endregion POST
281 }
282
284 [TestClass]
287 {
288 private const string TypeName = "ComparisonFilter";
289
290 #region POST
291 #region value
292 [TestMethod, TestCategory(TypeName)]
294 {
295 POST_WithValue(l => l.value, Double.MaxValue, true);
296 }
297 [TestMethod, TestCategory(TypeName)]
299 {
300 POST_WithValue(l => l.value, Double.MinValue, true);
301 }
302 [TestMethod, TestCategory(TypeName)]
304 {
305 POST_WithValue(l => l.value, Double.NaN, false);
306 }
307 [TestMethod, TestCategory(TypeName)]
309 {
310 POST_WithValue(l => l.value, Double.PositiveInfinity, false);
311 }
312 [TestMethod, TestCategory(TypeName)]
314 {
315 POST_WithValue(l => l.value, Double.NegativeInfinity, false);
316 }
317 [TestMethod, TestCategory(TypeName)]
319 {
320 POST_WithValue(l => l.value, Math.PI / 1E12, true);
321 }
322 #endregion value
323
324 #region inclusive
325 // Nothing to test on post, Booleans are pretty simple
326 #endregion inclusive
327 #endregion POST
328 }
329
331 [TestClass]
334 {
335 private const string TypeName = "AttributeFilter";
336
337 #region POST
338 #region attribute
339 [TestMethod, TestCategory(TypeName)]
341 {
342 POST_Attribute_Null(l => l.attribute);
343 }
344 [TestMethod, TestCategory(TypeName)]
346 {
347 POST_StringAttribute_Empty(l => l.attribute);
348 }
349 #endregion attribute
350 #endregion POST
351 }
352
354 [TestClass]
356 {
357 private const string TypeName = "LossFilter";
358
363 public override void AdditionalValidResourceTests(T posted) =>
364 TestSuite_LossFilter_Base.TestFilterInLayerView(posted);
365
366 #region POST
367 #region name
368 [TestMethod, TestCategory(TypeName)]
369 public virtual void Test_LossFilter_POST_Name_Null()
370 {
371 POST_Attribute_Null(l => l.name);
372 }
373 [TestMethod, TestCategory(TypeName)]
375 {
377 }
378 #endregion name
379
380 #region invert
381 // Nothing to test on post, Booleans are pretty simple
382 #endregion invert
383 #endregion POST
384 }
385 #endregion Abstract Base LossFilter Tests
386}
Tests for a stored resource collection which do not require an instance of that resource to be define...
void POST_StringAttribute_Empty(Expression< Func< T, string > > PropertyExpression, bool? shouldSucceed=null)
Post a resource with the specified string set to an empty string.
Exposes sample resource objects, with built-in methods for injecting dependencies.
Definition Samples.cs:14
IInjectableResource< RangeFilter > LossFilter_RangeFilter
IInjectableResource< OrFilter > LossFilter_OrFilter
IInjectableResource< AndFilter > LossFilter_AndFilter
IInjectableResource< Filter > Layer_Filter
IInjectableResource< LTFilter > LossFilter_LTFilter
IInjectableResource< AnyFilter > LossFilter_AnyFilter
IInjectableResource< GTFilter > LossFilter_GTFilter
IInjectableResource< RecordTypeAnyOfFilter > LossFilter_RecordTypeAnyOfFilter
IInjectableResource< AnyOfFilter > LossFilter_AnyOfFilter
Contains static helper methods for testing IAPIResourceView instances.
override IInjectableResource< AndFilter > TestInjectableResource
override IInjectableResource< AnyFilter > TestInjectableResource
override IInjectableResource< AnyOfFilter > TestInjectableResource
Includes tests that affect all types of AttributeFilter.
override IResourceCollection< LossFilter > collection_source
static void TestFilterInLayerView< T >(T filter)
Reference the specified filter in a new LayerView{Filter}, and test whether the LayerView POST and si...
Includes tests that affect all types of ComparisonFilter.
Includes tests that affect all types of ExpressionFilter.
override IInjectableResource< GTFilter > TestInjectableResource
override IInjectableResource< LTFilter > TestInjectableResource
override IInjectableResource< OrFilter > TestInjectableResource
override IInjectableResource< RangeFilter > TestInjectableResource
override IInjectableResource< RecordTypeAnyOfFilter > TestInjectableResource
Includes tests that affect all types of LossFilter.
override void AdditionalValidResourceTests(T posted)
For all tests, we want to test success both when the layer is posted on its own, and when it's posted...
Generic Unit test implementations that will test REST methods on arbitrary resources.
A helper class containing default skip dates.
Definition SkipUntil.cs:66
static void Validation(string ticket=null)
Skip a test due to a validation-related issue, possibly with no insight into when this issue is likel...
Class used in unit tests to mark tests as skipped by using Assert.Inconclusive() method.
Definition SkipUntil.cs:14
Describes a collection of resources which can be listed.
API methods / requests made available to the user.
static readonly ResourceCollection< LossFilter > LossFilters
The collection of LossFilters on the server.
A predicate that determines whether a loss should be included in the perspective or not.
Definition LossFilter.cs:11
A filter that does a test on some attribute.
A filter where the specified attribute's value is compared to some predetermined value.
A filter that operates on a list of filters.
IReference< T > AsReference
A reference to the posted resource.
T Unposted
The unPOSTed resource definition.
RecordType
The type of occurrence.
Definition RecordType.cs:10