C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_EventCatalog.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5using AnalyzeRe;
10
11#if MSTEST
12using Microsoft.VisualStudio.TestTools.UnitTesting;
13#elif NUNIT
14using NUnit.Framework;
15using TestClass = NUnit.Framework.TestFixtureAttribute;
16using TestMethod = NUnit.Framework.TestAttribute;
17using TestCategory = NUnit.Framework.CategoryAttribute;
18#endif
19
21{
22 [TestClass]
27
28 [TestClass]
29 public sealed class TestSuite_EventCatalog : BaseResourceWithDataTestSuite<EventCatalog>
30 {
31 #region Set Up and Configuration
32 private const string TypeName = "EventCatalog";
35
36 protected override string POSTData => Samples.CSV.Event_Catalog_Data;
37 #endregion Set Up and Configuration
38
39 #region POST
40 #region source
41 [TestMethod, TestCategory(TypeName)]
43 {
44 POST_Attribute_Null(e => e.source);
45 }
46 [TestMethod, TestCategory(TypeName)]
48 {
49 POST_StringAttribute_Empty(e => e.source);
50 }
51 #endregion source
52
53 #region tags
54 [TestMethod, TestCategory(TypeName)]
56 {
57 POST_Attribute_Null(e => e.tags);
58 }
59 [TestMethod, TestCategory(TypeName)]
61 {
63 }
64 [TestMethod, TestCategory(TypeName)]
66 {
67 POST_ListAttribute_Duplicates(e => e.tags, "Duplicate", false);
68 }
69 #endregion tags
70
71 // TODO: Post with various valid and invalid event catalog data.
72 #endregion POST
73
74 #region PUT
75 #region source
76 [TestMethod, TestCategory(TypeName)]
78 {
79 PUT_WithValue(e => e.source, "Modified Source", true);
80 }
81 [TestMethod, TestCategory(TypeName)]
83 {
84 PUT_Attribute_Null(e => e.source);
85 }
86 [TestMethod, TestCategory(TypeName)]
88 {
89 PUT_StringAttribute_Empty(e => e.source);
90 }
91 #endregion source
92
93 #region tags
94 [TestMethod, TestCategory(TypeName)]
96 {
97 PUT_WithValue(e => e.tags, new List<string> { "Modified 1", "Modified 2" }, true);
98 }
99 [TestMethod, TestCategory(TypeName)]
101 {
102 PUT_Attribute_Null(e => e.tags);
103 }
104 [TestMethod, TestCategory(TypeName)]
106 {
107 PUT_ListAttribute_Empty(e => e.tags);
108 }
109 [TestMethod, TestCategory(TypeName)]
111 {
112 PUT_ListAttribute_Duplicates(e => e.tags, "Duplicate", false);
113 }
114 #endregion tags
115 #endregion PUT
116
117 #region Test Data
118 [TestMethod, TestCategory(TypeName)]
120 {
121 GenericTest.POST_InvalidResourceWithData_Fails(TestResource,
122 "\"EventId\",\"Rate\"", (CommitFailedException ex) => { });
123 }
124 #endregion Test Data
125
126 #region Test Profile
127 [TestMethod, TestCategory(TypeName)]
129 {
130 EventCatalog posted = TestResource_Existing;
131 EventCatalog.Profile profile = posted.profile.Get();
132 Assert.IsNotNull(profile.attributes,
133 "The catalog profile had no attributes list.");
134 Assert.AreNotEqual(0, profile.attributes.Count,
135 "The catalog profile's attributes list was empty.");
136 // Print the profile for debugging purposes.
137 Console.WriteLine($"Event Catalog Profile:\n{profile.Serialize()}");
138
139 // Every profile should contain Rate and EventId attributes
140 EventCatalog.Attribute rate = profile.attributes.SingleOrDefault(
141 a => a.name.Equals("rate", StringComparison.InvariantCultureIgnoreCase));
142 Assert.IsNotNull(rate, "The profile had no \"rate\" attribute.");
143 Assert.AreEqual("float", rate.type,
144 "Expected the required \"rate\" column to be interpreted as a \"float\" type");
145
146 EventCatalog.Attribute eventId = profile.attributes.SingleOrDefault(
147 a => a.name.Equals("eventid", StringComparison.InvariantCultureIgnoreCase));
148 Assert.IsNotNull(eventId, "The profile had no \"eventid\" attribute.");
149 Assert.AreEqual("int", eventId.type,
150 "Expected the required \"eventid\" column to be interpreted as a \"int\" type");
151
152 // We know our test resource has the following attributes:
153 // "Attribute1","Attribute2","NumericAttribute","IntegerAttribute"
154 // These test assertions may need to change if the test data is modified
156 profile.attributes.Single(a => a.name == "Attribute1");
157 Assert.AreEqual("str", attrib.type);
158 Assert.IsTrue(attrib.values.SetEquals(new [] { "A", "B" }));
159
160 attrib = profile.attributes.Single(a => a.name == "Attribute2");
161 Assert.AreEqual("str", attrib.type);
162 Assert.IsTrue(attrib.values.SetEquals(new[] { "X", "Y" }));
163
164 attrib = profile.attributes.Single(a => a.name == "NumericAttribute");
165 Assert.AreEqual("float", attrib.type);
166
167 attrib = profile.attributes.Single(a => a.name == "IntegerAttribute");
168 Assert.AreEqual("int", attrib.type);
169 }
170 #endregion Test Profile
171 }
172}
Tests for a stored resource collection which do not require an instance of that resource to be define...
Exposes the various sample CSV files as strings.
Definition Samples.CSV.cs:9
static string Event_Catalog_Data
Exposes sample resource objects, with built-in methods for injecting dependencies.
Definition Samples.cs:14
IInjectableResource< EventCatalog > EventCatalog
override IResourceCollection< EventCatalog > collection_source
override IInjectableResource< EventCatalog > TestInjectableResource
Generic Unit test implementations that will test REST methods on arbitrary resources.
Describes a collection of resources which can be listed.
API methods / requests made available to the user.
static readonly ResourceCollection< EventCatalog > EventCatalogs
The collection of EventCatalogs on the server.
Represents a column of values parsed out of the catalog.
string type
The type of values that appear in this column, as determined by the server.
An object retrieved from the EventCatalog.profile endpoint of a catalog that describes the columns in...
List< Attribute > attributes
The set of all columns parsed from the catalog.
Representation of an event catalog. The event catalog may cover multiple region/perils,...
Exception raised when the commit process fails.