C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
BaseStoredResourceTestSuite.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5using AnalyzeRe;
8#if MSTEST
9using Microsoft.VisualStudio.TestTools.UnitTesting;
10#elif NUNIT
11using NUnit.Framework;
12using TestClass = NUnit.Framework.TestFixtureAttribute;
13using TestMethod = NUnit.Framework.TestAttribute;
14using TestCategory = NUnit.Framework.CategoryAttribute;
15#endif
16
18{
19 [TestClass]
21 {
22 #region Properties
23 private const string TypeName = "BaseStoredResourceTest";
24 #endregion Properties
25
26 #region GET
28 [TestMethod, TestCategory(TypeName)]
30 {
32 Assert.Inconclusive("RUN_OFFLINE = true");
35 AssertApi.AllPropertiesEqual(posted, getResult);
37 }
38 #endregion GET
39
40 #region POST
41 #region description
42 [TestMethod, TestCategory(TypeName)]
44 {
45 POST_Attribute_Null(a => a.description);
46 }
47
48 [TestMethod, TestCategory(TypeName)]
50 {
51 POST_StringAttribute_Empty(a => a.description);
52 }
53 #endregion description
54
55 #region created and modified
56 [TestMethod, TestCategory(TypeName)]
58 {
60 {
61 Assert.IsNotNull(posted.created, "Expected a 'created' date to be assigned.");
62 Assert.IsNotNull(posted.modified, "Expected a 'modified' date to be assigned.");
63 Assert.AreEqual(posted.created, posted.modified,
64 "Expected the created and modified date to be equal on a newly posted resource.");
65 });
66 }
67 #endregion created and modified
68
69 #region meta_data
70 [TestMethod, TestCategory(TypeName)]
72 {
73 POST_Attribute_Null(a => a.meta_data);
74 }
75 [TestMethod, TestCategory(TypeName)]
77 {
78 POST_WithValue(l => l.meta_data, new Dictionary<string, object>(), true);
79 }
80 [TestMethod, TestCategory(TypeName)]
82 {
84 {
85 { "Test1", "TestValue" },
86 { "Test2", 2 },
87 { "Test 3", 3.33 },
88 { "Test 4", true }
89 };
90 POST_WithValue(l => l.meta_data, mixedTypes, true);
91 }
92 [TestMethod, TestCategory(TypeName)]
94 {
95 Dictionary<string, object> TestDict(string key, object value) =>
96 new Dictionary<string, object> { { key, value } };
97
98 POST_WithValue(l => l.meta_data, TestDict("Test1", TestDict("Nested", "Nested")), false);
99 POST_WithValue(l => l.meta_data, TestDict("Test1", null), false);
100 POST_WithValue(l => l.meta_data, TestDict("Test1", Double.PositiveInfinity), false);
101 POST_WithValue(l => l.meta_data, TestDict("Test1", Double.NaN), false);
102 }
103 #endregion meta_data
104 #endregion POST
105
106 #region Collection GET Methods
108 [TestMethod, TestCategory(TypeName)]
109 public virtual void Test_Resource_Search()
110 {
112 Assert.Inconclusive("RUN_OFFLINE = true");
113
114 // Create a variation of our test resource with a unique description and metadata.
115 string unique_description = Guid.NewGuid().ToString();
116 string unique_metadata = Guid.NewGuid().ToString();
117 T uniqueToPost = TestResource.Change(r => r.description, unique_description);
118 uniqueToPost.meta_data["GUID"] = unique_metadata;
120 {
121 // Test that we can find this exact resource using the unique description we gave it in a simple search
123 Assert.AreEqual(1, batchGetResponse.meta.total_count);
124 Assert.AreEqual(uniqueResource.id, batchGetResponse.items.Single().id);
125
126 // Test that we can find this exact resource using the custom metadata we gave it in an advanced search
128 $"meta_data[GUID]={unique_metadata}", searchType: API.SearchType.Advanced);
129 Assert.AreEqual(1, batchGetResponse.meta.total_count);
130 Assert.AreEqual(uniqueResource.id, batchGetResponse.items.Single().id);
131 });
132 }
133 #endregion Collection GET Methods
134 }
135}
void POST_StringAttribute_Empty(Expression< Func< T, string > > PropertyExpression, bool? shouldSucceed=null)
Post a resource with the specified string set to an empty string.
virtual T TestResource_Existing
The resource used for all unit tests that require a prepared and already posted resource....
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...
virtual void Test_Resource_GET_Existing_ResolveReferences()
IStoredAPIResource collections support reference resolution.
virtual void Test_Resource_Search()
All resources should support searching in a few fundamental ways.
static void ReferencesResolved(object obj)
Definition AssertApi.cs:558
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...
Describes a collection of resources which can be listed.
Parameters that can be added to your REST requests to access additional API features.
static RequestParameters ExpandReferences()
Can be added to your GET requests to recursively resolve resource references in the response....
API methods / requests made available to the user.
static ICollectionResponse< IAPIResource > SearchResourceList(Type resourceType, string searchTerms, IEnumerable< Parameter > requestParameters=null, string collectionNameOverride=null, int? timeout=null, SearchType searchType=SearchType.Basic)
Get a collection of resources from the server that match the specified search criteria.
SearchType
The search type determines the interpretation of the query string.
Interface for Base class used by all stored resources.