-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfigurationTests.cs
More file actions
135 lines (107 loc) · 3.84 KB
/
ConfigurationTests.cs
File metadata and controls
135 lines (107 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System.Collections.Generic;
using System.IO;
using Aspose.BarCode.Cloud.Sdk.Api;
using System.Text.Json;
using NUnit.Framework;
namespace Aspose.BarCode.Cloud.Sdk.Tests
{
[TestFixture]
public class ConfigurationTests
{
private readonly Dictionary<string, string> _headers = new Dictionary<string, string>
{
["User-Agent"] = "Awesome SDK"
};
[Test]
public void CanChangeApiBaseUrl()
{
Configuration config = new Configuration
{
ApiBaseUrl = "http://localhost:47972"
};
Assert.AreEqual("http://localhost:47972/v4.0", config.GetApiRootUrl());
}
[Test]
public void CanChangeDefaultHeaders()
{
// ReSharper disable once UseObjectOrCollectionInitializer
Configuration config = new Configuration();
config.DefaultHeaders["User-Agent"] = "Awesome SDK";
Assert.AreEqual("Awesome SDK", config.DefaultHeaders["User-Agent"]);
}
[Test]
public void CanSetAuthTypeAndTokenTest()
{
Configuration config = new Configuration
{
JwtToken = "Test JWT token"
};
Assert.AreEqual("Test JWT token", config.JwtToken);
Assert.AreEqual(AuthType.ExternalAuth, config.AuthType);
}
[Test]
public void CanSetDebugMode()
{
Configuration config = new Configuration
{
DebugMode = true
};
Assert.AreEqual(true, config.DebugMode);
}
[Test]
public void CanSetDefaultHeaders()
{
Configuration config = new Configuration
{
DefaultHeaders = _headers
};
Assert.AreEqual("Awesome SDK", config.DefaultHeaders["User-Agent"]);
}
[Test]
public void DefaultParamsTest()
{
Configuration config = new Configuration();
Assert.AreEqual("https://api.aspose.cloud", config.ApiBaseUrl);
Assert.AreEqual("https://api.aspose.cloud/v4.0", config.GetApiRootUrl());
Assert.AreEqual("https://id.aspose.cloud/connect/token", config.TokenUrl);
Assert.AreEqual(false, config.DebugMode);
}
[Test]
public void DeserializeTest()
{
using FileStream file = File.OpenRead(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"..", "..", "..",
"Configuration.template.json"));
var config = JsonSerializer.Deserialize<Configuration>(file);
Assert.IsNotNull(config);
Assert.AreEqual("Client Secret from https://dashboard.aspose.cloud/applications", config.ClientSecret);
Assert.AreEqual("Client Id from https://dashboard.aspose.cloud/applications", config.ClientId);
Assert.AreEqual(AuthType.JWT, config.AuthType);
}
[Test]
public void GetApiVersionTest()
{
Configuration config = new Configuration();
Assert.AreEqual("4.0", config.ApiVersion);
}
[Test]
public void SerializationTest()
{
Configuration config = new Configuration();
Assert.AreEqual(
"{\"" +
"ApiBaseUrl\":\"https://api.aspose.cloud\",\"" +
"TokenUrl\":\"https://id.aspose.cloud/connect/token\",\"" +
"ClientSecret\":null,\"" +
"ClientId\":null,\"" +
"JwtToken\":null,\"" +
"DebugMode\":false,\"" +
"AuthType\":\"JWT\",\"" +
"ApiVersion\":\"4.0\",\"" +
"DefaultHeaders\":{}" +
"}",
JsonSerializer.Serialize(config));
}
}
}