Skip to content

Commit bdaf9d5

Browse files
authored
ApiException class made public (#7)
* 20.6.0 * Code cleanup
1 parent e90ca60 commit bdaf9d5

File tree

111 files changed

+2256
-2102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2256
-2102
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ bin
55
obj
66
.vs
77
Tests/Configuration*.json
8+
*.DotSettings

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Aspose.BarCode Cloud SDK for .NET
22

33
- API version: 3.0
4-
- SDK version: 20.5
4+
- SDK version: 20.6.0
55

66
[Aspose.BarCode for Cloud](https://products.aspose.cloud/barcode/cloud) is a REST API for Linear, 2D and postal barcode generation and recognition in the cloud. API recognizes and generates barcode images in a variety of formats. Barcode REST API allows to specify barcode image attributes like image width, height, border style and output image format in order to customize the generation process. Developers can also specify the barcode type and text attributes such as text location and font styles in order to suit the application requirements.
77

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// --------------------------------------------------------------------------------------------------------------------
2-
// <copyright company="Aspose" file="BarCodeApi.cs">
2+
// <copyright company="Aspose" file="ApiExceptionTests.cs">
33
// Copyright (c) 2020 Aspose.BarCode for Cloud
44
// </copyright>
55
// <summary>
@@ -23,28 +23,34 @@
2323
// </summary>
2424
// --------------------------------------------------------------------------------------------------------------------
2525

26-
namespace Aspose.BarCode.Cloud.Sdk.Internal
26+
using Aspose.BarCode.Cloud.Sdk.Api;
27+
using Aspose.BarCode.Cloud.Sdk.Model;
28+
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
29+
using NUnit.Framework;
30+
31+
namespace Tests
2732
{
28-
/// <summary>
29-
/// The available api versions.
30-
/// </summary>
31-
internal class ApiVersion
33+
[TestFixture]
34+
public class ApiExceptionTests : TestsBase
3235
{
33-
private string Version { get; }
34-
private ApiVersion(string version)
36+
[Test]
37+
public void GetBarcodeGenerateTestThrows()
3538
{
36-
Version = version;
37-
}
38-
39-
//public static ApiVersion V1 = new ApiVersion("1.0");
40-
//public static ApiVersion V1_1 = new ApiVersion("1.1");
39+
// Arrange
40+
var config = new Configuration();
41+
var api = new BarcodeApi(config);
42+
var request = new GetBarcodeGenerateRequest(
43+
text: "Very sample text",
44+
type: EncodeBarcodeType.Code128.ToString(),
45+
format: "png"
46+
);
4147

42-
public static readonly ApiVersion V3 = new ApiVersion("3.0");
48+
// Act
49+
var ex = Assert.Throws<ApiException>(
50+
() => { api.GetBarcodeGenerate(request); });
4351

44-
public override string ToString()
45-
{
46-
return Version;
52+
Assert.AreEqual(400, ex.ErrorCode);
53+
Assert.AreEqual("Bad Request", ex.Message);
4754
}
4855
}
49-
5056
}

Tests/BarcodeApiTests.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
using System.Collections.Generic;
2727
using System.IO;
2828
using System.Linq;
29-
using Aspose.BarCode.Cloud.Sdk;
3029
using Aspose.BarCode.Cloud.Sdk.Api;
3130
using Aspose.BarCode.Cloud.Sdk.Interfaces;
3231
using Aspose.BarCode.Cloud.Sdk.Model;
@@ -37,19 +36,17 @@
3736
namespace Tests
3837
{
3938
/// <summary>
40-
/// Class for testing BarcodeApi
39+
/// Class for testing BarcodeApi
4140
/// </summary>
4241
/// <remarks>
43-
/// This file is automatically generated by Swagger Codegen.
44-
/// Please update the test case below to test the API endpoint.
42+
/// This file is automatically generated by Swagger Codegen.
43+
/// Please update the test case below to test the API endpoint.
4544
/// </remarks>
4645
[TestFixture]
4746
public class BarcodeApiTests : TestsBase
4847
{
49-
private IBarcodeApi _api;
50-
5148
/// <summary>
52-
/// Setup before each unit test
49+
/// Setup before each unit test
5350
/// </summary>
5451
[SetUp]
5552
public void Init()
@@ -65,13 +62,15 @@ public void Init()
6562
}
6663

6764
/// <summary>
68-
/// Clean up after each unit test
65+
/// Clean up after each unit test
6966
/// </summary>
7067
[TearDown]
7168
public void Cleanup()
7269
{
7370
}
7471

72+
private IBarcodeApi _api;
73+
7574
private static string PutTestFile(IBarcodeApi api, string fileName, List<GeneratorParams> barcodes)
7675
{
7776
var generatorParamsList = new GeneratorParamsList
@@ -92,18 +91,9 @@ private static string PutTestFile(IBarcodeApi api, string fileName, List<Generat
9291
return folder;
9392
}
9493

95-
/// <summary>
96-
/// Test an instance of BarcodeApi
97-
/// </summary>
98-
[Test]
99-
public void InstanceTest()
100-
{
101-
Assert.IsInstanceOf(typeof(IBarcodeApi), _api, "instance is a IBarcodeApi");
102-
}
103-
10494

10595
/// <summary>
106-
/// Test GetBarcodeGenerate
96+
/// Test GetBarcodeGenerate
10797
/// </summary>
10898
[Test]
10999
public void GetBarcodeGenerateTest()
@@ -128,7 +118,7 @@ public void GetBarcodeGenerateTest()
128118
}
129119

130120
/// <summary>
131-
/// Test GetBarcodeRecognize
121+
/// Test GetBarcodeRecognize
132122
/// </summary>
133123
[Test]
134124
public void GetBarcodeRecognizeTest()
@@ -139,12 +129,12 @@ public void GetBarcodeRecognizeTest()
139129
new GeneratorParams
140130
{
141131
TypeOfBarcode = EncodeBarcodeType.QR,
142-
Text = "Hello world!",
132+
Text = "Hello world!"
143133
},
144134
new GeneratorParams
145135
{
146136
TypeOfBarcode = EncodeBarcodeType.Code128,
147-
Text = "Hello world!",
137+
Text = "Hello world!"
148138
}
149139
};
150140

@@ -172,7 +162,16 @@ public void GetBarcodeRecognizeTest()
172162
}
173163

174164
/// <summary>
175-
/// Test PostBarcodeRecognizeFromUrlOrContent
165+
/// Test an instance of BarcodeApi
166+
/// </summary>
167+
[Test]
168+
public void InstanceTest()
169+
{
170+
Assert.IsInstanceOf(typeof(IBarcodeApi), _api, "instance is a IBarcodeApi");
171+
}
172+
173+
/// <summary>
174+
/// Test PostBarcodeRecognizeFromUrlOrContent
176175
/// </summary>
177176
[Test]
178177
public void PostBarcodeRecognizeFromUrlOrContentTest()
@@ -198,7 +197,7 @@ public void PostBarcodeRecognizeFromUrlOrContentTest()
198197
}
199198

