C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_References.cs
Go to the documentation of this file.
1using AnalyzeRe;
5
6#if MSTEST
7using Microsoft.VisualStudio.TestTools.UnitTesting;
8#elif NUNIT
9using NUnit.Framework;
10using TestClass = NUnit.Framework.TestFixtureAttribute;
11using TestMethod = NUnit.Framework.TestAttribute;
12using TestCategory = NUnit.Framework.CategoryAttribute;
13#endif
14
16{
19 [TestClass]
21 {
22 private const string Category = "Reference";
23
24 [TestMethod, TestCategory(Category)]
26 {
28 Assert.Inconclusive("RUN_OFFLINE = true");
30 IReference<EventCatalog> original = resource.ToReference();
31 EventCatalog resolved = original.GetValue();
32 AssertApi.AllPropertiesEqual(resolved, new Reference<EventCatalog>(resource.id).GetValue());
33 AssertApi.AllPropertiesEqual(resolved, (EventCatalog)new Reference<IAPIResource>(resource.id, original.href).GetValue());
34 AssertApi.AllPropertiesEqual(resolved, (EventCatalog)new Reference<IAPIResource>(original).GetValue());
35 AssertApi.AllPropertiesEqual(resolved, (EventCatalog)new Reference<APIResource>(original).GetValue());
36 }
37
38 [TestMethod, TestCategory(Category)]
40 {
42 Assert.Inconclusive("RUN_OFFLINE = true");
44 IReference<ILayer> original = resource.ToReference();
45 ILayer resolved = original.GetValue();
46 AssertApi.AllPropertiesEqual(resolved, new Reference<AggXL>(resource.id).GetValue());
47 AssertApi.AllPropertiesEqual(resolved, new Reference<Layer>(resource.id).GetValue());
48 AssertApi.AllPropertiesEqual(resolved, new Reference<ILayer>(resource.id).GetValue());
49 AssertApi.AllPropertiesEqual(resolved, (ILayer)new Reference<IAPIResource>(resource.id, original.href).GetValue());
50 AssertApi.AllPropertiesEqual(resolved, (ILayer)new Reference<IAPIResource>(original).GetValue());
51 AssertApi.AllPropertiesEqual(resolved, (ILayer)new Reference<APIResource>(original).GetValue());
52 }
53
54 [TestMethod, TestCategory(Category)]
56 {
58 Assert.Inconclusive("RUN_OFFLINE = true");
60 IReference<ILayerView<AggXL>> original = resource.ToReference();
61 ILayerView resolved = original.GetValue();
62 AssertApi.AllPropertiesEqual(resolved, new Reference<LayerView<AggXL>>(resource.id).GetValue());
63 AssertApi.AllPropertiesEqual(resolved, new Reference<LayerView<ILayer_WithTerms>>(resource.id).GetValue());
64 AssertApi.AllPropertiesEqual(resolved, new Reference<LayerView<ILayer>>(resource.id).GetValue());
65 AssertApi.AllPropertiesEqual(resolved, new Reference<ILayerView<AggXL>>(resource.id).GetValue());
66 AssertApi.AllPropertiesEqual(resolved, new Reference<ILayerView<ILayer>>(resource.id).GetValue());
67 AssertApi.AllPropertiesEqual(resolved, new Reference<ILayerView>(resource.id).GetValue());
68 AssertApi.AllPropertiesEqual(resolved, (ILayerView)new Reference<IAPIResource>(resource.id, original.href).GetValue());
69 AssertApi.AllPropertiesEqual(resolved, (ILayerView)new Reference<IAPIResource>(original).GetValue());
70 // Test that GetValue no longer requires the compile-time type of the reference to
71 // resolve to some known collection. It will use type information at construction time
72 // to gather the information needed to resolve the reference.
73 AssertApi.AllPropertiesEqual(resolved, (ILayerView)new Reference<APIResource>(original).GetValue());
74 // But if the reference is constructed using only an id, assert that an Exception is thrown
75 // because there is no collection information that can be derived from the reference instance.
76 AssertApi.ExceptionThrown<System.Exception>(
77 () => _ = (ILayerView)new Reference<APIResource>(original.ref_id).GetValue(),
78 ex => Assert.IsTrue(ex.Message.Contains(
79 "the collection for resources of type APIResource could not be determined")));
80 // But if we have a strongly typed reference to the run-time type of this object
81 // (a LayerView<AggXL> instance), that IS convertible to an APIResource reference.
82 original = Samples.LayerView_AggXL.Posted.ToReference(true);
83 Assert.AreEqual(typeof(Reference<LayerView<AggXL>>), original.GetType());
84 AssertApi.AllPropertiesEqual(resolved, (ILayerView)new Reference<APIResource>(original).GetValue());
85 }
86 }
87}
Create a test class that takes care of setting the server URL and cleaning up after each unit test.
Exposes sample resource objects, with built-in methods for injecting dependencies.
Definition Samples.cs:14
IInjectableResource< ILayerView< AggXL > > LayerView_AggXL
IInjectableResource< AggXL > Layer_AggXL
IInjectableResource< EventCatalog > EventCatalog
Test the Reference class to ensure references of different types and instantiated in different ways c...
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...
string id
The resource's unique identifier. It will be used in the request URL when requesting the resource fro...
Representation of an event catalog. The event catalog may cover multiple region/perils,...
Represents the Analysis of a Layer.
Implements the reference entity interface, with support for resolving references using lazy loading.
T GetValue(IEnumerable< Parameter > requestParameters=null, int? timeout=null, bool updateCache=false)
Gets the resource that this reference refers to. If the reference has not previously been resolved,...
T Posted
The posted resource, ready to be referenced.
string id
The resource's unique identifier. It will be used in the request URL when requesting the resource fro...
Represents the Analysis of a Layer.
Abstract representation of a layer.
Definition ILayer.cs:7
Base interface for all reference entities.
string ref_id
The id of the object being referred to.
Definition IReference.cs:17
string href
The HREF that can be used to retrieve the object being referred to.
Definition IReference.cs:22
T GetValue(IEnumerable< Parameter > requestParameters=null, int? timeout=null, bool updateCache=false)
Gets the resource that this reference refers to by requesting it from the server.