C# Client Library
A C# Client Library for the AnalyzeRe REST API
Test_API_SettingsProvider.cs
Go to the documentation of this file.
1 using System.Collections.Specialized;
3 
4 #if MSTEST
5 using Microsoft.VisualStudio.TestTools.UnitTesting;
6 #elif NUNIT
7 using NUnit.Framework;
8 using TestClass = NUnit.Framework.TestFixtureAttribute;
9 using TestMethod = NUnit.Framework.TestAttribute;
10 #endif
11 
12 namespace AnalyzeReTesting.Tests.AnalyzeReAPI
13 {
14  [TestClass]
16  {
19  private static readonly object ParallelTestLock = new object();
20 
21  [TestMethod]
23  {
24  lock (ParallelTestLock)
25  {
28  WriteAndReadSettings();
29  }
30  }
31 
32  [TestMethod]
34  {
35  lock (ParallelTestLock)
36  {
39  WriteAndReadSettings();
40  }
41  }
42 
43  private void WriteAndReadSettings()
44  {
45  int? originalTimeout = null;
46  string originalServerURL = null;
47  StringCollection originalCachedCredentials = null;
48 
49  int timeout = 1234;
50  string serverURL = "http://www.google.com";
51  string cred1 = "asd|123";
52  string cred2 = "def|456";
53 
54  Settings writeSettings = new Settings();
55  try
56  {
57  // Remember the original settings before we test changing them
58  originalTimeout = writeSettings.User_DEFAULT_REQUEST_TIMEOUT;
59  originalServerURL = writeSettings.ServerURL;
60  originalCachedCredentials = writeSettings.CachedCredentials;
61 
62  // Set some values (while keeping some information so that we can undo our actions)
63  writeSettings.User_DEFAULT_REQUEST_TIMEOUT = timeout;
64  writeSettings.ServerURL = serverURL;
65  writeSettings.CachedCredentials = new StringCollection { cred1, cred2 };
66  writeSettings.Save();
67 
68  // With a new settings instance, we should see the values we just set
69  Settings readSettings = new Settings();
70  Assert.AreEqual(timeout, readSettings.User_DEFAULT_REQUEST_TIMEOUT);
71  Assert.AreEqual(serverURL, readSettings.ServerURL);
72  Assert.AreEqual(2, readSettings.CachedCredentials.Count);
73  Assert.IsTrue(readSettings.CachedCredentials.Contains(cred1));
74  Assert.IsTrue(readSettings.CachedCredentials.Contains(cred2));
75  }
76  finally
77  {
78  // If this value hasn't been set, it means we threw before even reading the original settings.
79  if (originalTimeout.HasValue)
80  {
81  // Clean up the values we set during this test
82  writeSettings.User_DEFAULT_REQUEST_TIMEOUT = originalTimeout.Value;
83  writeSettings.ServerURL = originalServerURL;
84  writeSettings.CachedCredentials = originalCachedCredentials;
85  writeSettings.Save();
86  }
87  }
88  }
89  }
90 }
global::System.Collections.Specialized.StringCollection CachedCredentials
A collection of cached authentication tokens which can be used to restore a previous connection betwe...
This part of the Settings class is not generated from the Settings.settings designer, and only used to set the SettingsProvider for the class.
Definition: Settings.cs:10
string ServerURL
The last API url to connected to. This can be used to override the default URL to restore a previous ...
A SettingsProvider that can be shared by both the AnalyzeRe.Client library, and users of the library ...
int User_DEFAULT_REQUEST_TIMEOUT
The user-overridden value for the default request timeout.
static SettingsLocation GlobalSettingsLocation
Sets the location
SettingsLocation
Allows configuration of the internal settings provider used by instances of this class.