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