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