Skip to content

Commit 80a485e

Browse files
Addition of async methods (#80)
* Async methods added * Tests for async added * Sync methods are marked as obsolete * README updated --------- Co-authored-by: Denis Averin <denis.averin@aspose.com>
1 parent fa033b7 commit 80a485e

23 files changed

Lines changed: 2539 additions & 123 deletions

.github/workflows/net-framework.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
- uses: actions/checkout@v3
3030

3131
- name: Setup MSBuild
32-
uses: microsoft/setup-msbuild@v1
32+
uses: microsoft/setup-msbuild@v1.1
3333

3434
- name: Setup VSTest
35-
uses: darenm/Setup-VSTest@v1
35+
uses: darenm/Setup-VSTest@v1.2
3636

3737
- name: Build the Solution
3838
run: msbuild -restore -p:Configuration=Release
@@ -41,7 +41,7 @@ jobs:
4141
run: |
4242
$ErrorActionPreference = "Stop"
4343
VSTest.Console.exe /Framework:".NETFramework,Version=${{ matrix.net-version }}" /ResultsDirectory:Tests\Results /Logger:"trx;LogFileName=test.log" Tests\bin\Release\${{ matrix.framework }}\Aspose.BarCode.Cloud.Sdk.Tests.dll
44-
if( ([xml](Get-Content Tests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 24 ){ throw "Not all tests were explored or added new tests" }
44+
if( ([xml](Get-Content Tests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 38 ){ throw "Not all tests were explored or added new tests" }
4545
4646
env:
4747
TEST_CONFIGURATION_JWT_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ using System.Reflection;
7474

7575
namespace ReadQR
7676
{
77-
class Program
77+
internal static class Program
7878
{
79-
static Configuration MakeConfiguration()
79+
private static Configuration MakeConfiguration()
8080
{
8181
var config = new Configuration();
8282

83-
var envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
83+
string envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_JWT_TOKEN");
8484
if (string.IsNullOrEmpty(envToken))
8585
{
8686
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
@@ -94,7 +94,7 @@ namespace ReadQR
9494
return config;
9595
}
9696

97-
static string ReadQR(IBarcodeApi api, string fileName)
97+
private static string ReadQR(IBarcodeApi api, string fileName)
9898
{
9999
using (FileStream imageStream = File.OpenRead(fileName))
100100
{
@@ -109,10 +109,10 @@ namespace ReadQR
109109
static void Main(string[] args)
110110
{
111111
string fileName = Path.GetFullPath(Path.Join(
112-
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
112+
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
113113
"..", "..", "..", "..",
114114
"qr.png"
115-
));
115+
));
116116

117117
var api = new BarcodeApi(MakeConfiguration());
118118

@@ -159,14 +159,17 @@ namespace GenerateQR
159159
return config;
160160
}
161161

162-
static void GenerateQR(IBarcodeApi api, string fileName)
162+
private static void GenerateQR(IBarcodeApi api, string fileName)
163163
{
164164
using (Stream generated = api.GetBarcodeGenerate(
165-
new GetBarcodeGenerateRequest(
166-
EncodeBarcodeType.QR.ToString(),
167-
"QR code text",
168-
textLocation: "None", format: "png"))
169-
)
165+
new GetBarcodeGenerateRequest(
166+
EncodeBarcodeType.QR.ToString(),
167+
"QR code text")
168+
{
169+
TextLocation = "None",
170+
format = "png"
171+
})
172+
)
170173
{
171174
using (FileStream stream = File.Create(fileName))
172175
{
@@ -178,10 +181,10 @@ namespace GenerateQR
178181
static void Main(string[] args)
179182
{
180183
string fileName = Path.GetFullPath(Path.Join(
181-
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
184+
Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location),
182185
"..", "..", "..", "..",
183186
"qr.png"
184-
));
187+
));
185188

186189
var api = new BarcodeApi(MakeConfiguration());
187190

Tests/ApiExceptionTests.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Aspose.BarCode.Cloud.Sdk.Model;
33
using Aspose.BarCode.Cloud.Sdk.Model.Requests;
44
using NUnit.Framework;
5+
using System;
6+
using System.Threading.Tasks;
57

68
namespace Aspose.BarCode.Cloud.Sdk.Tests
79
{
@@ -23,9 +25,37 @@ public void GetBarcodeGenerateTestThrows()
2325

2426
// Act
2527
var ex = Assert.Throws<ApiException>(
26-
() => { api.GetBarcodeGenerate(request); });
28+
() =>
29+
{
30+
#pragma warning disable CS0618 // Method is obsolete
31+
api.GetBarcodeGenerate(request);
32+
#pragma warning restore CS0618 // Method is obsolete
33+
});
2734

28-
Assert.AreEqual(400, ex.ErrorCode);
35+
// Assert
36+
Assert.AreEqual(400, ex!.ErrorCode);
37+
Assert.AreEqual("Bad Request", ex.Message);
38+
}
39+
40+
[Test]
41+
[Category("AsyncTests")]
42+
public void GetBarcodeGenerateAsyncTestThrows()
43+
{
44+
// Arrange
45+
var api = new BarcodeApi(clientId: "client id", clientSecret: "client secret");
46+
var request = new GetBarcodeGenerateRequest(
47+
text: "Very sample text",
48+
type: EncodeBarcodeType.Code128.ToString()
49+
)
50+
{
51+
format = "png"
52+
};
53+
54+
// Acts
55+
var ex = Assert.ThrowsAsync<ApiException>(
56+
async () => { await api.GetBarcodeGenerateAsync(request); });
57+
58+
Assert.AreEqual(400, ex!.ErrorCode);
2959
Assert.AreEqual("Bad Request", ex.Message);
3060
}
3161
}

Tests/Aspose.BarCode.Cloud.Sdk.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<None Remove="TestResults\**" />
1313
</ItemGroup>
1414
<ItemGroup>
15-
<PackageReference Include="Moq" Version="4.20.69" />
15+
<PackageReference Include="Moq" Version="4.20.70" />
1616
<PackageReference Include="NUnit" Version="3.14.0" />
1717
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
1818
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />

0 commit comments

Comments
 (0)