200199
/// <summary>
201-
/// Test PostGenerateMultiple
200+
/// Test PostGenerateMultiple
202201
/// </summary>
203202
[Test]
204203
public void PostGenerateMultipleTest()
@@ -212,12 +211,12 @@ public void PostGenerateMultipleTest()
212211
new GeneratorParams
213212
{
214213
TypeOfBarcode = EncodeBarcodeType.QR,
215-
Text = "Hello world!",
214+
Text = "Hello world!"
216215
},
217216
new GeneratorParams
218217
{
219218
TypeOfBarcode = EncodeBarcodeType.Code128,
220-
Text = "Hello world!",
219+
Text = "Hello world!"
221220
}
222221
}
223222
}
@@ -237,7 +236,7 @@ public void PostGenerateMultipleTest()
237236
}
238237

239238
/// <summary>
240-
/// Test PutBarcodeGenerateFile
239+
/// Test PutBarcodeGenerateFile
241240
/// </summary>
242241
[Test]
243242
public void PutBarcodeGenerateFileTest()
@@ -260,7 +259,7 @@ public void PutBarcodeGenerateFileTest()
260259
}
261260

262261
/// <summary>
263-
/// Test PutBarcodeRecognizeFromBody
262+
/// Test PutBarcodeRecognizeFromBody
264263
/// </summary>
265264
[Test]
266265
public void PutBarcodeRecognizeFromBodyTest()
@@ -271,12 +270,12 @@ public void PutBarcodeRecognizeFromBodyTest()
271270
new GeneratorParams
272271
{
273272
TypeOfBarcode = EncodeBarcodeType.QR,
274-
Text = "PutBarcodeRecognizeFromBody QR",
273+
Text = "PutBarcodeRecognizeFromBody QR"
275274
},
276275
new GeneratorParams
277276
{
278277
TypeOfBarcode = EncodeBarcodeType.Code128,
279-
Text = "PutBarcodeRecognizeFromBody Code128",
278+
Text = "PutBarcodeRecognizeFromBody Code128"
280279
}
281280
};
282281

@@ -287,7 +286,7 @@ public void PutBarcodeRecognizeFromBodyTest()
287286
fileName,
288287
new ReaderParams
289288
{
290-
Preset = PresetType.HighPerformance,
289+
Preset = PresetType.HighPerformance
291290
},
292291
folder: folder
293292
);
@@ -308,7 +307,7 @@ public void PutBarcodeRecognizeFromBodyTest()
308307
}
309308

