C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_Layer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Linq.Expressions;
5using System.Reflection;
6
7using AnalyzeRe;
10using AnalyzeRe.Fees;
16
17#if MSTEST
18using Microsoft.VisualStudio.TestTools.UnitTesting;
19#elif NUNIT
20using NUnit.Framework;
21using TestClass = NUnit.Framework.TestFixtureAttribute;
22using TestMethod = NUnit.Framework.TestAttribute;
23using TestCategory = NUnit.Framework.CategoryAttribute;
24#endif
25
27{
28 [TestClass]
30 {
32
36
42 where T : ILayer
43 {
45 Samples.GetInjectableLayerView(layerToInline).Unposted;
46 if (shouldSucceed)
47 {
48 // Assert not only that we can post a layer_view containing this layer,
49 // but that we can retrieve metrics on this layer_view without issues.
50 GenericTest.POST_ThenDoAction(inlinedLayerView,
51 TestSuite_APIResourceView.TestMetricsRetrievable);
52 }
53 else
54 GenericTest.POST_InvalidResource_Fails(inlinedLayerView);
55 }
56
59 [TestMethod, TestCategory("FixedRateCurrencyConverter")]
64
68 [TestMethod, TestCategory("Filter")]
70 {
71 GenericTest.POST_ValidResource(Samples.Layer_Filter.Unposted);
72 }
73 }
74
75 #region Layer Derived Types
76 [TestClass]
78 {
79 #region Set Up and Configuration
80 private const string TypeName = "AggXL";
83 #endregion Set Up and Configuration
84 }
85
86 [TestClass]
88 {
89 #region Set Up and Configuration
90 private const string TypeName = "Generic";
93 #endregion Set Up and Configuration
94
95 #region POST
96 // Includes some additional Reinstatement Type tests.
97 #region reinstatements
98 [TestMethod, TestCategory(TypeName)]
100 {
101 POST_Attribute_Null(l => l.reinstatements);
102 }
103
104 [TestMethod, TestCategory(TypeName)]
106 {
107 POST_ListAttribute_Empty(l => l.reinstatements);
108 }
109
110 #region reinstatement.premium and .brokerage
111 [TestMethod, TestCategory(TypeName)]
113 {
114 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = Double.MaxValue, brokerage = Double.MaxValue } };
115 POST_WithValue(l => l.reinstatements, newList, true);
116 }
117 [TestMethod, TestCategory(TypeName)]
119 {
120 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = Double.MinValue, brokerage = Double.MinValue } };
121 POST_WithValue(l => l.reinstatements, newList, true);
122 }
123 [TestMethod, TestCategory(TypeName)]
125 {
126 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = 0, brokerage = 0 } };
127 POST_WithValue(l => l.reinstatements, newList, true);
128 }
129 [TestMethod, TestCategory(TypeName)]
131 {
132 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = Double.NaN, brokerage = Double.NaN } };
133 POST_WithValue(l => l.reinstatements, newList, false);
134 }
135 [TestMethod, TestCategory(TypeName)]
137 {
138 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = Double.PositiveInfinity, brokerage = Double.PositiveInfinity } };
139 POST_WithValue(l => l.reinstatements, newList, false);
140 }
141 [TestMethod, TestCategory(TypeName)]
143 {
144 List<Reinstatement> newList = new List<Reinstatement> { new Reinstatement { premium = Double.NegativeInfinity, brokerage = Double.NegativeInfinity } };
145 POST_WithValue(l => l.reinstatements, newList, false);
146 }
147 [TestMethod, TestCategory(TypeName)]
149 {
151 new Reinstatement { premium = Math.PI / 1E12, brokerage = Math.PI / 1E12 }
152 };
153 POST_WithValue(l => l.reinstatements, newList, true);
154 }
155 #endregion reinstatement.premium and .brokerage
156 #endregion reinstatements
157 #endregion POST
158
159 #region PUT
160 #region reinstatements
161 [TestMethod, TestCategory(TypeName)]
163 {
165 {
166 new Reinstatement { brokerage = 1, premium = 1 },
167 new Reinstatement { brokerage = 0.5, premium = 1 }
168 };
169 PUT_WithValue(l => l.reinstatements, newReinstatements, true);
170 }
171 [TestMethod, TestCategory(TypeName)]
173 {
174 PUT_ListAttribute_Empty(l => l.reinstatements);
175 }
176 #endregion reinstatements
177 #endregion PUT
178 }
179
180 [TestClass]
181 public sealed class TestSuite_Layer_CatXL : TestSuite_Layer_XL<CatXL>
182 {
183 #region Set Up and Configuration
184 private const string TypeName = "CatXL";
187 #endregion Set Up and Configuration
188
189 #region POST
190 #region nth
191 [TestMethod, TestCategory(TypeName)]
193 {
194 POST_WithValue(l => l.nth, Int32.MaxValue, true);
195 }
196 [TestMethod, TestCategory(TypeName)]
198 {
199 POST_WithValue(l => l.nth, Int32.MinValue, false);
200 }
201 [TestMethod, TestCategory(TypeName)]
203 {
204 POST_WithValue(l => l.nth, 0, false);
205 POST_WithValue(l => l.nth, -1, false);
206 }
207 #endregion nth
208
209 #region reinstatements
210 [TestMethod, TestCategory(TypeName)]
212 {
213 POST_Attribute_Null(l => l.reinstatements);
214 }
215
216 [TestMethod, TestCategory(TypeName)]
218 {
219 POST_ListAttribute_Empty(l => l.reinstatements);
220 }
221
222 // Note: Detailed Reinstatements tests exist in the Generic layer tests
223 // the test outcomes are assumed to be shared between the two.
224 #endregion reinstatements
225 #endregion POST
226
227 #region PUT
228 #region nth
229 [TestMethod, TestCategory(TypeName)]
231 {
232 PUT_WithValue(l => l.nth, 5, true);
233 }
234 [TestMethod, TestCategory(TypeName)]
236 {
237 PUT_WithValue(l => l.nth, Int32.MaxValue, true);
238 }
239 [TestMethod, TestCategory(TypeName)]
241 {
242 PUT_WithValue(l => l.nth, Int32.MinValue, false);
243 }
244 [TestMethod, TestCategory(TypeName)]
246 {
247 PUT_WithValue(l => l.nth, 0, false);
248 PUT_WithValue(l => l.nth, -1, false);
249 }
250 #endregion nth
251
252 #region reinstatements
253 [TestMethod, TestCategory(TypeName)]
255 {
257 {
258 new Reinstatement { brokerage = 1, premium = 1 },
259 new Reinstatement { brokerage = 0.5, premium = 1 }
260 };
261 PUT_WithValue(l => l.reinstatements, newReinstatements, true);
262 }
263 [TestMethod, TestCategory(TypeName)]
265 {
266 PUT_ListAttribute_Empty(l => l.reinstatements);
267 }
268 #endregion reinstatements
269 #endregion PUT
270 }
271
272 [TestClass]
274 {
275 #region Set Up and Configuration
276 private const string TypeName = "QuotaShare";
279 #endregion Set Up and Configuration
280 }
281
282 [TestClass]
284 : TestSuite_Layer_QuotaShare_Base<AggregateQuotaShare>
285 {
286 #region Set Up and Configuration
287 private const string TypeName = "AggregateQuotaShare";
290 #endregion Set Up and Configuration
291
292 #region POST
293 #region aggregate_attachment
294 [TestMethod, TestCategory(TypeName)]
296 {
297 POST_Attribute_Null(l => l.aggregate_attachment);
298 }
299
300 [TestMethod, TestCategory(TypeName)]
302 {
303 POST_WithValue(l => l.aggregate_attachment,
304 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
305 }
306 #endregion aggregate_attachment
307
308 #region aggregate_limit
309 [TestMethod, TestCategory(TypeName)]
311 {
312 POST_Attribute_Null(l => l.aggregate_limit);
313 }
314
315 [TestMethod, TestCategory(TypeName)]
317 {
318 POST_WithValue(l => l.aggregate_limit,
319 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
320 }
321 #endregion aggregate_limit
322 #endregion POST
323
324 #region PUT
325 #region aggregate_attachment
326 [TestMethod, TestCategory(TypeName)]
328 {
329 PUT_Attribute_Null(l => l.aggregate_attachment);
330 }
331
332 [TestMethod, TestCategory(TypeName)]
334 {
335 PUT_WithValue(l => l.aggregate_attachment,
336 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
337 }
338 #endregion aggregate_attachment
339
340 #region aggregate_limit
341 [TestMethod, TestCategory(TypeName)]
343 {
344 PUT_Attribute_Null(l => l.aggregate_limit);
345 }
346
347 [TestMethod, TestCategory(TypeName)]
349 {
350 PUT_WithValue(l => l.aggregate_limit,
351 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
352 }
353 #endregion aggregate_limit
354 #endregion PUT
355 }
356
357 [TestClass]
358 public sealed class TestSuite_Layer_SurplusShare : TestSuite_Layer_WithTerms<SurplusShare>
359 {
360 #region Set Up and Configuration
361 private const string TypeName = "SurplusShare";
364 #endregion Set Up and Configuration
365
366 #region POST
367 #region sums_insured
368 [TestMethod, TestCategory(TypeName)]
370 {
371 POST_Attribute_Null(l => l.sums_insured);
372 }
373
374 [TestMethod, TestCategory(TypeName)]
376 {
377 POST_WithValue(l => l.sums_insured,
378 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
379 }
380
381 [TestMethod, TestCategory(TypeName)]
383 {
384 POST_WithValue(l => l.sums_insured,
385 new MonetaryUnit(-100.0, "USD"), true);
386 }
387 #endregion sums_insured
388
389 #region retained_line
390 [TestMethod, TestCategory(TypeName)]
392 {
393 POST_Attribute_Null(l => l.retained_line);
394 }
395
396 [TestMethod, TestCategory(TypeName)]
398 {
399 POST_WithValue(l => l.retained_line,
400 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
401 }
402 #endregion retained_line
403
404 #region participation
405 // Disable these inherited test methods and don't set the [TestMethod] attribute - participation is get only, no set.
406 public override void Test_Layer_POST_Participation_MaxValue() { }
407 public override void Test_Layer_POST_Participation_MinValue() { }
408 public override void Test_Layer_POST_Participation_NaN() { }
409 public override void Test_Layer_POST_Participation_Infinity() { }
412
413 [TestMethod, TestCategory(TypeName)]
415 {
416 Skip.Indefinitely("ARE-5460: Server doesn't return SurplusShare participation.");
417 SurplusShare postedLayer = TestResource_Existing;
418
419 // Check that the server_computed participation is being populated behind the scenes
421 "server_set_participation", BindingFlags.NonPublic | BindingFlags.Instance);
422 double? privateValue = (double?)privateParticipation?.GetValue(postedLayer);
423 Assert.IsNotNull(privateValue, "The server didn't supply a participation value!");
424 Assert.AreEqual(postedLayer.participation, privateValue);
425 }
426
427 [TestMethod, TestCategory(TypeName)]
429 {
430 // Check that the overridden 'participation' property behaves as expected
431 double computed_participation = TestResource.participation;
432 SurplusShare postedLayer = TestResource_Existing;
433 // The server-side participation is used after post, but it should match our calculations
434 AssertApi.DoublesAreEqual(computed_participation, postedLayer.participation);
435
436 // Check that there is only one user-facing property that identifies as "participation"
437 PropertyInfo participation = typeof(SurplusShare).GetUserFacingProperties()
438 .Single(pi => pi.Name.ToLower().Equals(nameof(ILayer_WithTerms.participation)) ||
439 (pi.GetCustomAttributeFast<PropertyAlias>()?.Aliases?
440 .Contains(nameof(ILayer_WithTerms.participation)) ?? false));
441
442 // Verify that property that identifies as "participation" returns the same
443 // value as the overridden participation property.
444 double reflected_value = (double)participation.GetValue(TestResource);
445 AssertApi.DoublesAreEqual(computed_participation, reflected_value);
446 Console.WriteLine("Property identifying as \"participation\" is named \"" +
447 participation.Name + "\" (Value: " + reflected_value + ")");
448
449 // Verify that the same is observed if referencing participation without strong typing.
451 AssertApi.DoublesAreEqual(computed_participation, asWithTerms.participation);
452 }
453
454 [TestMethod, TestCategory(TypeName)]
456 {
457 // Test that both client and server compute negative participation the same.
458 double original_participation = TestResource.participation;
460 "This test assumes the test resource has a positive computed participation.");
461 MonetaryUnit sumsInsured = TestResource.sums_insured;
462 SurplusShare negated = TestResource.Change(ss => ss.sums_insured,
463 new MonetaryUnit(sumsInsured.value * -1, sumsInsured.currency));
464 double computed_negative_participation = negated.participation;
466 // Ensure that the server agrees with our calculations
467 POST_ThenDoAction(negated, posted =>
468 Assert.AreEqual(computed_negative_participation, posted.participation,
469 "Server did not compute the same negative participation as us."));
470 }
471
472 [TestMethod, TestCategory(TypeName)]
474 {
475 AssertApi.ExceptionThrown<NotSupportedException>(
476 () => TestResource.participation = 1);
477 }
478 #endregion participation
479
480 #region number_of_lines
481 [TestMethod, TestCategory(TypeName)]
483 {
484 POST_WithValue(l => l.number_of_lines, Double.MaxValue, true);
485 }
486 [TestMethod, TestCategory(TypeName)]
488 {
489 POST_WithValue(l => l.number_of_lines, Double.MinValue, false);
490 }
491 [TestMethod, TestCategory(TypeName)]
493 {
494 POST_WithValue(l => l.number_of_lines, Double.NaN, false);
495 }
496 [TestMethod, TestCategory(TypeName)]
498 {
499 POST_WithValue(l => l.number_of_lines, Double.PositiveInfinity, false);
500 }
501 [TestMethod, TestCategory(TypeName)]
503 {
504 POST_WithValue(l => l.number_of_lines, Double.NegativeInfinity, false);
505 }
506 [TestMethod, TestCategory(TypeName)]
508 {
509 POST_WithValue(l => l.number_of_lines, Math.PI / 1E12, true);
510 }
511 #endregion number_of_lines
512 #endregion POST
513
514 #region PUT
515 #region sums_insured
516 [TestMethod, TestCategory(TypeName)]
518 {
519 PUT_Attribute_Null(l => l.sums_insured);
520 }
521
522 [TestMethod, TestCategory(TypeName)]
524 {
525 PUT_WithValue(l => l.sums_insured,
526 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
527 }
528 #endregion sums_insured
529
530 #region retained_line
531 [TestMethod, TestCategory(TypeName)]
533 {
534 PUT_Attribute_Null(l => l.retained_line);
535 }
536
537 [TestMethod, TestCategory(TypeName)]
539 {
540 PUT_WithValue(l => l.retained_line, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
541 }
542 #endregion retained_line
543
544 #region participation
545 // Disable this inherited test method and don't set the [TestMethod] attribute - participation is get only, no set.
546 public override void Test_Layer_PUT_Participation() { }
547 #endregion participation
548
549 #region number_of_lines
550 [TestMethod, TestCategory(TypeName)]
552 {
553 PUT_WithValue(l => l.number_of_lines, 1234.56789, true);
554 }
555 #endregion number_of_lines
556 #endregion PUT
557 }
558
559 [TestClass]
560 public sealed class TestSuite_Layer_IndustryLossWarranty : TestSuite_Layer_WithTerms<IndustryLossWarranty>
561 {
562 #region Set Up and Configuration
563 private const string TypeName = "IndustryLossWarranty";
566 #endregion Set Up and Configuration
567
568 #region POST
569 #region trigger
570 [TestMethod, TestCategory(TypeName)]
575
576 [TestMethod, TestCategory(TypeName)]
578 {
579 POST_WithValue(l => l.trigger,
580 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
581 }
582 #endregion trigger
583
584 #region payout
585 [TestMethod, TestCategory(TypeName)]
590
591 [TestMethod, TestCategory(TypeName)]
593 {
594 POST_WithValue(l => l.payout,
595 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
596 }
597 #endregion payout
598
599 #region nth
600 [TestMethod, TestCategory(TypeName)]
605
606 [TestMethod, TestCategory(TypeName)]
608 {
609 POST_WithValue(l => l.nth, Int32.MaxValue, true);
610 }
611
612 [TestMethod, TestCategory(TypeName)]
614 {
615 POST_WithValue(l => l.nth, Int32.MinValue, false);
616 }
617
618 [TestMethod, TestCategory(TypeName)]
620 {
621 POST_WithValue(l => l.nth, 0, false);
622 POST_WithValue(l => l.nth, -1, false);
623 }
624 #endregion nth
625 #endregion POST
626
627 #region PUT
628 #region trigger
629 [TestMethod, TestCategory(TypeName)]
631 {
632 PUT_Attribute_Null(l => l.trigger);
633 }
634
635 [TestMethod, TestCategory(TypeName)]
637 {
638 PUT_WithValue(l => l.trigger,
639 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
640 }
641 #endregion trigger
642
643 #region payout
644 [TestMethod, TestCategory(TypeName)]
649
650 [TestMethod, TestCategory(TypeName)]
652 {
653 PUT_WithValue(l => l.payout, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
654 }
655 #endregion payout
656
657 #region nth
658 [TestMethod, TestCategory(TypeName)]
660 {
661 PUT_WithValue(l => l.nth, 5, true);
662 }
663
664 [TestMethod, TestCategory(TypeName)]
669
670 [TestMethod, TestCategory(TypeName)]
672 {
673 PUT_WithValue(l => l.nth, Int32.MaxValue, true);
674 }
675
676 [TestMethod, TestCategory(TypeName)]
678 {
679 PUT_WithValue(l => l.nth, Int32.MinValue, false);
680 }
681
682 [TestMethod, TestCategory(TypeName)]
684 {
685 PUT_WithValue(l => l.nth, 0, false);
686 PUT_WithValue(l => l.nth, -1, false);
687 }
688 #endregion nth
689 #endregion PUT
690 }
691
692 [TestClass]
693 public sealed class TestSuite_Layer_Nested : TestSuite_Layer<Nested>
694 {
695 #region Set Up and Configuration
696 private const string TypeName = "Nested";
699 #endregion Set Up and Configuration
700
701 #region Test Helpers
704
707 Samples.AllLayerTypesTestList.Where(i => !UnsupportedNestedSinkTypes.Contains(i.UnderlyingType));
708
711 Samples.AllLayerTypesTestList.Where(i => UnsupportedNestedSinkTypes.Contains(i.UnderlyingType));
712 #endregion Test Helpers
713
714 #region POST
715 #region sink
716 [TestMethod, TestCategory(TypeName)]
718 {
719 POST_Attribute_Null(l => l.sink);
720 }
721 [TestMethod, TestCategory(TypeName)]
723 {
724 POST_Reference_NullId(l => l.sink);
725 // Try a "null" version of various reference types to ensure our serializer can handle it.
726 POST_WithValue(l => l.sink, new Reference<ILayer>((string)null), false);
727 POST_WithValue(l => l.sink, new Reference<Layer>((string)null), false);
728 POST_WithValue(l => l.sink, new Reference<ILayerView>((string)null), false);
729 POST_WithValue(l => l.sink, new Reference<ILayerSource>((string)null), false);
730 }
731 [TestMethod, TestCategory(TypeName)]
733 {
734 //POST_Reference_EmptyStringId(l => l.sink);
736 POST_WithValue(l => l.sink, reference, false);
737 }
738 [TestMethod, TestCategory(TypeName)]
740 {
741 //POST_Reference_NonExistantId(l => l.sink);
743 POST_WithValue(l => l.sink, reference, false);
744 }
745 [TestMethod, TestCategory(TypeName)]
747 {
748 // Loop over each layer type, generate and test POST a testResource with it.
750 .Where(l => !l.UnderlyingType.IsAttributeDefinedFast<NotSaveableAttribute>()))
751 POST_WithValue(l => l.sink, layer.AsReference, true);
752 }
753 [TestMethod, TestCategory(TypeName)]
755 {
756 // Demonstrate that posting Nested layers with inlined sinks is disallowed.
757 // LayerViews, however, allow the inlining
759 POST_WithValue_Inconsistent(l => l.sink, layer.AsInlinedReference, false);
760 }
761 [TestMethod, TestCategory(TypeName)]
763 {
764 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
765 // While the Nested Layer sink can hold a layer_view reference, these cannot be saved
767 POST_WithValue_Inconsistent(l => l.sink, layerView.AsReference, false);
768 }
769 [TestMethod, TestCategory(TypeName)]
771 {
773 {
774 // Test invalid types as layer references
775 POST_WithValue(l => l.sink, layer.AsReference, false);
776 // Test invalid types as inlined layer definitions
777 POST_WithValue(l => l.sink, layer.AsInlinedReference, false);
778 }
779 }
780 #endregion sink
781
782 #region sources
783 [TestMethod, TestCategory(TypeName)]
785 {
786 POST_WithValue(l => l.sources, null, false);
787 }
788 [TestMethod, TestCategory(TypeName)]
790 {
791 // BUG: ARE-3548 - Nested "sources" can't be empty on POST, but can be empty in a LayerView
792 POST_WithValue_Inconsistent(l => l.sources, new Nested.Sources(), false);
793 }
794 [TestMethod, TestCategory(TypeName)]
799 [TestMethod, TestCategory(TypeName)]
801 {
802 // BUG: ARE-3553 - Inconsistency: /layers/ forbids duplicate layer references
803 // in "sources", but /layer_views/ does not.
806 }
807 [TestMethod, TestCategory(TypeName)]
809 {
810 // This is actually okay, the same layer definition can be used both as a source,
811 // and the sink that all the sources are put through. This is because even
812 // if they are passed as references, they are only used for their layer terms.
813 POST_WithValue(l => l.sources, new Nested.Sources(TestResource.sink), true);
814 }
815 [TestMethod, TestCategory(TypeName)]
817 {
818 POST_WithValue(l => l.sources, new Nested.Sources(
819 Samples.AllSaveableLayerTypesTestList.Select(s => s.AsReference)), true);
820 }
821 [TestMethod, TestCategory(TypeName)]
823 {
824 // Inlined sources are not allowed for saved layers, but are okay for layer_views
826 Samples.AllLayerTypesTestList.Select(s => s.AsInlinedReference)), false);
827 }
828 [TestMethod, TestCategory(TypeName)]
830 {
831 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
832 // LayerView references are not allowed for saved layers, but are okay for layer_views
834 Samples.AllLayerViewTypesTestList.Select(s => s.AsReference)), false);
835 }
836 #endregion sources
837 #endregion POST
838
839 #region PUT
840 #region sink
841 [TestMethod, TestCategory(TypeName)]
843 {
845 }
846 [TestMethod, TestCategory(TypeName)]
848 {
849 PUT_Attribute_Null(l => l.sink);
850 }
851 [TestMethod, TestCategory(TypeName)]
856 [TestMethod, TestCategory(TypeName)]
861 [TestMethod, TestCategory(TypeName)]
866 [TestMethod, TestCategory(TypeName)]
868 {
869 // Loop over each layer type, generate and test PUT a testResource with it.
871 .Where(l => !l.UnderlyingType.IsAttributeDefinedFast<NotSaveableAttribute>()))
872 PUT_WithValue(l => l.sink, layer.AsReference, true);
873 }
874 [TestMethod, TestCategory(TypeName)]
876 {
877 // Demonstrate that updating Nested layers with inlined sinks is disallowed.
879 PUT_WithValue(l => l.sink, layer.AsInlinedReference, false);
880 }
881 [TestMethod, TestCategory(TypeName)]
883 {
884 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
885 // While the Nested Layer can hold a layer_view reference, these cannot be saved
887 PUT_WithValue(l => l.sink, layerView.AsReference, false);
888 }
889 [TestMethod, TestCategory(TypeName)]
891 {
893 {
894 // Test invalid types as layer references
895 PUT_WithValue(l => l.sink, layer.AsReference, false);
896 // Test invalid types as inlined layer definitions
897 PUT_WithValue(l => l.sink, layer.AsInlinedReference, false);
898 }
899 }
900 #endregion sink
901
902 #region sources
903 [TestMethod, TestCategory(TypeName)]
905 {
906 PUT_WithValue(l => l.sources,
908 }
909 [TestMethod, TestCategory(TypeName)]
911 {
912 PUT_Attribute_Null(l => l.sources);
913 }
914 [TestMethod, TestCategory(TypeName)]
916 {
917 PUT_ListAttribute_Empty(l => l.sources);
918 }
919 [TestMethod, TestCategory(TypeName)]
924 [TestMethod, TestCategory(TypeName)]
930 [TestMethod, TestCategory(TypeName)]
932 {
933 PUT_WithValue(l => l.sources, new Nested.Sources(
934 Samples.AllSaveableLayerTypesTestList.Select(sample => sample.AsReference)), true);
935 }
936 [TestMethod, TestCategory(TypeName)]
938 {
939 // Demonstrate that posting Nested layers with inlined sources is disallowed.
940 PUT_WithValue(l => l.sources, new Nested.Sources(
941 Samples.AllLayerTypesTestList.Select(sample => sample.AsInlinedReference)), false);
942 }
943 [TestMethod, TestCategory(TypeName)]
945 {
946 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
947 // Demonstrate that posting Nested layer_view references is disallowed.
948 PUT_WithValue(l => l.sources, new Nested.Sources(
949 Samples.AllLayerViewTypesTestList.Select(s => s.AsReference)), false);
950 }
951 #endregion sources
952 #endregion PUT
953 }
954
955 [TestClass]
957 {
958 #region Set Up and Configuration
959 private const string TypeName = "Filter";
962 #endregion Set Up and Configuration
963
964 #region POST
965 #region Test Invert
966 [TestMethod, TestCategory(TypeName)]
968 {
969 POST_WithValue(l => l.invert, true, true);
970 }
971 #endregion Test Invert
972
973 #region Test Filters
974 [TestMethod, TestCategory(TypeName)]
976 {
977 POST_WithValue(l => l.filters, new List<IReference<LossFilter>> {
978 Samples.LossFilter_GTFilter.AsReference }, true);
979 }
980
981 [TestMethod, TestCategory(TypeName)]
983 {
984 POST_Attribute_Null(l => l.filters);
985 }
986
987 [TestMethod, TestCategory(TypeName)]
989 {
990 //POST_ReferenceList_NonExistantId(l => l.filters);
991 POST_WithValue(l => l.filters, new List<IReference<LossFilter>> {
992 new Reference<LossFilter>(Samples.Valid_NonExistant_UUID) }, false);
993 }
994
995 [TestMethod, TestCategory(TypeName)]
997 {
998 POST_WithValue(l => l.filters, new List<IReference<LossFilter>>(), true);
999 //POST_ListAttribute_Empty(l => l.filters);
1000 }
1001
1002 // After ARE-7829 implementation, the following two tests were failing in the base class
1003 // An override was added here to correctly handle the updated API logic.
1004 [TestMethod, TestCategory(TypeName)]
1005 public override void Test_Resource_POST_FieldsIdOnly()
1006 {
1007 GenericTest.POST_ValidResource(TestResource);
1008 }
1009
1010 [TestMethod, TestCategory(TypeName)]
1011 public override void Test_Resource_POST_Valid()
1012 {
1013 // Only in this base test - confirm that a layer with this type cannot be posted
1014 GenericTest.POST_ValidResource(TestResource);
1015 // Now test that it can be posted as part of a layer_view
1016 TestSuite_Layer_Base.TestLayerInLayerView(TestResource, true);
1017 }
1018
1019 #endregion Test Filters
1020 #endregion POST
1021
1022 #region PUT
1023 /* PUT Tests are disabled until there is some way to save these layers
1024 #region Test Invert
1025 [TestMethod, TestCategory(TypeName)]
1026 public void Test_Layer_Filter_PUT_Invert()
1027 {
1028 PUT_WithValue(l => l.invert, true, true);
1029 }
1030 #endregion Test Invert
1031
1032 #region Test Filters
1033 [TestMethod, TestCategory(TypeName)]
1034 public void Test_Layer_Filter_PUT_Filters()
1035 {
1036 PUT_WithValue(l => l.filters, new List<IReference<LossFilter>> {
1037 Samples.LossFilter_GTFilter.AsReference }, true);
1038 }
1039
1040 [TestMethod, TestCategory(TypeName)]
1041 public void Test_Layer_Filter_PUT_Filters_NonExistantId()
1042 {
1043 PUT_ReferenceList_NonExistantId(l => l.filters);
1044 }
1045
1046 [TestMethod, TestCategory(TypeName)]
1047 public void Test_Layer_Filter_PUT_Filters_Empty()
1048 {
1049 PUT_ListAttribute_Empty(l => l.filters);
1050 }
1051 #endregion Test Filters
1052 */
1053 #endregion PUT
1054 }
1055
1056 [TestClass]
1058 : TestSuite_Layer_Unsaveable<FixedRateCurrencyConverter>
1059 {
1060 #region Set Up and Configuration
1061 private const string TypeName = "FixedRateCurrencyConverter";
1064 #endregion Set Up and Configuration
1065
1066 #region POST
1067 #region in_currency
1068 [TestMethod, TestCategory(TypeName)]
1073
1074 [TestMethod, TestCategory(TypeName)]
1076 {
1077 //POST_StringAttribute_Empty(l => l.in_currency);
1078 POST_WithValue(l => l.in_currency, "", false);
1079 }
1080 [TestMethod, TestCategory(TypeName)]
1082 {
1083 POST_WithValue(l => l.in_currency, "AU", false);
1084 }
1085 [TestMethod, TestCategory(TypeName)]
1087 {
1088 POST_WithValue(l => l.in_currency, "asdf", false);
1089 }
1090 [TestMethod, TestCategory(TypeName)]
1092 {
1093 POST_WithValue(l => l.in_currency, "EUR", true);
1094 }
1095 [TestMethod, TestCategory(TypeName)]
1097 {
1098 // This is a valid ISO currency code, but it's not in the exchange rate table,
1099 // and doesn't match the underlying loss set currency, so we expect a
1100 // BadRequest error due to a missing exchange rate.
1101 POST_WithValue(l => l.in_currency, "AED", false);
1102 }
1103 [TestMethod, TestCategory(TypeName)]
1105 {
1107 Assert.Inconclusive("RUN_OFFLINE = true");
1108 // For simplicity, we'll just modify a copy of a sample ELT loss set that already has data.
1109 ELTLossSet lossSet = Samples.LossSet_ELTLossSet.Posted
1110 .Change(ls => ls.currency, "AAA").Post().PollUntilReady(Samples.DataPollingOptions);
1111 // This is NOT a valid ISO currency code, but the system should allow it as long as the
1112 // underlying loss set has the same currency code (thereby requiring no automatic conversion)
1113 FixedRateCurrencyConverter toTest = Samples.Layer_FixedRateCurrencyConverter.Unposted
1114 .Change(layer => layer.in_currency, "AAA")
1115 .Change(layer => layer.loss_sets, new List<IReference<LossSet>> { lossSet.ToReference() });
1116 TestSuite_Layer_Base.TestLayerInLayerView(toTest, true);
1117 // TODO: Use this instead when layer is saveable
1118 // POST_ThenDoAction(toTest, AdditionalValidResourceTests);
1119 }
1120 #endregion in_currency
1121
1122 #region out_currency
1123 [TestMethod, TestCategory(TypeName)]
1128
1129 [TestMethod, TestCategory(TypeName)]
1131 {
1132 //POST_StringAttribute_Empty(l => l.out_currency);
1133 POST_WithValue(l => l.out_currency, "", false);
1134 }
1135 [TestMethod, TestCategory(TypeName)]
1137 {
1138 POST_WithValue(l => l.out_currency, "AU", false);
1139 }
1140 [TestMethod, TestCategory(TypeName)]
1142 {
1143 POST_WithValue(l => l.out_currency, "asdf", false);
1144 }
1145 [TestMethod, TestCategory(TypeName)]
1147 {
1148 POST_WithValue(l => l.out_currency, "EUR", true);
1149 }
1150 [TestMethod, TestCategory(TypeName)]
1152 {
1153 POST_WithValue(l => l.out_currency, "AAA", true);
1154 }
1155 #endregion out_currency
1156
1157 #region rate
1158 [TestMethod, TestCategory(TypeName)]
1160 {
1161 POST_WithValue(l => l.rate, 1.23, true);
1162 }
1163
1164 [TestMethod, TestCategory(TypeName)]
1166 {
1167 POST_WithValue(l => l.rate, 0, true);
1168 }
1169
1170 [TestMethod, TestCategory(TypeName)]
1172 {
1173 POST_WithValue(l => l.rate, -1.23, true);
1174 }
1175 #endregion rate
1176 #endregion POST
1177
1178 #region PUT
1179 /* PUT Tests are disabled until there is some way to save these layers
1180 #region in_currency
1181 [TestMethod, TestCategory(TypeName)]
1182 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_Null()
1183 {
1184 PUT_Attribute_Null(l => l.in_currency);
1185 }
1186
1187 [TestMethod, TestCategory(TypeName)]
1188 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_Empty()
1189 {
1190 PUT_StringAttribute_Empty(l => l.in_currency);
1191 }
1192 [TestMethod, TestCategory(TypeName)]
1193 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_TooShort()
1194 {
1195 PUT_WithValue(l => l.in_currency, "AU", shouldSucceed: false);
1196 }
1197 [TestMethod, TestCategory(TypeName)]
1198 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_TooLong()
1199 {
1200 PUT_WithValue(l => l.in_currency, "asdf", shouldSucceed: false);
1201 }
1202 [TestMethod, TestCategory(TypeName)]
1203 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_ValidISO()
1204 {
1205 PUT_WithValue(l => l.in_currency, "EUR", shouldSucceed: true);
1206 }
1207 [TestMethod, TestCategory(TypeName)]
1208 public void Test_Layer_FixedRateCurrencyConverter_PUT_InCurrency_InvalidISO()
1209 {
1210 PUT_WithValue(l => l.in_currency, "AAA", shouldSucceed: true);
1211 }
1212 #endregion in_currency
1213
1214 #region out_currency
1215 [TestMethod, TestCategory(TypeName)]
1216 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_Null()
1217 {
1218 PUT_Attribute_Null(l => l.out_currency);
1219 }
1220
1221 [TestMethod, TestCategory(TypeName)]
1222 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_Empty()
1223 {
1224 PUT_StringAttribute_Empty(l => l.out_currency);
1225 }
1226 [TestMethod, TestCategory(TypeName)]
1227 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_TooShort()
1228 {
1229 PUT_WithValue(l => l.out_currency, "AU", shouldSucceed: false);
1230 }
1231 [TestMethod, TestCategory(TypeName)]
1232 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_TooLong()
1233 {
1234 PUT_WithValue(l => l.out_currency, "asdf", shouldSucceed: false);
1235 }
1236 [TestMethod, TestCategory(TypeName)]
1237 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_ValidISO()
1238 {
1239 PUT_WithValue(l => l.out_currency, "EUR", shouldSucceed: true);
1240 }
1241 [TestMethod, TestCategory(TypeName)]
1242 public void Test_Layer_FixedRateCurrencyConverter_PUT_OutCurrency_InvalidISO()
1243 {
1244 PUT_WithValue(l => l.out_currency, "AAA", shouldSucceed: true);
1245 }
1246 #endregion out_currency
1247
1248 #region rate
1249 [TestMethod, TestCategory(TypeName)]
1250 public void Test_Layer_FixedRateCurrencyConverter_PUT_Rate()
1251 {
1252 PUT_WithValue(l => l.rate, 1.23, shouldSucceed: true);
1253 }
1254
1255 [TestMethod, TestCategory(TypeName)]
1256 public void Test_Layer_FixedRateCurrencyConverter_PUT_Rate_Zero()
1257 {
1258 PUT_WithValue(l => l.rate, 0, shouldSucceed: true);
1259 }
1260
1261 [TestMethod, TestCategory(TypeName)]
1262 public void Test_Layer_FixedRateCurrencyConverter_PUT_Rate_Negative()
1263 {
1264 PUT_WithValue(l => l.rate, -1.23, shouldSucceed: true);
1265 }
1266 #endregion rate
1267 */
1268 #endregion PUT
1269 }
1270
1271 [TestClass]
1273 {
1274 #region Set Up and Configuration
1275 private const string TypeName = "LossRank";
1278 #endregion Set Up and Configuration
1279
1280 #region POST
1281 #region Test Invert
1282 [TestMethod, TestCategory(TypeName)]
1284 {
1285 POST_WithValue(l => l.invert, true, true);
1286 }
1287 #endregion Test Invert
1288
1289 #region Test Count
1290 [TestMethod, TestCategory(TypeName)]
1292 {
1293 POST_WithValue(l => l.count, 100, true);
1294 }
1295 [TestMethod, TestCategory(TypeName)]
1297 {
1298 POST_WithValue(l => l.count, Int32.MaxValue, true);
1299 }
1300 [TestMethod, TestCategory(TypeName)]
1302 {
1303 POST_WithValue(l => l.count, 0, true);
1304 }
1305 [TestMethod, TestCategory(TypeName)]
1307 {
1308 POST_WithValue(l => l.count, Int32.MinValue, false);
1309 }
1310 #endregion Test Count
1311
1312 #region Test Criterion
1313 // TODO: Uncomment when criterion is fixed (ARE-6251 for context)
1314 // [TestMethod, TestCategory(TypeName)]
1315 // public void Test_Layer_LossRank_POST_Criterion()
1316 // {
1317 // POST_WithValue(l => l.criterion, LossRank.Criterion.SmallestLoss, true);
1318 // }
1319
1320 // TODO: Uncomment when criterion is fixed (ARE-6251 for context)
1321 // [TestMethod, TestCategory(TypeName)]
1322 // public void Test_Layer_LossRank_POST_Criterion_Unknown()
1323 // {
1324 // POST_WithValue(l => l.criterion, (LossRank.Criterion)0xff, false);
1325 // }
1326 #endregion Test Criterion
1327 #endregion POST
1328
1329 #region PUT
1330 #region Test Invert
1331 [TestMethod, TestCategory(TypeName)]
1333 {
1334 PUT_WithValue(l => l.invert, true, true);
1335 }
1336 #endregion Test Invert
1337
1338 #region Test Count
1339 [TestMethod, TestCategory(TypeName)]
1341 {
1342 PUT_WithValue(l => l.count, 100, true);
1343 }
1344 [TestMethod, TestCategory(TypeName)]
1346 {
1347 PUT_WithValue(l => l.count, Int32.MaxValue, true);
1348 }
1349 [TestMethod, TestCategory(TypeName)]
1351 {
1352 PUT_WithValue(l => l.count, Int32.MinValue, false);
1353 }
1354 #endregion Test Count
1355
1356 #region Test Criterion
1357 // TODO: Uncomment when criterion is fixed (ARE-6251 for context)
1358 // [TestMethod, TestCategory(TypeName)]
1359 // public void Test_Layer_LossRank_PUT_Criterion()
1360 // {
1361 // PUT_WithValue(l => l.criterion, LossRank.Criterion.SmallestLoss, true);
1362 // }
1363
1364 // TODO: Uncomment when criterion is fixed (ARE-6251 for context)
1365 // [TestMethod, TestCategory(TypeName)]
1366 // public void Test_Layer_LossRank_PUT_Criterion_Unknown()
1367 // {
1368 // PUT_WithValue(l => l.criterion, (LossRank.Criterion)0xff, false);
1369 // }
1370 #endregion Test Criterion
1371 #endregion PUT
1372 }
1373
1374 [TestClass]
1376 {
1377 #region Set Up and Configuration
1378 private const string TypeName = "NoClaimsBonus";
1381 #endregion Set Up and Configuration
1382
1383 #region POST
1384 #region payout_amount
1385 [TestMethod, TestCategory(TypeName)]
1387 {
1388 POST_Attribute_Null(l => l.payout_amount);
1389 }
1390
1391 [TestMethod, TestCategory(TypeName)]
1393 {
1394 POST_WithValue(l => l.payout_amount, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
1395 }
1396 #endregion payout_amount
1397
1398 #region payout_date
1399 [TestMethod, TestCategory(TypeName)]
1401 {
1402 POST_WithValue(l => l.payout_date, null, false);
1403 }
1404
1405 [TestMethod, TestCategory(TypeName)]
1407 {
1408 POST_WithValue(l => l.payout_date, DateTime.UtcNow, true);
1409 }
1410
1411 [TestMethod, TestCategory(TypeName)]
1413 {
1414 POST_WithValue(l => l.payout_date,
1415 new DateTime(DateTime.MinValue.Ticks, DateTimeKind.Utc), true);
1416 }
1417
1418 [TestMethod, TestCategory(TypeName)]
1420 {
1421 POST_WithValue(l => l.payout_date,
1422 new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc), true);
1423 }
1424 #endregion payout_date
1425 #endregion POST
1426
1427 #region PUT
1428 #region payout_amount
1429 [TestMethod, TestCategory(TypeName)]
1431 {
1432 PUT_Attribute_Null(l => l.payout_amount);
1433 }
1434
1435 [TestMethod, TestCategory(TypeName)]
1437 {
1438 PUT_WithValue(l => l.payout_amount, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
1439 }
1440 #endregion payout_amount
1441
1442 #region payout_date
1443 [TestMethod, TestCategory(TypeName)]
1445 {
1446 PUT_WithValue(l => l.payout_date, null, false);
1447 }
1448
1449 [TestMethod, TestCategory(TypeName)]
1451 {
1452 PUT_WithValue(l => l.payout_date,
1453 TestResource.payout_date.Value.Subtract(new TimeSpan(0, 0, 0, 1)), true);
1454 }
1455
1456 [TestMethod, TestCategory(TypeName)]
1458 {
1459 PUT_WithValue(l => l.payout_date,
1460 new DateTime(DateTime.MinValue.Ticks, DateTimeKind.Utc), true);
1461 }
1462
1463 [TestMethod, TestCategory(TypeName)]
1465 {
1466 PUT_WithValue(l => l.payout_date,
1467 new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc), true);
1468 }
1469 #endregion payout_date
1470 #endregion PUT
1471 }
1472
1473 [TestClass]
1474 public sealed class TestSuite_Layer_ValueAllocator : TestSuite_Layer<ValueAllocator>
1475 {
1476 #region Set Up and Configuration
1477 private const string TypeName = "ValueAllocator";
1480 #endregion Set Up and Configuration
1481
1482 #region POST
1483 #region source
1484 [TestMethod, TestCategory(TypeName)]
1486 {
1487 POST_Attribute_Null(l => l.source);
1488 }
1489 [TestMethod, TestCategory(TypeName)]
1491 {
1492 //POST_Reference_NullId(l => l.source);
1493 IReference<ILayer> reference = new Reference<Layer>((string)null);
1494 POST_WithValue(l => l.source, reference, false);
1495 }
1496 [TestMethod, TestCategory(TypeName)]
1498 {
1499 //POST_Reference_EmptyStringId(l => l.source);
1501 POST_WithValue(l => l.source, reference, false);
1502 }
1503 [TestMethod, TestCategory(TypeName)]
1505 {
1506 //POST_Reference_NonExistantId(l => l.source);
1508 POST_WithValue(l => l.source, reference, false);
1509 }
1510 [TestMethod, TestCategory(TypeName)]
1512 {
1513 // Loop over each layer type, generate and test POST a testResource with it.
1515 POST_WithValue(l => l.source, layer.AsReference, true);
1516 }
1517 [TestMethod, TestCategory(TypeName)]
1519 {
1520 // While the ValueAllocator can hold an inlined layer definition,
1521 // these are only allowed when posting as a layer_view, not a layer.
1523 POST_WithValue_Inconsistent(l => l.source, layer.AsInlinedReference, false);
1524 }
1525 [TestMethod, TestCategory(TypeName)]
1527 {
1528 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1529 // While the ValueAllocator can hold a layer_view reference,
1530 // these are only allowed when posting as a layer_view, not a layer.
1532 POST_WithValue_Inconsistent(l => l.source, layerView.AsReference, false);
1533 }
1534 #endregion source
1535
1536 #region target
1537 [TestMethod, TestCategory(TypeName)]
1539 {
1540 POST_Attribute_Null(l => l.target);
1541 }
1542 [TestMethod, TestCategory(TypeName)]
1544 {
1545 //POST_Reference_NullId(l => l.target);
1546 IReference<ILayer> reference = new Reference<Layer>((string)null);
1547 POST_WithValue(l => l.target, reference, false);
1548 }
1549 [TestMethod, TestCategory(TypeName)]
1551 {
1552 //POST_Reference_EmptyStringId(l => l.target);
1554 POST_WithValue(l => l.target, reference, false);
1555 }
1556 [TestMethod, TestCategory(TypeName)]
1558 {
1559 //POST_Reference_NonExistantId(l => l.target);
1561 POST_WithValue(l => l.target, reference, false);
1562 }
1563 [TestMethod, TestCategory(TypeName)]
1565 {
1566 // Loop over each layer type, generate and test POST a testRetarget with it.
1568 POST_WithValue(l => l.target, layer.AsReference, true);
1569 }
1570 [TestMethod, TestCategory(TypeName)]
1572 {
1573 // Demonstrate that posting Nested layers with inlined targets is disallowed.
1575 POST_WithValue_Inconsistent(l => l.target, layer.AsInlinedReference, false);
1576 }
1577 [TestMethod, TestCategory(TypeName)]
1579 {
1580 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1581 // While the ValueAllocator can hold a layer_view reference,
1582 // these are only allowed when posting as a layer_view, not a layer.
1584 POST_WithValue_Inconsistent(l => l.target, layerView.AsReference, false);
1585 }
1586 #endregion target
1587
1588 #region group
1589 [TestMethod, TestCategory(TypeName)]
1591 {
1592 POST_Attribute_Null(l => l.group);
1593 }
1594 [TestMethod, TestCategory(TypeName)]
1596 {
1597 //POST_Reference_NullId(l => l.group);
1598 IReference<ILayer> reference = new Reference<Layer>((string)null);
1599 POST_WithValue(l => l.group, reference, false);
1600 }
1601 [TestMethod, TestCategory(TypeName)]
1603 {
1604 //POST_Reference_EmptyStringId(l => l.group);
1606 POST_WithValue(l => l.group, reference, false);
1607 }
1608 [TestMethod, TestCategory(TypeName)]
1610 {
1611 //POST_Reference_NonExistantId(l => l.group);
1613 POST_WithValue(l => l.group, reference, false);
1614 }
1615 [TestMethod, TestCategory(TypeName)]
1617 {
1618 // Loop over each layer type, generate and test POST a testRegroup with it.
1620 POST_WithValue(l => l.group, layer.AsReference, true);
1621 }
1622 [TestMethod, TestCategory(TypeName)]
1624 {
1625 // Demonstrate that posting Nested layers with inlined groups is disallowed.
1627 POST_WithValue_Inconsistent(l => l.group, layer.AsInlinedReference, false);
1628 }
1629 [TestMethod, TestCategory(TypeName)]
1631 {
1632 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1633 // While the ValueAllocator can hold a layer_view reference,
1634 // these are only allowed when posting as a layer_view, not a layer.
1636 POST_WithValue_Inconsistent(l => l.group, layerView.AsReference, false);
1637 }
1638 #endregion group
1639
1640 #region allocation_perspectives
1641 [TestMethod, TestCategory(TypeName)]
1643 {
1644 POST_Attribute_Null(l => l.allocation_perspectives);
1645 }
1646 [TestMethod, TestCategory(TypeName)]
1648 {
1649 POST_ListAttribute_Empty(l => l.allocation_perspectives);
1650 }
1651 [TestMethod, TestCategory(TypeName)]
1653 {
1654 POST_ListAttribute_Duplicates(l => l.allocation_perspectives,
1655 ValueAllocator.Perspective.LossNetOfAggregateTerms, false);
1656 }
1657 [TestMethod, TestCategory(TypeName)]
1659 {
1660 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms }, true);
1661 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementPremium }, true);
1662 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1663 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms, ValueAllocator.Perspective.ReinstatementPremium }, true);
1664 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1665 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementPremium, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1666 POST_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms,
1667 ValueAllocator.Perspective.ReinstatementPremium, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1668 }
1669 #endregion allocation_perspectives
1670
1671 #region proportioned_perspective
1672 [TestMethod, TestCategory(TypeName)]
1674 {
1675 POST_Attribute_Null(l => l.proportioned_perspective);
1676 }
1677 [TestMethod, TestCategory(TypeName)]
1679 {
1680 POST_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.LossNetOfAggregateTerms, true);
1681 POST_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.ReinstatementPremium, true);
1682 POST_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.ReinstatementBrokerage, true);
1683 }
1684 #endregion proportioned_perspective
1685
1686 #region allocation_ratio_basis
1687 [TestMethod, TestCategory(TypeName)]
1689 {
1690 POST_Attribute_Null(l => l.allocation_ratio_basis);
1691 }
1692 [TestMethod, TestCategory(TypeName)]
1694 {
1695 POST_WithValue(l => l.allocation_ratio_basis, ValueAllocator.AllocationRatioBasis.PerEvent, true);
1696 POST_WithValue(l => l.allocation_ratio_basis, ValueAllocator.AllocationRatioBasis.PerTrial, true);
1697 }
1698 #endregion allocation_ratio_basis
1699 #endregion POST
1700
1701 #region PUT
1702 #region source
1703 [TestMethod, TestCategory(TypeName)]
1705 {
1707 }
1708 [TestMethod, TestCategory(TypeName)]
1710 {
1711 PUT_Attribute_Null(l => l.source);
1712 }
1713 [TestMethod, TestCategory(TypeName)]
1718 [TestMethod, TestCategory(TypeName)]
1723 [TestMethod, TestCategory(TypeName)]
1728 [TestMethod, TestCategory(TypeName)]
1730 {
1731 // Loop over each layer type, generate and test PUT a testResource with it.
1733 PUT_WithValue(l => l.source, layer.AsReference, true);
1734 }
1735 [TestMethod, TestCategory(TypeName)]
1737 {
1738 // Demonstrate that updating Nested layers with inlined sources is disallowed.
1740 PUT_WithValue(l => l.source, layer.AsInlinedReference, false);
1741 }
1742 [TestMethod, TestCategory(TypeName)]
1744 {
1745 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1746 // While the ValueAllocator can hold a layer_view reference,
1747 // these are only allowed when updating as a layer_view, not a layer.
1749 PUT_WithValue(l => l.source, layerView.AsReference, false);
1750 }
1751 #endregion source
1752
1753 #region target
1754 [TestMethod, TestCategory(TypeName)]
1756 {
1758 }
1759 [TestMethod, TestCategory(TypeName)]
1761 {
1762 PUT_Attribute_Null(l => l.target);
1763 }
1764 [TestMethod, TestCategory(TypeName)]
1769 [TestMethod, TestCategory(TypeName)]
1774 [TestMethod, TestCategory(TypeName)]
1779 [TestMethod, TestCategory(TypeName)]
1781 {
1782 // Loop over each layer type, generate and test PUT a testRetarget with it.
1784 PUT_WithValue(l => l.target, layer.AsReference, true);
1785 }
1786 [TestMethod, TestCategory(TypeName)]
1788 {
1789 // Demonstrate that updating Nested layers with inlined targets is disallowed.
1791 PUT_WithValue(l => l.target, layer.AsInlinedReference, false);
1792 }
1793 [TestMethod, TestCategory(TypeName)]
1795 {
1796 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1797 // While the ValueAllocator can hold a layer_view reference,
1798 // these are only allowed when updating as a layer_view, not a layer.
1800 PUT_WithValue(l => l.target, layerView.AsReference, false);
1801 }
1802 #endregion target
1803
1804 #region group
1805 [TestMethod, TestCategory(TypeName)]
1810 [TestMethod, TestCategory(TypeName)]
1812 {
1813 PUT_Attribute_Null(l => l.group);
1814 }
1815 [TestMethod, TestCategory(TypeName)]
1820 [TestMethod, TestCategory(TypeName)]
1825 [TestMethod, TestCategory(TypeName)]
1830 [TestMethod, TestCategory(TypeName)]
1832 {
1833 // Loop over each layer type, generate and test PUT a testRegroup with it.
1835 PUT_WithValue(l => l.group, layer.AsReference, true);
1836 }
1837 [TestMethod, TestCategory(TypeName)]
1839 {
1840 // Demonstrate that updating Nested layers with inlined groups is disallowed.
1842 PUT_WithValue(l => l.group, layer.AsInlinedReference, false);
1843 }
1844 [TestMethod, TestCategory(TypeName)]
1846 {
1847 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
1848 // While the ValueAllocator can hold a layer_view reference,
1849 // these are only allowed when updating as a layer_view, not a layer.
1851 PUT_WithValue(l => l.group, layerView.AsReference, false);
1852 }
1853 #endregion group
1854
1855 #region allocation_perspectives
1856 [TestMethod, TestCategory(TypeName)]
1858 {
1859 PUT_Attribute_Null(l => l.allocation_perspectives);
1860 }
1861 [TestMethod, TestCategory(TypeName)]
1863 {
1864 PUT_ListAttribute_Empty(l => l.allocation_perspectives);
1865 }
1866 [TestMethod, TestCategory(TypeName)]
1868 {
1869 PUT_ListAttribute_Duplicates(l => l.allocation_perspectives,
1870 ValueAllocator.Perspective.LossNetOfAggregateTerms, false);
1871 }
1872 [TestMethod, TestCategory(TypeName)]
1874 {
1875 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms }, true);
1876 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementPremium }, true);
1877 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1878 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms, ValueAllocator.Perspective.ReinstatementPremium }, true);
1879 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1880 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.ReinstatementPremium, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1881 PUT_WithValue(l => l.allocation_perspectives, new[] { ValueAllocator.Perspective.LossNetOfAggregateTerms,
1882 ValueAllocator.Perspective.ReinstatementPremium, ValueAllocator.Perspective.ReinstatementBrokerage }, true);
1883 }
1884 #endregion allocation_perspectives
1885
1886 #region proportioned_perspective
1887 [TestMethod, TestCategory(TypeName)]
1889 {
1890 PUT_Attribute_Null(l => l.proportioned_perspective);
1891 }
1892 [TestMethod, TestCategory(TypeName)]
1894 {
1895 PUT_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.LossNetOfAggregateTerms, true);
1896 PUT_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.ReinstatementPremium, true);
1897 PUT_WithValue(l => l.proportioned_perspective, ValueAllocator.Perspective.ReinstatementBrokerage, true);
1898 }
1899 #endregion proportioned_perspective
1900
1901 #region allocation_ratio_basis
1902 [TestMethod, TestCategory(TypeName)]
1904 {
1905 PUT_Attribute_Null(l => l.allocation_ratio_basis);
1906 }
1907 [TestMethod, TestCategory(TypeName)]
1909 {
1910 PUT_WithValue(l => l.allocation_ratio_basis, ValueAllocator.AllocationRatioBasis.PerEvent, true);
1911 PUT_WithValue(l => l.allocation_ratio_basis, ValueAllocator.AllocationRatioBasis.PerTrial, true);
1912 }
1913 #endregion allocation_ratio_basis
1914 #endregion PUT
1915 }
1916
1917 [TestClass]
1918 public sealed class TestSuite_Layer_BackAllocatedLayer : TestSuite_Layer<BackAllocatedLayer>
1919 {
1920 #region Set Up and Configuration
1921 private const string TypeName = "BackAllocatedLayer";
1924 #endregion Set Up and Configuration
1925
1926 #region Test Helpers
1930
1933 Samples.AllLayerTypesTestList.Where(i => !UnsupportedBackAllocatedLayerSinkTypes.Contains(i.UnderlyingType));
1934
1937 Samples.AllLayerTypesTestList.Where(i => UnsupportedBackAllocatedLayerSinkTypes.Contains(i.UnderlyingType));
1938 #endregion Test Helpers
1939
1940 #region POST
1941 #region sink
1942 [TestMethod, TestCategory(TypeName)]
1944 {
1945 POST_Attribute_Null(l => l.sink);
1946 }
1947 [TestMethod, TestCategory(TypeName)]
1949 {
1950 //POST_Reference_NullId(l => l.sink);
1951 IReference<ILayer> reference = new Reference<Layer>((string)null);
1952 POST_WithValue(l => l.sink, reference, false);
1953 }
1954 [TestMethod, TestCategory(TypeName)]
1956 {
1957 //POST_Reference_EmptyStringId(l => l.sink);
1959 POST_WithValue(l => l.sink, reference, false);
1960 }
1961 [TestMethod, TestCategory(TypeName)]
1963 {
1964 //POST_Reference_NonExistantId(l => l.sink);
1966 POST_WithValue(l => l.sink, reference, false);
1967 }
1968 [TestMethod, TestCategory(TypeName)]
1970 {
1971 // While the BackAllocatedLayer can hold an inlined layer definition,
1972 // these are only allowed when posting as a layer_view, not a layer.
1974 {
1975 // First, test having with this type of layer definition inlined
1976 IReference<ILayer> newSink = layer.AsInlinedReference;
1977 BackAllocatedLayer ofCurrentType = TestResource.Change(l => l.sink, newSink)
1978 // We must also change the source_id to match something within the sink.
1979 .Change(l => l.source_id, Reflection.PickBackAllocatedLayerSourceId(newSink));
1980 // Saving to "/layers/" will always fail, because inlining is not allowed
1981 GenericTest.POST_InvalidResource_Fails(ofCurrentType);
1982 // But posting as a layer_view should succeed.
1983 TestSuite_Layer_Base.TestLayerInLayerView(ofCurrentType, true);
1984
1985 // If this layer type is saveable, test again using a saved layer reference of this type
1986 if (layer.UnderlyingType.IsAttributeDefinedFast<NotSaveableAttribute>())
1987 {
1988 Console.WriteLine("Skipping sink layer reference test of un-saveable layer type " +
1989 layer.UnderlyingType.NiceTypeName());
1990 continue;
1991 }
1992
1993 newSink = layer.AsReference;
1994 ofCurrentType = ofCurrentType.Change(l => l.sink, newSink)
1995 .Change(l => l.source_id, Reflection.PickBackAllocatedLayerSourceId(newSink));
1996 // Test that the resource can be posted as a layer, and a layer_view
1997 POST_ThenDoAction(ofCurrentType, AdditionalValidResourceTests);
1998 }
1999 }
2000 [TestMethod, TestCategory(TypeName)]
2002 {
2003 Skip.Indefinitely("ARE-7212: BackAllocating Payment Patterns cause Internal Server Errors");
2004 // While the BackAllocatedLayer can hold an inlined layer definition,
2005 // these are only allowed when posting as a layer_view, not a layer.
2007 {
2008 // First, test having with this type of layer definition inlined
2009 IReference<ILayer> newSink = layer.AsInlinedReference;
2010 BackAllocatedLayer ofCurrentType = TestResource.Change(l => l.sink, newSink)
2011 // We must also change the source_id to match something within the sink.
2012 .Change(l => l.source_id, Reflection.PickBackAllocatedLayerSourceId(newSink));
2013
2014 // Saving to "/layers/" will always fail, because inlining is not allowed
2015 GenericTest.POST_InvalidResource_Fails(ofCurrentType);
2016 // Posting as a layer_view should always fail if this type is not allowed.
2017 // BUG ARE-7212 Causes an Internal Server Error rather than a BadRequest
2018 TestSuite_Layer_Base.TestLayerInLayerView(ofCurrentType, false);
2019
2020 // If this layer type is saveable, test again using a saved layer reference of this type
2021 if (layer.UnderlyingType.IsAttributeDefinedFast<NotSaveableAttribute>())
2022 {
2023 Console.WriteLine("Skipping sink layer reference test of un-saveable layer type " +
2024 layer.UnderlyingType.NiceTypeName());
2025 continue;
2026 }
2027
2028 newSink = layer.AsReference;
2029 ofCurrentType = ofCurrentType.Change(l => l.sink, newSink)
2030 .Change(l => l.source_id, Reflection.PickBackAllocatedLayerSourceId(newSink));
2031 // BUG ARE-7212 - this is not validated on the API, so this POST is allowed
2032 GenericTest.POST_InvalidResource_Fails(ofCurrentType);
2033 }
2034 }
2035 [TestMethod, TestCategory(TypeName)]
2037 {
2038 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
2039 // While the BackAllocatedLayer sink can hold a layer_view reference, these cannot be saved
2041 POST_WithValue_Inconsistent(l => l.sink, layerView.AsReference, false);
2042 }
2043 #endregion sink
2044
2045 #region source_id
2046 [TestMethod, TestCategory(TypeName)]
2048 {
2049 POST_WithValue(a => a.source_id,
2050 // Try setting the source to a loss set id
2051 // which is known to be part of our sink layer definition
2052 Samples.Layer_CatXL.Unposted.loss_sets.First().ref_id, true);
2053 }
2054
2055 [TestMethod, TestCategory(TypeName)]
2057 {
2058 POST_Attribute_Null(a => a.source_id);
2059 }
2060
2061 [TestMethod, TestCategory(TypeName)]
2063 {
2064 POST_StringAttribute_Empty(a => a.source_id);
2065 }
2066
2067 [TestMethod, TestCategory(TypeName)]
2069 {
2070 POST_WithValue(a => a.source_id, "Not_A_UUID", false);
2071 }
2072
2073 [TestMethod, TestCategory(TypeName)]
2075 {
2076 // In invalid source id can be referenced when persisting this layer,
2077 // only upon submission for Analytics is it known that the id is invalid.
2078 POST_WithValue_Inconsistent(a => a.source_id,
2080 }
2081 #endregion source_id
2082 #endregion POST
2083
2084 #region PUT
2085 #region sink
2086 [TestMethod, TestCategory(TypeName)]
2091 [TestMethod, TestCategory(TypeName)]
2093 {
2094 PUT_Attribute_Null(l => l.sink);
2095 }
2096 [TestMethod, TestCategory(TypeName)]
2101 [TestMethod, TestCategory(TypeName)]
2106 [TestMethod, TestCategory(TypeName)]
2111 [TestMethod, TestCategory(TypeName)]
2113 {
2114 // Used to restore back-allocated layers to a valid definition once we're done testing.
2115 IReference<ILayerSource> originalSink = TestResource.sink;
2116
2117 // Loop over each layer type, generate and test using a reference
2119 .Where(l => !l.UnderlyingType.IsAttributeDefinedFast<NotSaveableAttribute>()))
2120 {
2121 BackAllocatedLayer created = PUT_WithValue(l => l.sink, layer.AsReference, true);
2122 // Clean up: put the sink back to the original value (compatible with source_id)
2123 // So that we aren't abandoning saved resources on the test server that are invalid.
2124 created.Change(l => l.sink, originalSink).Put();
2125 }
2126 }
2127 [TestMethod, TestCategory(TypeName)]
2129 {
2130 // BUG ARE-7212 - this is not validated on the API, so this PUT is allowed
2131 Skip.Indefinitely("ARE-7212: BackAllocating Payment Patterns cause Internal Server Errors");
2132 // Loop over each layer type, and ensure that PUT references to invalid types are forbidden
2134 PUT_WithValue(l => l.sink, layer.AsReference, false);
2135 }
2136 [TestMethod, TestCategory(TypeName)]
2138 {
2139 // Demonstrate that updating Nested layers with inlined sources is disallowed.
2141 PUT_WithValue(l => l.sink, layer.AsInlinedReference, false);
2142 }
2143 [TestMethod, TestCategory(TypeName)]
2145 {
2146 Skip.UntilRelease.Validation("ARE-6190: Referenced LayerViews cause Internal Server Error");
2147 // While the BackAllocatedLayer can hold a layer_view reference, these cannot be saved
2149 PUT_WithValue(l => l.sink, layerView.AsReference, false);
2150 }
2151 #endregion sink
2152
2153 #region source_id
2154 [TestMethod, TestCategory(TypeName)]
2156 {
2157 PUT_WithValue(a => a.source_id,
2158 Samples.Layer_CatXL.Unposted.loss_sets.First().ref_id, true);
2159 }
2160
2161 [TestMethod, TestCategory(TypeName)]
2163 {
2164 PUT_Attribute_Null(a => a.source_id);
2165 }
2166
2167 [TestMethod, TestCategory(TypeName)]
2169 {
2170 PUT_StringAttribute_Empty(a => a.source_id);
2171 }
2172
2173 [TestMethod, TestCategory(TypeName)]
2175 {
2176 PUT_WithValue(a => a.source_id, "Not_A_UUID", false);
2177 }
2178 #endregion source_id
2179 #endregion PUT
2180 }
2181
2182 [TestClass]
2184 {
2185 #region Set Up and Configuration
2186 private const string TypeName = "DelayedPayment";
2189 #endregion Set Up and Configuration
2190
2191 #region POST
2192 #region Test payments
2193 [TestMethod, TestCategory(TypeName)]
2195 {
2197 {
2198 new DelayedPayment.Payment(0d, 0.5),
2199 new DelayedPayment.Payment(1d, 0.5)
2200 }, true);
2201 }
2202
2203 [TestMethod, TestCategory(TypeName)]
2205 {
2206 POST_Attribute_Null(l => l.payments);
2207 }
2208
2209 [TestMethod, TestCategory(TypeName)]
2211 {
2212 POST_ListAttribute_Empty(l => l.payments);
2213 }
2214
2215 [TestMethod, TestCategory(TypeName)]
2217 {
2218 // Both negative sequence offsets and negative loads should be supported
2220 {
2221 new DelayedPayment.Payment(-2d, -5.0),
2222 new DelayedPayment.Payment(-1d, 0.5),
2223 new DelayedPayment.Payment(1d, -0.5)
2224 }, true);
2225 }
2226
2227 [TestMethod, TestCategory(TypeName)]
2229 {
2230 // DelayedPayments' sort order is NOT validated.
2232 {
2233 new DelayedPayment.Payment(1d, 0.1),
2234 new DelayedPayment.Payment(3d, 0.1),
2235 new DelayedPayment.Payment(2d, 0.1),
2236 }, true);
2237 }
2238
2239 [TestMethod, TestCategory(TypeName)]
2241 {
2242 // Special case double values are not allowed
2244 { new DelayedPayment.Payment(Double.NaN, 0.1), }, false);
2246 { new DelayedPayment.Payment(Double.PositiveInfinity, 0.1), }, false);
2248 { new DelayedPayment.Payment(Double.NegativeInfinity, 0.1), }, false);
2249
2251 { new DelayedPayment.Payment(0d, Double.NaN), }, false);
2253 { new DelayedPayment.Payment(0d, Double.PositiveInfinity), }, false);
2255 { new DelayedPayment.Payment(0d, Double.NegativeInfinity), }, false);
2256 }
2257
2258 [TestMethod, TestCategory(TypeName)]
2260 {
2261 // Test certain special values that are allowed and precision survives the round-trip
2263 { new DelayedPayment.Payment(Double.MaxValue, 0.1), }, true);
2265 { new DelayedPayment.Payment(Double.Epsilon, 0.1), }, true);
2267 { new DelayedPayment.Payment(Double.MinValue, 0.1), }, true);
2269 { new DelayedPayment.Payment(Math.PI, 0.1), }, true);
2270
2272 { new DelayedPayment.Payment(0d, Double.MaxValue), }, true);
2274 { new DelayedPayment.Payment(0d, Double.Epsilon), }, true);
2276 { new DelayedPayment.Payment(0d, Double.MinValue), }, true);
2278 { new DelayedPayment.Payment(0d, Math.PI), }, true);
2279 }
2280 #endregion Test payments
2281 #endregion POST
2282
2283 #region PUT
2284 #region Test payments
2285 [TestMethod, TestCategory(TypeName)]
2287 {
2289 {
2290 new DelayedPayment.Payment(0d, 0.5),
2291 new DelayedPayment.Payment(1d, 0.5)
2292 }, true);
2293 }
2294
2295 [TestMethod, TestCategory(TypeName)]
2297 {
2298 PUT_Attribute_Null(l => l.payments);
2299 }
2300
2301 [TestMethod, TestCategory(TypeName)]
2303 {
2304 PUT_ListAttribute_Empty(l => l.payments);
2305 }
2306
2307 [TestMethod, TestCategory(TypeName)]
2309 {
2310 // Both negative sequence offsets and negative loads should be supported
2312 {
2313 new DelayedPayment.Payment(-2d, -5.0),
2314 new DelayedPayment.Payment(-1d, 0.5),
2315 new DelayedPayment.Payment(1d, -0.5)
2316 }, true);
2317 }
2318
2319 [TestMethod, TestCategory(TypeName)]
2321 {
2322 // DelayedPayments' sort order is NOT validated.
2324 {
2325 new DelayedPayment.Payment(1d, 0.1),
2326 new DelayedPayment.Payment(3d, 0.1),
2327 new DelayedPayment.Payment(2d, 0.1),
2328 }, true);
2329 }
2330
2331 [TestMethod, TestCategory(TypeName)]
2333 {
2334 // Special case double values are not allowed
2336 { new DelayedPayment.Payment(Double.NaN, 0.1), }, false);
2338 { new DelayedPayment.Payment(Double.PositiveInfinity, 0.1), }, false);
2340 { new DelayedPayment.Payment(Double.NegativeInfinity, 0.1), }, false);
2341
2343 { new DelayedPayment.Payment(0d, Double.NaN), }, false);
2345 { new DelayedPayment.Payment(0d, Double.PositiveInfinity), }, false);
2347 { new DelayedPayment.Payment(0d, Double.NegativeInfinity), }, false);
2348 }
2349
2350 [TestMethod, TestCategory(TypeName)]
2352 {
2353 // Test certain special values that are allowed and precision survives the round-trip
2355 { new DelayedPayment.Payment(Double.MaxValue, 0.1), }, true);
2357 { new DelayedPayment.Payment(Double.Epsilon, 0.1), }, true);
2359 { new DelayedPayment.Payment(Double.MinValue, 0.1), }, true);
2361 { new DelayedPayment.Payment(Math.PI, 0.1), }, true);
2362
2364 { new DelayedPayment.Payment(0d, Double.MaxValue), }, true);
2366 { new DelayedPayment.Payment(0d, Double.Epsilon), }, true);
2368 { new DelayedPayment.Payment(0d, Double.MinValue), }, true);
2370 { new DelayedPayment.Payment(0d, Math.PI), }, true);
2371 }
2372 #endregion Test payments
2373 #endregion PUT
2374 }
2375
2376 [TestClass]
2378 {
2379 #region Set Up and Configuration
2380 private const string TypeName = "FixedDatePayment";
2383 #endregion Set Up and Configuration
2384
2385 #region POST
2386 #region Test payments
2387 [TestMethod, TestCategory(TypeName)]
2389 {
2390 POST_WithValue(l => l.payments, new List<double> { 0d, 0.5, 1d, 0.5 }, true);
2391 }
2392
2393 [TestMethod, TestCategory(TypeName)]
2395 {
2396 POST_Attribute_Null(l => l.payments);
2397 }
2398
2399 [TestMethod, TestCategory(TypeName)]
2401 {
2402 POST_ListAttribute_Empty(l => l.payments);
2403 }
2404
2405 [TestMethod, TestCategory(TypeName)]
2407 {
2408 // Negative payment fractions (loads) should be supported
2409 POST_WithValue(l => l.payments, new List<double> { -2d, -5.0, -1d, 0.5, 1d, -0.5 }, true);
2410 }
2411
2412 [TestMethod, TestCategory(TypeName)]
2414 {
2415 // Special case double values are not allowed
2416 POST_WithValue(l => l.payments, new List<double> { Double.NaN, 0.1 }, false);
2417 POST_WithValue(l => l.payments, new List<double> { Double.PositiveInfinity, 0.1 }, false);
2418 POST_WithValue(l => l.payments, new List<double> { Double.NegativeInfinity, 0.1 }, false);
2419 }
2420
2421 [TestMethod, TestCategory(TypeName)]
2423 {
2424 // Test certain special values that are allowed and precision survives the round-trip
2425 POST_WithValue(l => l.payments, new List<double> { Double.MaxValue, 0.1 }, true);
2426 POST_WithValue(l => l.payments, new List<double> { Double.Epsilon, 0.1 }, true);
2427 POST_WithValue(l => l.payments, new List<double> { Double.MinValue, 0.1 }, true);
2428 POST_WithValue(l => l.payments, new List<double> { Math.PI, 0.1 }, true);
2429 }
2430 #endregion Test payments
2431
2432 #region Test payment_dates
2433 [TestMethod, TestCategory(TypeName)]
2435 {
2436 POST_WithValue(l => l.payment_dates,
2437 Enumerable.Range(0, TestResource.payments.Count)
2438 .Select(i => Samples.SimulationStartDate.AddYears(i + 1)).ToList(), true);
2439 }
2440
2441 [TestMethod, TestCategory(TypeName)]
2443 {
2444 POST_Attribute_Null(l => l.payment_dates);
2445 }
2446
2447 [TestMethod, TestCategory(TypeName)]
2449 {
2450 POST_ListAttribute_Empty(l => l.payment_dates);
2451 }
2452
2453 [TestMethod, TestCategory(TypeName)]
2455 {
2456 // PaymentDates should be sorted from soonest to latest.
2457 POST_WithValue(l => l.payment_dates,
2458 TestResource.payment_dates.Reverse<DateTime>().ToList(), false);
2459 }
2460
2461 [TestMethod, TestCategory(TypeName)]
2463 {
2464 POST_WithValue(l => l.payment_dates,
2465 Enumerable.Range(0, TestResource.payments.Count - 1)
2466 .Select(i => Samples.SimulationStartDate.AddYears(i)).ToList(), false);
2467 }
2468
2469 [TestMethod, TestCategory(TypeName)]
2471 {
2472 // Test certain special values that are allowed and precision survives the round-trip
2473 POST_WithValue(l => l.payment_dates, new[] { new DateTime(0L, DateTimeKind.Utc) }
2474 .Concat(TestResource.payment_dates).ToList(), true);
2475 POST_WithValue(l => l.payment_dates, TestResource.payment_dates.Concat(
2476 new[] { new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc) }).ToList(), true);
2477 }
2478 #endregion Test payment_dates
2479 #endregion POST
2480
2481 #region PUT
2482 #region Test payments
2483 [TestMethod, TestCategory(TypeName)]
2485 {
2486 PUT_WithValue(l => l.payments, new List<double> { 0d, 0.5, 1d, 0.5 }, true);
2487 }
2488
2489 [TestMethod, TestCategory(TypeName)]
2491 {
2492 PUT_Attribute_Null(l => l.payments);
2493 }
2494
2495 [TestMethod, TestCategory(TypeName)]
2497 {
2498 PUT_ListAttribute_Empty(l => l.payments);
2499 }
2500
2501 [TestMethod, TestCategory(TypeName)]
2503 {
2504 // Negative payment fractions (loads) should be supported
2505 PUT_WithValue(l => l.payments, new List<double> { -2d, -5.0, -1d, 0.5, 1d, -0.5 }, true);
2506 }
2507
2508 [TestMethod, TestCategory(TypeName)]
2510 {
2511 // Special case double values are not allowed
2512 PUT_WithValue(l => l.payments, new List<double> { Double.NaN, 0.1 }, false);
2513 PUT_WithValue(l => l.payments, new List<double> { Double.PositiveInfinity, 0.1 }, false);
2514 PUT_WithValue(l => l.payments, new List<double> { Double.NegativeInfinity, 0.1 }, false);
2515 }
2516
2517 [TestMethod, TestCategory(TypeName)]
2519 {
2520 // Test certain special values that are allowed and precision survives the round-trip
2521 PUT_WithValue(l => l.payments, new List<double> { Double.MaxValue, 0.1 }, true);
2522 PUT_WithValue(l => l.payments, new List<double> { Double.Epsilon, 0.1 }, true);
2523 PUT_WithValue(l => l.payments, new List<double> { Double.MinValue, 0.1 }, true);
2524 PUT_WithValue(l => l.payments, new List<double> { Math.PI, 0.1 }, true);
2525 }
2526 #endregion Test payments
2527
2528 #region Test payment_dates
2529 [TestMethod, TestCategory(TypeName)]
2531 {
2532 PUT_WithValue(l => l.payment_dates,
2533 Enumerable.Range(0, TestResource.payments.Count)
2534 .Select(i => Samples.SimulationStartDate.AddYears(i + 1)).ToList(), true);
2535 }
2536
2537 [TestMethod, TestCategory(TypeName)]
2539 {
2540 PUT_Attribute_Null(l => l.payment_dates);
2541 }
2542
2543 [TestMethod, TestCategory(TypeName)]
2545 {
2546 PUT_ListAttribute_Empty(l => l.payment_dates);
2547 }
2548
2549 [TestMethod, TestCategory(TypeName)]
2551 {
2552 // PaymentDates should be sorted from soonest to latest.
2553 PUT_WithValue(l => l.payment_dates,
2554 TestResource.payment_dates.Reverse<DateTime>().ToList(), false);
2555 }
2556
2557 [TestMethod, TestCategory(TypeName)]
2559 {
2560 PUT_WithValue(l => l.payment_dates,
2561 Enumerable.Range(0, TestResource.payments.Count - 1)
2562 .Select(i => Samples.SimulationStartDate.AddYears(i)).ToList(), false);
2563 }
2564
2565 [TestMethod, TestCategory(TypeName)]
2567 {
2568 // Test certain special values that are allowed and precision survives the round-trip
2569 PUT_WithValue(l => l.payment_dates, new[] { new DateTime(0L, DateTimeKind.Utc) }
2570 .Concat(TestResource.payment_dates).ToList(), true);
2571 PUT_WithValue(l => l.payment_dates, TestResource.payment_dates.Concat(
2572 new[] { new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc) }).ToList(), true);
2573 }
2574 #endregion Test payment_dates
2575 #endregion PUT
2576 }
2577 #endregion Layer Derived Types
2578
2579 #region Abstract Base Layer Tests
2581 [TestClass]
2583 {
2584 private const string TypeName = "QuotaShare";
2585
2586 #region POST
2587 #region event_limit
2588 [TestMethod, TestCategory(TypeName)]
2590 {
2591 POST_Attribute_Null(l => l.event_limit);
2592 }
2593
2594 [TestMethod, TestCategory(TypeName)]
2596 {
2597 POST_WithValue(l => l.event_limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2598 }
2599 #endregion event_limit
2600 #endregion POST
2601
2602 #region PUT
2603 #region event_limit
2604 [TestMethod, TestCategory(TypeName)]
2606 {
2607 PUT_Attribute_Null(l => l.event_limit);
2608 }
2609
2610 [TestMethod, TestCategory(TypeName)]
2612 {
2613 PUT_WithValue(l => l.event_limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2614 }
2615 #endregion event_limit
2616 #endregion PUT
2617 }
2618
2620 [TestClass]
2622 {
2623 private const string TypeName = "Layer_AggXL_Base";
2624
2625 #region POST
2626 #region aggregate_limit
2627 [TestMethod, TestCategory(TypeName)]
2629 {
2630 POST_Attribute_Null(l => l.aggregate_limit);
2631 }
2632
2633 [TestMethod, TestCategory(TypeName)]
2635 {
2636 POST_WithValue(l => l.aggregate_limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2637 }
2638 #endregion aggregate_limit
2639
2640 #region aggregate_attachment
2641 [TestMethod, TestCategory(TypeName)]
2643 {
2644 POST_Attribute_Null(l => l.aggregate_attachment);
2645 }
2646
2647 [TestMethod, TestCategory(TypeName)]
2649 {
2650 POST_WithValue(l => l.aggregate_attachment, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2651 }
2652 #endregion aggregate_attachment
2653 #endregion POST
2654
2655 #region PUT
2656 #region aggregate_limit
2657 [TestMethod, TestCategory(TypeName)]
2659 {
2660 PUT_Attribute_Null(l => l.aggregate_limit);
2661 }
2662
2663 [TestMethod, TestCategory(TypeName)]
2665 {
2666 PUT_WithValue(l => l.aggregate_limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2667 }
2668 #endregion aggregate_limit
2669
2670 #region aggregate_attachment
2671 [TestMethod, TestCategory(TypeName)]
2673 {
2674 PUT_Attribute_Null(l => l.aggregate_attachment);
2675 }
2676
2677 [TestMethod, TestCategory(TypeName)]
2679 {
2680 PUT_WithValue(l => l.aggregate_attachment, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2681 }
2682 #endregion aggregate_attachment
2683 #endregion PUT
2684 }
2685
2686 [TestClass]
2688 {
2689 private const string TypeName = "Layer_XL";
2690
2691 #region POST
2692 #region limit
2693 [TestMethod, TestCategory(TypeName)]
2694 public virtual void Test_Layer_XL_POST_Limit_Null()
2695 {
2696 POST_Attribute_Null(l => l.limit);
2697 }
2698
2699 [TestMethod, TestCategory(TypeName)]
2701 {
2702 POST_WithValue(l => l.limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2703 }
2704 #endregion limit
2705
2706 #region attachment
2707 [TestMethod, TestCategory(TypeName)]
2709 {
2710 POST_Attribute_Null(l => l.attachment);
2711 }
2712
2713 [TestMethod, TestCategory(TypeName)]
2715 {
2716 POST_WithValue(l => l.attachment, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2717 }
2718 #endregion attachment
2719
2720 #region franchise
2721 [TestMethod, TestCategory(TypeName)]
2723 {
2724 POST_Attribute_Null(l => l.franchise);
2725 }
2726
2727 [TestMethod, TestCategory(TypeName)]
2729 {
2730 POST_WithValue(l => l.franchise, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2731 }
2732 #endregion franchise
2733 #endregion POST
2734
2735 #region PUT
2736 #region limit
2737 [TestMethod, TestCategory(TypeName)]
2738 public virtual void Test_Layer_XL_PUT_Limit_Null()
2739 {
2740 PUT_Attribute_Null(l => l.limit);
2741 }
2742
2743 [TestMethod, TestCategory(TypeName)]
2745 {
2746 PUT_WithValue(l => l.limit, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2747 }
2748 #endregion limit
2749
2750 #region attachment
2751 [TestMethod, TestCategory(TypeName)]
2753 {
2754 PUT_Attribute_Null(l => l.attachment);
2755 }
2756
2757 [TestMethod, TestCategory(TypeName)]
2759 {
2760 PUT_WithValue(l => l.attachment, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2761 }
2762 #endregion attachment
2763
2764 #region franchise
2765 [TestMethod, TestCategory(TypeName)]
2767 {
2768 PUT_Attribute_Null(l => l.franchise);
2769 }
2770
2771 [TestMethod, TestCategory(TypeName)]
2773 {
2774 PUT_WithValue(l => l.franchise, new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2775 }
2776 #endregion franchise
2777 #endregion PUT
2778 }
2779
2780 [TestClass]
2782 {
2783 private const string TypeName = "Layer_WithTerms";
2784
2785 #region POST
2786 #region participation
2787 [TestMethod, TestCategory(TypeName)]
2789 {
2790 POST_WithValue(l => l.participation, Double.MaxValue, true);
2791 }
2792 [TestMethod, TestCategory(TypeName)]
2794 {
2795 POST_WithValue(l => l.participation, Double.MinValue, true);
2796 }
2797 [TestMethod, TestCategory(TypeName)]
2799 {
2800 POST_WithValue(l => l.participation, Double.NaN, false);
2801 }
2802 [TestMethod, TestCategory(TypeName)]
2804 {
2805 POST_WithValue(l => l.participation, Double.PositiveInfinity, false);
2806 }
2807 [TestMethod, TestCategory(TypeName)]
2809 {
2810 POST_WithValue(l => l.participation, Double.NegativeInfinity, false);
2811 }
2812 [TestMethod, TestCategory(TypeName)]
2814 {
2815 POST_WithValue(l => l.participation, Math.PI / 1E12, true);
2816 }
2817 #endregion participation
2818
2819 #region inception_date and expiry_date
2820 [TestMethod, TestCategory(TypeName)]
2821 public virtual void Test_Layer_POST_Expiry_Null()
2822 {
2823 POST_WithValue(l => l.expiry_date, null, true);
2824 }
2825
2826 [TestMethod, TestCategory(TypeName)]
2828 {
2829 POST_WithValue(l => l.inception_date, null, true);
2830 }
2831
2832 [TestMethod, TestCategory(TypeName)]
2834 {
2836 // Test them together so we don't violate inception <= expiry
2838 .Change(r => r.inception_date, minUtcDateTime)
2839 .Change(r => r.expiry_date, minUtcDateTime);
2841 }
2842
2843 [TestMethod, TestCategory(TypeName)]
2845 {
2846 DateTime maxUtcDateTime = new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc);
2847 // Test them together so we don't violate inception <= expiry
2849 .Change(r => r.inception_date, maxUtcDateTime)
2850 .Change(r => r.expiry_date, maxUtcDateTime);
2852 }
2853
2854 [TestMethod, TestCategory(TypeName)]
2856 {
2857 Assert.IsNotNull(TestResource.inception_date,
2858 "Test cannot proceed unless the inception date is set on the test resource.");
2859 POST_WithValue(l => l.expiry_date,
2860 TestResource.inception_date.Value.Subtract(new TimeSpan(0, 0, 0, 1)), false);
2861 }
2862 #endregion inception_date and expiry_date
2863
2864 #region premium
2865 [TestMethod, TestCategory(TypeName)]
2866 public virtual void Test_Layer_POST_Premium_Null()
2867 {
2868 POST_Attribute_Null(l => l.premium);
2869 }
2870
2871 [TestMethod, TestCategory(TypeName)]
2873 {
2874 POST_WithValue(l => l.premium,
2875 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
2876 }
2877 #endregion premium
2878
2879 #region fees
2880 [TestMethod, TestCategory(TypeName)]
2881 public virtual void Test_Layer_POST_Fees_Null()
2882 {
2883 POST_Attribute_Null(l => l.fees);
2884 }
2885
2886 [TestMethod, TestCategory(TypeName)]
2887 public virtual void Test_Layer_POST_Fees_Empty()
2888 {
2889 POST_WithValue(l => l.fees, new List<Fee>(), true);
2890 }
2891
2892 private void Test_Layer_POST_Fee(Fee fee)
2893 {
2894 POST_WithValue(l => l.fees, new List<Fee> { fee }, true);
2895 }
2896
2897 [TestMethod, TestCategory(TypeName)]
2898 public virtual void Test_Layer_POST_EachFee()
2899 {
2900 foreach (Fee fee in Samples.Fees.ListOfAllFeeTypes)
2901 Test_Layer_POST_Fee(fee);
2902 }
2903
2904 [TestMethod, TestCategory(TypeName)]
2906 {
2907 POST_WithValue(l => l.fees, new List<Fee>
2908 {
2909 new ProfitCommission
2910 {
2911 name = "MyFee",
2912 payout_date = TestResource.inception_date,
2913 rate = 0.5,
2914 losses = new List<FeeReference> { FeeReference.CreateFromPremiumOrLossName("X") },
2915 }
2916 }, false);
2917 }
2918
2919 [TestMethod, TestCategory(TypeName)]
2921 {
2922 POST_WithValue(l => l.fees, new List<Fee>
2923 {
2924 new ProfitCommission()
2925 {
2926 name = "MyFee",
2927 payout_date = TestResource.inception_date,
2928 rate = 0.5,
2929 losses = new List<FeeReference>
2930 {
2931 FeeReference.CreateFromPremiumOrLossName("ReinstatementBrokerage")
2932 },
2933 premiums = new List<FeeReference>
2934 {
2935 FeeReference.CreateFromPremiumOrLossName("ReinstatementPremium")
2936 },
2937 },
2938 }, true);
2939 }
2940
2941 [TestMethod, TestCategory(TypeName)]
2943 {
2944 POST_WithValue(l => l.fees, new List<Fee>
2945 {
2946 new ProfitCommission()
2947 {
2948 name = "MyFee",
2949 payout_date = TestResource.inception_date,
2950 rate = 0.5,
2951 premiums = new List<FeeReference>
2952 {
2953 FeeReference.CreateFromPremiumOrLossName("ReinstatementBrokerage")
2954 },
2955 },
2956 }, false);
2957 }
2958
2959 [TestMethod, TestCategory(TypeName)]
2961 {
2962 POST_WithValue(l => l.fees, new List<Fee>
2963 {
2964 new ProportionalExpense
2965 {
2966 name = "MyFee",
2967 payout_date = TestResource.inception_date,
2968 rate = 0.5,
2969 premiums = new List<FeeReference> { FeeReference.CreateFromPremiumOrLossName("X") },
2970 },
2971 }, false);
2972 }
2973
2974 [TestMethod, TestCategory(TypeName)]
2976 {
2977 POST_WithValue(l => l.fees, new List<Fee>
2978 {
2979 new ProfitCommission
2980 {
2981 name = "MyFee",
2982 payout_date = TestResource.inception_date,
2983 rate = 0.5,
2984 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("X") }
2985 }
2986 }, false);
2987 }
2988
2989 [TestMethod, TestCategory(TypeName)]
2991 {
2992 POST_WithValue(l => l.fees, new List<Fee>
2993 {
2994 new ProfitCommission
2995 {
2996 name = "MyFee",
2997 payout_date = TestResource.inception_date,
2998 rate = 0.5,
2999 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFee") }
3000 }
3001 }, false);
3002 }
3003
3004 [TestMethod, TestCategory(TypeName)]
3006 {
3007 List<Fee> fees = new List<Fee>
3008 {
3010 {
3011 name = "MyFeeA",
3012 payout_date = TestResource.inception_date,
3013 rate = 0.5
3014 },
3016 {
3017 name = "MyFee1",
3018 payout_date = TestResource.inception_date,
3019 rate = 0.5,
3020 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFee3") }
3021 },
3023 {
3024 name = "MyFeeB",
3025 payout_date = TestResource.inception_date,
3026 rate = 0.5,
3027 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFeeA") }
3028 },
3030 {
3031 name = "MyFee2",
3032 payout_date = TestResource.inception_date,
3033 rate = 0.5,
3034 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFee1") }
3035 },
3037 {
3038 name = "MyFeeC",
3039 payout_date = TestResource.inception_date,
3040 rate = 0.5,
3041 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFeeB") }
3042 },
3044 {
3045 name = "MyFee3",
3046 payout_date = TestResource.inception_date,
3047 rate = 0.5,
3048 fees = new List<FeeReference>
3049 {
3052 }
3053 },
3055 {
3056 name = "MyFee4",
3057 payout_date = TestResource.inception_date,
3058 rate = 0.5,
3059 fees = new List<FeeReference> { FeeReference.CreateFromFeeName("MyFee3") }
3060 }
3061 };
3062
3063 POST_WithValue(l => l.fees, fees, false);
3064 }
3065
3066 [TestMethod, TestCategory(TypeName)]
3067 public virtual void Test_Layer_POST_Fees_Many()
3068 {
3070 }
3071 #endregion fees
3072 #endregion POST
3073
3074 #region PUT
3075 #region participation
3076 [TestMethod, TestCategory(TypeName)]
3077 public virtual void Test_Layer_PUT_Participation()
3078 {
3079 PUT_WithValue(l => l.participation, 0.56789, true);
3080 }
3081 #endregion participation
3082
3083 #region inception_date and expiry_date
3084 [TestMethod, TestCategory(TypeName)]
3085 public virtual void Test_Layer_PUT_Expiry_Null()
3086 {
3087 PUT_WithValue(l => l.expiry_date, null, true);
3088 }
3089
3090 [TestMethod, TestCategory(TypeName)]
3091 public virtual void Test_Layer_PUT_Inception_Null()
3092 {
3093 PUT_WithValue(l => l.inception_date, null, true);
3094 }
3095
3096 [TestMethod, TestCategory(TypeName)]
3097 public virtual void Test_Layer_PUT_InceptionDate()
3098 {
3099 PUT_WithValue(l => l.inception_date,
3100 TestResource.inception_date.Value.Subtract(new TimeSpan(0, 0, 0, 1)), true);
3101 }
3102
3103 [TestMethod, TestCategory(TypeName)]
3104 public virtual void Test_Layer_PUT_ExpiryDate()
3105 {
3106 PUT_WithValue(l => l.expiry_date,
3107 TestResource.expiry_date.Value.Add(new TimeSpan(0, 0, 0, 1)), true);
3108 }
3109
3110 [TestMethod, TestCategory(TypeName)]
3112 {
3114 // Test them together so we don't violate inception <= expiry
3115 PUT_WithChanges_Succeeds(posted => posted
3116 .Change(r => r.inception_date, minUtcDateTime)
3117 .Change(r => r.expiry_date, minUtcDateTime));
3118 }
3119
3120 [TestMethod, TestCategory(TypeName)]
3122 {
3123 DateTime maxUtcDateTime = new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc);
3124 // Test them together so we don't violate inception <= expiry
3125 PUT_WithChanges_Succeeds(posted => posted
3126 .Change(r => r.inception_date, maxUtcDateTime)
3127 .Change(r => r.expiry_date, maxUtcDateTime));
3128 }
3129
3130 [TestMethod, TestCategory(TypeName)]
3132 {
3133 Assert.IsNotNull(TestResource.inception_date,
3134 "Test cannot proceed unless the inception date is set on the test resource.");
3135 PUT_WithValue(l => l.expiry_date,
3136 TestResource.inception_date.Value.Subtract(new TimeSpan(0, 0, 0, 1)), false);
3137 }
3138 #endregion inception_date and expiry_date
3139
3140 #region premium
3141 [TestMethod, TestCategory(TypeName)]
3142 public virtual void Test_Layer_PUT_Premium_Null()
3143 {
3144 PUT_Attribute_Null(l => l.premium);
3145 }
3146
3147 [TestMethod, TestCategory(TypeName)]
3149 {
3150 PUT_WithValue(l => l.premium,
3151 new MonetaryUnit(Math.PI / 1E12, "USD"), true);
3152 }
3153 #endregion premium
3154
3155 // TODO: There are no tests for modifying fees
3156 #endregion PUT
3157 }
3158
3167 [TestClass]
3169 {
3170 private const string TypeName = "Layer_Unsaveable";
3171
3175 [TestMethod, TestCategory(TypeName)]
3176 public sealed override void Test_Layer_Saveable()
3177 {
3179 $"The {typeof(T).NiceTypeName()} layer type is being tested as an un-saveable " +
3180 $"layer, but it does not carry the {nameof(NotSaveableAttribute)}.");
3181 }
3182
3183 // Override any POST tests to *only* test these Layers as inlined LayerViews.
3184 // since they cannot be saved on their own.
3185 #region POST
3187 [TestMethod, TestCategory(TypeName)]
3188 public override void Test_Resource_POST_Valid()
3189 {
3190 // Only in this base test - confirm that a layer with this type cannot be posted
3191 GenericTest.POST_InvalidResource_Fails(TestResource);
3192 // Now test that it can be posted as part of a layer_view
3193 TestSuite_Layer_Base.TestLayerInLayerView(TestResource, true);
3194 }
3195
3198 public override void POST_WithValue<TProperty>(
3201 {
3202 TestSuite_Layer_Base.TestLayerInLayerView(
3203 TestResource.Change(PropertyExpression, newValue), shouldSucceed);
3204 }
3205 #endregion POST
3206
3207 // Can't perform a GET/PUT/POST on layers that can't be saved.
3208 // In this case, we simply need to make sure the tests don't exist (aren't inherited)
3209 // for layers that can't be saved.
3210 // We do this by overriding base test methods and omitting the [TestMethod] attribute
3211 // This is simpler than deriving from BaseStoredResourceTestSuite and re-implementing
3212 // the BaseMutableResourceTestSuite tests elsewhere. Again, multiple inheritance is missed.
3213 #region Hidden Tests
3214 public sealed override void Test_Resource_GET_Existing() { }
3215 public sealed override void Test_Resource_GET_Existing_ResolveReferences() { }
3216 public sealed override void Test_Resource_Search() { }
3217 public sealed override void Test_Resource_GET_FromBatch() { }
3218
3219 public sealed override void Test_Resource_POST_CreatedAndModified() { }
3220 public sealed override void Test_Resource_POST_Id_Ignored() { }
3221 public sealed override void Test_Resource_POST_ExistingId() { }
3222
3223 public sealed override void Test_Resource_PUT_Description() { }
3224 public sealed override void Test_Resource_PUT_Description_Blank() { }
3225 public sealed override void Test_Resource_PUT_Description_Null() { }
3226 public sealed override void Test_Resource_PUT_Metadata_Empty() { }
3227 public sealed override void Test_Resource_PUT_Metadata_MixedTypes() { }
3228 public sealed override void Test_Resource_PUT_Metadata_Null() { }
3229 public sealed override void Test_Resource_PUT_Metadata_InvalidValues() { }
3231 public sealed override void Test_Layer_WithLossSets_PUT_LossSets() { }
3232 public sealed override void Test_Layer_WithLossSets_PUT_LossSets_Duplicates() { }
3233 public sealed override void Test_Layer_WithLossSets_PUT_LossSets_Empty() { }
3234 public sealed override void Test_Layer_WithLossSets_PUT_LossSets_Invalid() { }
3235 public sealed override void Test_Layer_WithLossSets_PUT_Policy() { }
3236 public sealed override void Test_Layer_WithLossSets_PUT_Policy_TransformAll() { }
3237 public sealed override void Test_Layer_WithLossSets_PUT_Policy_ForwardAll() { }
3238 public sealed override void Test_Layer_WithLossSets_PUT_Policy_Empty() { }
3239 public sealed override void Test_Layer_WithLossSets_PUT_Policy_Duplicates() { }
3240 public sealed override void Test_Resource_PUT_CreatedAndModified() { }
3241 public sealed override void Test_Resource_PUT_NoChanges() { }
3242
3243 public sealed override void Test_Resource_DELETE() { }
3244 #endregion Hidden Tests
3245 }
3246
3247 [TestClass]
3249 {
3250 private const string TypeName = "Layer_WithLossSets";
3251
3252 #region POST
3253 #region loss_sets
3254 [TestMethod, TestCategory(TypeName)]
3256 {
3257 POST_Attribute_Null(l => l.loss_sets);
3258 }
3259 [TestMethod, TestCategory(TypeName)]
3261 {
3262 POST_ListAttribute_Empty(l => l.loss_sets);
3263 }
3264 [TestMethod, TestCategory(TypeName)]
3270 [TestMethod, TestCategory(TypeName)]
3272 {
3273 POST_ReferenceList_NonExistantId(l => l.loss_sets);
3274 }
3275 [TestMethod, TestCategory(TypeName)]
3277 {
3279 Assert.Inconclusive("RUN_OFFLINE = true");
3280 // We expect an error when trying to attach a LossSet that has not had data uploaded
3281 // against it to a layer.
3283 // Post the loss set but not with data.
3284 notFinalized.Post();
3285 // Try to reference the loss set and demonstrate the error
3286 GenericTest.POST_InvalidResource_Fails(TestResource.Change(l => l.loss_sets,
3287 new List<IReference<LossSet>> { notFinalized.ToReference() }));
3288 }
3289 #endregion loss_sets
3290
3291 #region policy
3292 [TestMethod, TestCategory(TypeName)]
3294 {
3295 POST_Attribute_Null(l => l.policy);
3296 }
3297 [TestMethod, TestCategory(TypeName)]
3299 {
3300 POST_WithValue(l => l.policy, Samples.TransformAllPolicy, true);
3301 }
3302 [TestMethod, TestCategory(TypeName)]
3304 {
3305 POST_WithValue(l => l.policy, Samples.ForwardAllPolicy, true);
3306 }
3307 [TestMethod, TestCategory(TypeName)]
3309 {
3310 POST_WithValue(l => l.policy, new Policy(), true);
3311 }
3312 [TestMethod, TestCategory(TypeName)]
3314 {
3316 withDuplicates.forward_records.Add(RecordType.Loss);
3317 withDuplicates.transform_records.Add(RecordType.Loss);
3318 POST_WithValue(l => l.policy, withDuplicates, false);
3319 }
3320 #endregion policy
3321 #endregion POST
3322
3323 #region PUT
3324 #region loss_sets
3325 [TestMethod, TestCategory(TypeName)]
3327 {
3328 PUT_WithValue(l => l.loss_sets, new List<IReference<LossSet>>
3329 {
3330 Samples.LossSet_YELTLossSetWithReinstatements.AsReference,
3331 }, true);
3332 }
3333 [TestMethod, TestCategory(TypeName)]
3335 {
3336 PUT_ListAttribute_Empty(l => l.loss_sets);
3337 }
3338 [TestMethod, TestCategory(TypeName)]
3344 [TestMethod, TestCategory(TypeName)]
3346 {
3347 PUT_ReferenceList_NonExistantId(l => l.loss_sets);
3348 }
3349 [TestMethod, TestCategory(TypeName)]
3351 {
3353 Assert.Inconclusive("RUN_OFFLINE = true");
3354 // We expect an error when trying to attach a LossSet that has not had data uploaded
3355 // against it to a layer.
3357 {
3358 PUT_WithValue(l => l.loss_sets,
3359 new List<IReference<LossSet>> { notFinalized.ToReference() }, false);
3360 });
3361 }
3362 #endregion loss_sets
3363
3364 #region policy
3365 [TestMethod, TestCategory(TypeName)]
3367 {
3368 PUT_WithValue(l => l.policy, Samples.Policy, true);
3369 }
3370 [TestMethod, TestCategory(TypeName)]
3372 {
3373 PUT_WithValue(l => l.policy, Samples.TransformAllPolicy, true);
3374 }
3375 [TestMethod, TestCategory(TypeName)]
3377 {
3378 PUT_WithValue(l => l.policy, Samples.ForwardAllPolicy, true);
3379 }
3380 [TestMethod, TestCategory(TypeName)]
3382 {
3383 PUT_WithValue(l => l.policy, new Policy(), true);
3384 }
3385 [TestMethod, TestCategory(TypeName)]
3387 {
3389 withDuplicates.forward_records.Add(RecordType.Loss);
3390 withDuplicates.transform_records.Add(RecordType.Loss);
3391 PUT_WithValue(l => l.policy, withDuplicates, false);
3392 }
3393 #endregion policy
3394 #endregion PUT
3395 }
3396
3397 [TestClass]
3399 {
3400 private const string TypeName = "Layer";
3401
3407 public override void AdditionalValidResourceTests(T posted) =>
3408 TestSuite_Layer_Base.TestLayerInLayerView(posted, true);
3409
3410 #region POST
3414 [TestMethod, TestCategory(TypeName)]
3415 public virtual void Test_Layer_Saveable()
3416 {
3418 $"The {typeof(T).NiceTypeName()} layer type is being tested as a saveable " +
3419 $"layer, but it carries the {nameof(NotSaveableAttribute)}.");
3420 }
3421 #endregion POST
3422
3423 #region BaseMutableResourceTestSuite Overrides
3424 #region GET
3425 [TestMethod, TestCategory(TypeName)]
3426 public virtual void Test_Resource_GET_As_Inlined()
3427 {
3428 // Test getting an existing layer of this type inlined in a layer_view
3429 GenericTest.GET_ExistingResource_Succeeds(
3430 LayerViews.Create(TestResource, Samples.AnalysisProfile.Posted).Post());
3431 }
3432
3433 [TestMethod, TestCategory(TypeName)]
3435 {
3437 base.Test_Resource_GET_AllPropertiesRecognized();
3438 // Test that all properties are recognized in layer_view layer
3439 GenericTest.GET_AllPropertiesRecognized(
3440 LayerViews.Create(TestResource, Samples.AnalysisProfile.Posted).Post());
3441 }
3442 #endregion GET
3443
3444 #region POST
3445 #region Helper Methods
3447 public override void POST_WithValue<TProperty>(
3450 {
3452 // If the post should fail, we want to also verify that it fails when inlined in a
3453 // layer_view either. (AdditionalValidResourceTests already handles the success case.)
3454 if (!shouldSucceed)
3455 TestSuite_Layer_Base.TestLayerInLayerView(
3456 TestResource.Change(PropertyExpression, newValue), false);
3457 }
3458
3472 {
3473 // Similar to base.POST_WithValue, but skip AdditionalValidResourceTests,
3474 // since in this inconsistent case, we do not expect the layer_view to succeed
3475 T modifiedResource = TestResource.Change(PropertyExpression, newValue);
3477 GenericTest.POST_ValidResource(modifiedResource);
3478 else
3479 GenericTest.POST_InvalidResource_Fails(modifiedResource);
3480 // Now test that a layer_view with this definition has the opposite outcome.
3482 }
3483 #endregion Helper Methods
3484
3485 [TestMethod, TestCategory(TypeName)]
3486 public override void Test_Resource_POST_FieldsIdOnly()
3487 {
3489 GenericTest.POST_InvalidResource_Fails(TestResource);
3490 else
3491 base.Test_Resource_POST_FieldsIdOnly();
3492 }
3493 #endregion POST
3494
3495 [TestMethod, TestCategory(TypeName)]
3496 public override void Test_Resource_ShallowCopy()
3497 {
3499 base.Test_Resource_ShallowCopy();
3500 // Test the resource inlined as part of a layer_view definition
3501 TestCopyHelper(Samples.GetInjectableLayerView(TestResource).Unposted,
3502 r => r.ShallowCopy());
3503 }
3504
3505 [TestMethod, TestCategory(TypeName)]
3506 public override void Test_Resource_DeepCopy()
3507 {
3509 base.Test_Resource_DeepCopy();
3510 // Test the resource inlined as part of a layer_view definition
3511 TestCopyHelper(Samples.GetInjectableLayerView(TestResource).Unposted,
3512 r => r.DeepCopy());
3513 }
3514 #endregion BaseMutableResourceTestSuite Overrides
3515 }
3516 #endregion Abstract Base Layer Tests
3517}
Tests for a stored resource collection which do not require an instance of that resource to be define...
virtual T TestResource
The resource used for all unit tests that require a valid prepared but unPOSTed resource.
virtual void POST_ThenDoAction(T validToPost, Action< T > toExecute)
Post a valid resource under the assumption that it will succeed, then perform an action on the result...
static List< Fee > ListOfAllFeeTypes
Definition Samples.cs:81
static List< Fee > ListWithNestedFeeReference
Definition Samples.cs:88
Exposes sample resource objects, with built-in methods for injecting dependencies.
Definition Samples.cs:14
static readonly PollingOptions DataPollingOptions
Polling options to use when uploading a data file.
List< IInjectableResource< ILayerView > > AllLayerViewTypesTestList
A list of one of each type of layer.
IInjectableResource< Nested > Layer_Nested
A simple nested layer retaining a CatXL source's losses to an AggXL sink.
static Policy TransformAllPolicy
Definition Samples.cs:121
IInjectableResource< SurplusShare > Layer_SurplusShare
IInjectableResource< ELTLossSet > LossSet_ELTLossSet
static Policy Policy
Definition Samples.cs:113
IInjectableResource< AggXL > Layer_AggXL
IInjectableResource< Generic > Layer_Generic
List< IInjectableResource< ILayer > > AllSaveableLayerTypesTestList
A list of one of each type of layer that can be POSTed. Layer types that cannot be posted on their ow...
IInjectableResource< AnalysisProfile > AnalysisProfile
An analysis profile with one of each possible type of filter.
IInjectableResource< BackAllocatedLayer > Layer_BackAllocatedLayer
IInjectableResource< IndustryLossWarranty > Layer_IndustryLossWarranty
IInjectableResource< LossRank > Layer_LossRank
IInjectableResource< AggregateQuotaShare > Layer_AggregateQuotaShare
static string Valid_NonExistant_UUID
Definition Samples.cs:41
IInjectableResource< ValueAllocator > Layer_ValueAllocator
DateTime SimulationStartDate
The relative start_date to use for all new resources that require an absolute DateTime point of refer...
IInjectableResource< CatXL > Layer_CatXL
List< IInjectableResource< ILayer > > AllLayerTypesTestList
A list of one of each type of layer.
IInjectableResource< Filter > Layer_Filter
IInjectableResource< FixedDatePayment > Layer_FixedDatePayment
static Policy ForwardAllPolicy
Definition Samples.cs:123
IInjectableResource< QuotaShare > Layer_QuotaShare
IInjectableResource< DelayedPayment > Layer_DelayedPayment
IInjectableResource< FixedRateCurrencyConverter > Layer_FixedRateCurrencyConverter
IInjectableResource< NoClaimsBonus > Layer_NoClaimsBonus
Contains static helper methods for testing IAPIResourceView instances.
Special case - for simplicity, Generic layer inherits from AggXL.
override IInjectableResource< AggXL > TestInjectableResource
Definition Test_Layer.cs:81
override IInjectableResource< AggregateQuotaShare > TestInjectableResource
override IInjectableResource< BackAllocatedLayer > TestInjectableResource
static IEnumerable< IInjectableResource< ILayer > > ForbiddenSinkLayerTypesTestList
A set of injectable test layers that are not valid to use as a sink.
static IEnumerable< IInjectableResource< ILayer > > ValidSinkLayerTypesTestList
A set of injectable test layers that are valid to use as a sink.
static HashSet< Type > UnsupportedBackAllocatedLayerSinkTypes
Types that cannot be the sink of a Back-Allocated layer.
void Test_Layer_FixedRateCurrencyConverter_POST_NotAllowed()
Demonstrate that layers of type "FixedRateCurrencyConverter" cannot be posted to the /layers/ endpoin...
Definition Test_Layer.cs:60
override IResourceCollection< ILayer > collection_source
Definition Test_Layer.cs:31
static void TestLayerInLayerView< T >(T layerToInline, bool shouldSucceed)
Inline the specified layer in a new LayerView, and test whether the LayerView POST succeeds.
Definition Test_Layer.cs:41
static IEnumerable< Type > PaymentPatternTypes
A list of "PaymentPattern" layer types for convenience (because they comes up in a lot of validation ...
Definition Test_Layer.cs:35
void Test_Layer_Filter_POST_Allowed()
Demonstrate that layers of type "FilterLayer" can be posted to the /layers/ endpoint....
Definition Test_Layer.cs:69
override IInjectableResource< CatXL > TestInjectableResource
override IInjectableResource< DelayedPayment > TestInjectableResource
override IInjectableResource< Filter > TestInjectableResource
override IInjectableResource< FixedDatePayment > TestInjectableResource
override IInjectableResource< FixedRateCurrencyConverter > TestInjectableResource
override IInjectableResource< Generic > TestInjectableResource
Definition Test_Layer.cs:91
override IInjectableResource< IndustryLossWarranty > TestInjectableResource
override IInjectableResource< LossRank > TestInjectableResource
static HashSet< Type > UnsupportedNestedSinkTypes
Types that cannot be the sink of a Nested layer.
static IEnumerable< IInjectableResource< ILayer > > ForbiddenSinkLayerTypesTestList
A set of injectable test layers that are not valid to use as a sink.
static IEnumerable< IInjectableResource< ILayer > > ValidSinkLayerTypesTestList
A set of injectable test layers that are valid to use as a sink.
override IInjectableResource< Nested > TestInjectableResource
override IInjectableResource< NoClaimsBonus > TestInjectableResource
Special case - for simplicity, AggregateQuotaShare layer inherits from QuotaShare.
override IInjectableResource< QuotaShare > TestInjectableResource
override IInjectableResource< SurplusShare > TestInjectableResource
Special case - certain layer types do not currently support being saved (See ARE-3360)....
override void Test_Resource_GET_FromBatch()
Test that resources of this type can be retrieved using the collection batch-get feature.
override void Test_Resource_POST_ExistingId()
Verifies that it is okay to post an object with an ID that already exists on the server,...
override void Test_Layer_Saveable()
As a sanity check, layers that are saveable should not carry the NotSaveableAttribute....
override void Test_Resource_GET_Existing_ResolveReferences()
IStoredAPIResource collections support reference resolution.
override void Test_Resource_Search()
All resources should support searching in a few fundamental ways.
override void Test_Resource_POST_Id_Ignored()
No matter what string we set the Id property to, POST should succeed because the Id of the posted res...
override IInjectableResource< ValueAllocator > TestInjectableResource
override void Test_Resource_POST_FieldsIdOnly()
Test that a user can post a resource and get back only the id using the omit query parameter.
override void Test_Resource_ShallowCopy()
Test that any resource can be "Shallow Copied", which is a quick copy that does a member-wise clone o...
override void Test_Resource_DeepCopy()
Test that any resource can be "Deep Copied", a slower copy method that creates a new duplicate instan...
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...
virtual void Test_Layer_Saveable()
As a sanity check, layers that are saveable should not carry the NotSaveableAttribute....
static void DoublesAreEqual(double expected, double actual, Func< string > message, double? relative_tolerance=null)
Determines if two doubles are equivalent within the accepted tolerance.
Definition AssertApi.cs:594
Retrieve settings from environment variables if they exist, or the project settings file otherwise.
static bool RUN_OFFLINE
Controls whether tests that normally require a connection to the server should be allowed to try to r...
Generic Unit test implementations that will test REST methods on arbitrary resources.
A collection of filthy hacks to populate some fields of APIResources objects of any type.
Definition Reflection.cs:41
string PickBackAllocatedLayerSourceId(IReference< ILayerSource > sinkReference)
Finds a random source loss set or layer_view id within the specified sinkReference which can be used...
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
static void Indefinitely(string ticket=null)
Skip the specified test.
Definition SkipUntil.cs:54
Describes a collection of resources which can be listed.
API methods / requests made available to the user.
static readonly ResourceCollection< ILayer > Layers
The collection of Layers on the server.
Indicates that while the current APIResource-derived class can be constructed and potentially inlined...
Specifies one or more aliases to be used as synonyms for the property's name.
string[] Aliases
The aliases associated with this property.
Represents a reference, used in Fee objects.
static FeeReference CreateFromFeeName(string name)
Create a reference to a Fee from its name.
Abstract representation of a fee. This resource type cannot be instantiated instead derived resource ...
Definition Fee.cs:14
The Profit Commission applies a fee that is the sum of the premium sources minus the sum of loss and ...
LayerView factory class.
Definition LayerViews.cs:9
Abstract representation of a layer. This resource type cannot be instantiated instead derived resourc...
Definition Layer.cs:12
Representation of an Aggregate Catastrophe Excess of Loss layer.
Definition AggXL.cs:8
Acts as a replacement for IAPIResourceView.back_allocations. Computes the proportion of some sink str...
A "delayed payment" payment pattern models claims being paid in instalments at fixed delays after the...
A "delayed payment" payment pattern models claims being paid in instalments at specific dates followi...
A structure that can be used to change the currency of a loss stream from one currency to another at ...
Abstract representation of a layer. This resource type cannot be instantiated instead derived resourc...
Abstract representation of a layer. This resource type cannot be instantiated instead derived resourc...
Abstract representation of a base Excess of Loss layer.
Definition Layer_XL.cs:8
A wrapper for a List<T> of IReference<ILayerSource> references that simplifies the construction and u...
Definition Nested.cs:67
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
Definition Nested.cs:22
Layer Policy is the rule on RecordType that determines how occurrences belonging to a particular Reco...
Definition Policy.cs:17
Representation of a Quota Share contract.
Definition QuotaShare.cs:9
Represents a reinstatement premium and brokerage amount.
Representation of a Surplus Share contract.
Surfaces the value-allocator specialty structure (which is treated as a "layer definition" by the API...
Perspective
The loss perspectives that can be used when computing proportions (proportioned_perspective) and allo...
AllocationRatioBasis
Dictates how value allocator layer should allocate losses per event or per trial.
Base class for all LossSet sub-types. A LossSet is a resource that generates sample (trial) losses wh...
Definition LossSet.cs:13
Representation of a single loss set with an associated event loss table.
Definition ELTLossSet.cs:10
Representation of a monetary value with a currency.
IReference< T > AsReference
A reference to the posted resource.
T Unposted
The unPOSTed resource definition.
T Posted
The posted resource, ready to be referenced.
Abstract representation of a layer.
Definition ILayer.cs:7
Abstract representation of a layer with terms.
double participation
The amount of participation of the reinsurer in this deal as the percentage of loss,...
RecordType
The type of occurrence.
Definition RecordType.cs:10