C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_AnalysisProfile.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Diagnostics;
3using System.Linq;
4
5using AnalyzeRe;
12
13#if MSTEST
14
15using Microsoft.VisualStudio.TestTools.UnitTesting;
16
17#elif NUNIT
18using NUnit.Framework;
19using TestClass = NUnit.Framework.TestFixtureAttribute;
20using TestMethod = NUnit.Framework.TestAttribute;
21using TestCategory = NUnit.Framework.CategoryAttribute;
22#endif
23
25{
26 [TestClass]
28 {
29 protected override bool PUT_Allowed => false;
31
32 // See models.py#AnyFilter.get_default_protobuf, currently
33 // at https://github.com/analyzere/are-platform/blob/master/api-v1/loss_filters/models.py#L223
38 Reflection.Resolve(Reflection.Resolve(analysisProfile).loss_filters
39 .FirstOrDefault(lf => Reflection.Resolve(lf) is AnyFilter))?.name ?? "All Losses";
40 }
41
42 [TestClass]
43 public sealed class TestSuite_AnalysisProfile : BaseImmutableResourceTestSuite<AnalysisProfile>
44 {
45 #region Set Up and Configuration
46
47 private const string TypeName = "AnalysisProfile";
48
51
52 #endregion Set Up and Configuration
53
54 #region POST
55
56 #region simulation
57
58 [TestMethod, TestCategory(TypeName)]
60 {
61 POST_Attribute_Null(a => a.simulation);
62 }
63
64 [TestMethod, TestCategory(TypeName)]
69
70 [TestMethod, TestCategory(TypeName)]
75
76 [TestMethod, TestCategory(TypeName)]
81
82 #endregion simulation
83
84 #region event_catalogs
85
86 [TestMethod, TestCategory(TypeName)]
88 {
89 POST_Attribute_Null(a => a.event_catalogs);
90 }
91
92 [TestMethod, TestCategory(TypeName)]
94 {
95 POST_ListAttribute_Empty(a => a.event_catalogs);
96 }
97
98 [TestMethod, TestCategory(TypeName)]
103
104 #endregion event_catalogs
105
106 #region loss_filters
107
108 [TestMethod, TestCategory(TypeName)]
110 {
111 POST_Attribute_Null(a => a.loss_filters);
112 }
113
114 [TestMethod, TestCategory(TypeName)]
116 {
117 POST_ListAttribute_Empty(a => a.loss_filters);
118 }
119
120 [TestMethod, TestCategory(TypeName)]
125
126 [TestMethod, TestCategory(TypeName)]
128 {
129 POST_WithValue(a => a.loss_filters,
130 Samples.AnalysisProfile.Unposted.loss_filters, true);
131 }
132
133 [TestMethod, TestCategory(TypeName)]
135 {
137 new List<IReference<LossFilter>> { Samples.LossFilter_AnyFilter.AsReference };
138 // Create a new filter with the same name (different description though)
139 AnyFilter duplicate = Samples.LossFilter_AnyFilter.Unposted
140 .Change(f => f.description, "same name, different filter").Post();
141 withDuplicateNames.Add(duplicate.ToReference());
142
143 POST_WithValue(a => a.loss_filters, withDuplicateNames, false);
144 }
145
146 [TestMethod, TestCategory(TypeName)]
148 {
149 const string filterName = "NO_MATCH_FILTER";
150 POST_WithValue(a => a.loss_filters, new List<IReference<LossFilter>>
151 {
152 new AnyOfFilter
153 {
154 name = filterName,
155 attribute = "Unknown",
156 values = new List<object> { 0d }
157 }.Post().ToReference()
158 }, false);
159 }
160
161 #endregion loss_filters
162
163 #region exchange_rate_profile
164
165 [TestMethod, TestCategory(TypeName)]
167 {
168 POST_Attribute_Null(a => a.exchange_rate_profile);
169 }
170
171 [TestMethod, TestCategory(TypeName)]
173 {
174 POST_Reference_NullId(a => a.exchange_rate_profile);
175 }
176
177 [TestMethod, TestCategory(TypeName)]
182
183 [TestMethod, TestCategory(TypeName)]
188
189 #endregion exchange_rate_profile
190
191 #region yelt_loss_set_simulation_filtering
192
193 [TestMethod, TestCategory(TypeName)]
195 {
196 POST_WithValue(a => a.yelt_loss_set_simulation_filtering, true, true);
197 }
198
199 #endregion yelt_loss_set_simulation_filtering
200
201 #region round_sequences
202
203 [TestMethod, TestCategory(TypeName)]
205 {
206 POST_WithValue(a => a.round_sequences, true, true);
207 }
208
209 #endregion round_sequences
210
211 #region status
212
213 [TestMethod, TestCategory(TypeName)]
215 {
216 POST_ThenDoAction(TestResource, posted =>
217 {
218 Assert.IsTrue(posted.status.IsBusy(), "Expected the server behaviour to " +
219 "be one that asynchronously processes new Analysis Profiles.");
221 Assert.AreEqual(TaskStatus.Success, ready.status, "Expected the final " +
222 "Analysis Profile status to be \"processing_succeeded\"");
223 // Check that the profile truly is ready by using it in a small layer_view
224 ILayerView test = LayerViews.Create(new Filter(), posted).Post();
225 Debug.WriteLine(test.id + " posted, so analysis profile must be ready.");
226 });
227 }
228
229 #endregion status
230
231 #region default_perspective
232 [TestMethod, TestCategory(TypeName)]
234 {
235 Skip.Indefinitely("ARE-6645: Remove skip and uncomment the AnalysisProfile.default_perspective" +
236 "ServerHasDefault attribute once API changes are complete.");
237 // Try a complex perspective
238 POST_WithValue(l => l.default_perspective, Perspective.LossNetOf(Perspective.Base.ReinstatementPremium), true);
239 // Try creating a variation on our analysis profile having every test perspective
241 POST_WithValue(l => l.default_perspective, persp, true);
242 }
243
244 [TestMethod, TestCategory(TypeName)]
246 {
247 POST_Attribute_Null(l => l.default_perspective);
248 }
249 #endregion default_perspective
250
251 #endregion POST
252
253 // Put not allowed, no need for detailed PUT tests.
254 }
255}
Tests for a stored resource collection which do not require an instance of that resource to be define...
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.
IInjectableResource< AnalysisProfile > AnalysisProfile
An analysis profile with one of each possible type of filter.
static IEnumerable< Perspective > TestPerspectives
Create a list of distinct perspectives to test.
override IResourceCollection< AnalysisProfile > collection_source
static string GetDefaultFilterNameForAnalysisProfile(IReference< AnalysisProfile > analysisProfile)
Get the name of the default filter of the analysis profile. This should be the first filter whose typ...
override IInjectableResource< AnalysisProfile > TestInjectableResource
A collection of filthy hacks to populate some fields of APIResources objects of any type.
Definition Reflection.cs:41
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< AnalysisProfile > AnalysisProfiles
The collection of AnalysisProfiles on the server.
A configuration of resources used to simulate a layer or portfolio.
LayerView factory class.
Definition LayerViews.cs:9
Filter is like a layer whose 'terms' are to filter events out of the loss sources....
Definition Filter.cs:13
Matches all losses (always returns true).
Definition AnyFilter.cs:4
The loss perspective determines what factors to include when computing a distribution.
static Perspective LossNetOf(params Base[] perspectives)
A convenience static method, similar to the other static singletons, which constructs a complex persp...
Base
The set of available values and RecordTypes that can be used to construct a distribution or metrics r...
T Unposted
The unPOSTed resource definition.
Represents the Analysis of a Layer.
TaskStatus
The status of a data upload which may be in progress.
Definition TaskStatus.cs:9