310309
/// <summary>
311-
/// Test PutGenerateMultiple
310+
/// Test PutGenerateMultiple
312311
/// </summary>
313312
[Test]
314313
public void PutGenerateMultipleTest()
@@ -321,7 +320,7 @@ public void PutGenerateMultipleTest()
321320
new GeneratorParams
322321
{
323322
TypeOfBarcode = EncodeBarcodeType.Code128,
324-
Text = "Hello world!",
323+
Text = "Hello world!"
325324
}
326325
}
327326
};
@@ -341,4 +340,4 @@ public void PutGenerateMultipleTest()
341340
Assert.True(response.ImageHeight > 0);
342341
}
343342
}
344-
}
343+
}

Tests/ConfigurationTests.cs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.IO;
2-
using Aspose.BarCode.Cloud.Sdk;
2+
using Aspose.BarCode.Cloud.Sdk.Api;
33
using Newtonsoft.Json;
44
using NUnit.Framework;
55

@@ -9,27 +9,24 @@ namespace Tests
99
public class ConfigurationTests
1010
{
1111
[Test]
12-
public void DefaultParamsTest()
12+
public void CanChangeApiBaseUrl()
1313
{
14-
var config = new Configuration();
14+
var config = new Configuration
15+
{
16+
ApiBaseUrl = "http://localhost:12345"
17+
};
1518

16-
Assert.AreEqual("https://api.aspose.cloud", config.ApiBaseUrl);
17-
Assert.AreEqual("https://api.aspose.cloud/v3.0", config.GetApiRootUrl());
18-
Assert.AreEqual(false, config.DebugMode);
19+
Assert.AreEqual("http://localhost:12345/v3.0", config.GetApiRootUrl());
1920
}
2021

2122
[Test]
22-
public void DeserializeTest()
23+
public void CanChangeDefaultHeaders()
2324
{
24-
Configuration config;
25-
using (StreamReader file = File.OpenText(Path.Combine("..", "..", "..", "Configuration.template.json")))
26-
{
27-
var serializer = new JsonSerializer();
28-
config = (Configuration) serializer.Deserialize(file, typeof(Configuration));
29-
}
25+
// ReSharper disable once UseObjectOrCollectionInitializer
26+
var config = new Configuration();
27+
config.DefaultHeaders["User-Agent"] = "Awesome SDK";
3028

31-
Assert.AreEqual("Test.AppKey", config.AppKey);
32-
Assert.AreEqual("Test.AppSid", config.AppSid);
29+
Assert.AreEqual("Awesome SDK", config.DefaultHeaders["User-Agent"]);
3330
}
3431

3532

@@ -39,28 +36,51 @@ public void CanSetAuthTypeAndTokenTest()
3936
var config = new Configuration {JwtToken = "Test JWT token"};
4037

4138
Assert.AreEqual("Test JWT token", config.JwtToken);
39+
Assert.AreEqual(AuthType.ExternalAuth, config.AuthType);
4240
}
4341

4442
[Test]
45-
public void CanChangeApiBaseUrl()
43+
public void CanSetDebugMode()
4644
{
4745
var config = new Configuration
4846
{
49-
ApiBaseUrl = "http://localhost:12345"
47+
DebugMode = true
5048
};
5149

52-
Assert.AreEqual("http://localhost:12345/v3.0", config.GetApiRootUrl());
50+
Assert.AreEqual(true, config.DebugMode);
5351
}
5452

5553
[Test]
56-
public void CanSetDebugMode()
54+
public void CanSetDefaultHeaders()
5755
{
58-
var config = new Configuration
56+
var config = new Configuration {DefaultHeaders = {["User-Agent"] = "Awesome SDK"}};
57+
58+
Assert.AreEqual("Awesome SDK", config.DefaultHeaders["User-Agent"]);
59+
}
60+
61+
[Test]
62+
public void DefaultParamsTest()
63+
{
64+
var config = new Configuration();
65+
66+
Assert.AreEqual("https://api.aspose.cloud", config.ApiBaseUrl);
67+
Assert.AreEqual("https://api.aspose.cloud/v3.0", config.GetApiRootUrl());
68+
Assert.AreEqual(false, config.DebugMode);
69+
}
70+
71+
[Test]
72+
public void DeserializeTest()
73+
{
74+
Configuration config;
75+
using (StreamReader file = File.OpenText(Path.Combine("..", "..", "..", "Configuration.template.json")))
5976
{
60-
DebugMode = true
61-
};
77+
var serializer = new JsonSerializer();
78+
config = (Configuration) serializer.Deserialize(file, typeof(Configuration));
79+
}
6280

63-
Assert.AreEqual(true, config.DebugMode);
81+
Assert.AreEqual("Test.AppKey", config.AppKey);
82+
Assert.AreEqual("Test.AppSid", config.AppSid);
83+
Assert.AreEqual(AuthType.JWT, config.AuthType);
6484
}
6585
}
66-
}
86+
}

0 commit comments

Comments
 (0)