Skip to content

Commit 6109a18

Browse files
Ivan KamkinIvan Kamkin
authored andcommitted
Split tests for .net and old .netframework
1 parent acc7b5f commit 6109a18

17 files changed

Lines changed: 677 additions & 15 deletions

.github/workflows/net-framework.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,26 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v4
3030

31-
- name: Setup .NET 10 SDK
32-
uses: actions/setup-dotnet@v4
33-
with:
34-
dotnet-version: '10.0.x'
35-
3631
- name: Setup MSBuild
3732
uses: microsoft/setup-msbuild@v1.1
3833

3934
- name: Setup VSTest
4035
uses: darenm/Setup-VSTest@v1.2
4136

37+
- name: Pack nuget
38+
run: |
39+
msbuild -restore -t:clean,rebuild,pack -p:Configuration=Release
40+
copy src\bin\Release\*.nupkg NetFrameworkTests
41+
4242
- name: Build the Solution
43-
run: msbuild -restore -p:Configuration=Release
43+
run: msbuild NetFrameworkTests\Aspose.BarCode.Cloud.Sdk.NetFrameworkTests.csproj -restore -p:Configuration=Release
44+
4445

4546
- name: Test with VSTest
4647
run: |
4748
$ErrorActionPreference = "Stop"
48-
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
49-
if( ([xml](Get-Content Tests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 25 ){ throw "Not all tests were explored or added new tests" }
49+
VSTest.Console.exe /Framework:".NETFramework,Version=${{ matrix.net-version }}" /ResultsDirectory:NetFrameworkTests\Results /Logger:"trx;LogFileName=test.log" NetFrameworkTests\bin\Release\${{ matrix.framework }}\Aspose.BarCode.Cloud.Sdk.NetFrameworkTests.dll
50+
if( ([xml](Get-Content NetFrameworkTests\Results\test.log)).TestRun.ResultSummary.Counters.total -ne 21 ){ throw "Not all tests were explored or added new tests" }
5051
5152
env:
5253
TEST_CONFIGURATION_JWT_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _ReSharper.*
44
bin
55
obj
66
.vs
7-
Tests/Configuration*.json
7+
Configuration.json
88
*.DotSettings
99
*.binlog
1010
snippets_test/

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ format:
1212
dotnet restore ./Aspose.BarCode.Cloud.Sdk.sln
1313
dotnet format ./Aspose.BarCode.Cloud.Sdk.sln --no-restore
1414
dotnet format --include ./snippets/
15+
dotnet format --include ./NetFrameworkTests/
1516
# Trim white space in comments
1617
find . -iname "*.cs" -exec sed -i -e 's_[[:space:]]*$$__' {} \;
1718

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Aspose.BarCode.Cloud.Sdk.Api;
2+
using Aspose.BarCode.Cloud.Sdk.Model;
3+
4+
using NUnit.Framework;
5+
6+
namespace Aspose.BarCode.Cloud.Sdk.Tests
7+
{
8+
[TestFixture]
9+
public class ApiExceptionTests : TestsBase
10+
{
11+
12+
[Test]
13+
[Category("AsyncTests")]
14+
public void GetBarcodeGenerateAsyncTestThrows()
15+
{
16+
// Arrange
17+
GenerateApi api = new GenerateApi(clientId: "client id", clientSecret: "client secret");
18+
19+
// Acts
20+
ApiException ex = Assert.ThrowsAsync<ApiException>(
21+
async () =>
22+
{
23+
await api.GenerateAsync(data: "Very sample text",
24+
barcodeType: EncodeBarcodeType.Code128, imageFormat: BarcodeImageFormat.Png);
25+
});
26+
27+
Assert.AreEqual(400, ex!.ErrorCode);
28+
Assert.AreEqual("{\"error\":\"invalid_client\"}: ", ex.Message);
29+
}
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>net462;net480;net481</TargetFrameworks>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<IsTestProject>true</IsTestProject>
7+
<LangVersion>8.0</LangVersion>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Remove="TestResults\**"/>
11+
<EmbeddedResource Remove="TestResults\**"/>
12+
<None Remove="TestResults\**"/>
13+
</ItemGroup>
14+
<ItemGroup>
15+
<PackageReference Include="Moq" Version="4.20.70"/>
16+
<PackageReference Include="NUnit" Version="3.14.0"/>
17+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
19+
<PackageReference Include="System.Net.Http" Version="4.3.4"/>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.11.0" />
23+
</ItemGroup>
24+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ClientId": "Client Id from https://dashboard.aspose.cloud/applications",
3+
"ClientSecret": "Client Secret from https://dashboard.aspose.cloud/applications"
4+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Aspose.BarCode.Cloud.Sdk.Api;
6+
using Aspose.BarCode.Cloud.Sdk.Interfaces;
7+
using Aspose.BarCode.Cloud.Sdk.Model;
8+
9+
using NUnit.Framework;
10+
11+
namespace Aspose.BarCode.Cloud.Sdk.Tests
12+
{
13+
[TestFixture]
14+
public class GenerateAndThenRecognize : TestsBase
15+
{
16+
[SetUp]
17+
public void Init()
18+
{
19+
_generateApi = new GenerateApi(TestConfiguration);
20+
_scanApi = new ScanApi(TestConfiguration);
21+
}
22+
23+
private IGenerateApi _generateApi;
24+
private IScanApi _scanApi;
25+
26+
[Test]
27+
[Category("AsyncTests")]
28+
public async Task GenerateAndThenRecognizeAsyncTest()
29+
{
30+
Stream generatedImage = await _generateApi.GenerateAsync(EncodeBarcodeType.QR, "Test");
31+
32+
BarcodeResponseList recognized = await _scanApi.ScanMultipartAsync(generatedImage);
33+
34+
Assert.AreEqual(1, recognized.Barcodes.Count);
35+
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), recognized.Barcodes.First().Type);
36+
Assert.AreEqual("Test", recognized.Barcodes.First().BarcodeValue);
37+
Assert.AreEqual(
38+
"{\"barcodes\":[{" +
39+
"\"barcodeValue\":\"Test\"," +
40+
"\"type\":\"QR\"," +
41+
"\"region\":[{\"x\":7,\"y\":6},{\"x\":49,\"y\":6},{\"x\":48,\"y\":48},{\"x\":6,\"y\":49}],\"checksum\":null}]}",
42+
recognized.ToString()
43+
);
44+
}
45+
}
46+
}

NetFrameworkTests/GenerateTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using Aspose.BarCode.Cloud.Sdk.Api;
5+
using Aspose.BarCode.Cloud.Sdk.Interfaces;
6+
using Aspose.BarCode.Cloud.Sdk.Model;
7+
8+
using NUnit.Framework;
9+
10+
namespace Aspose.BarCode.Cloud.Sdk.Tests
11+
{
12+
[TestFixture]
13+
public class GenerateTests : TestsBase
14+
{
15+
private IGenerateApi _api;
16+
17+
[SetUp]
18+
public void Init()
19+
{
20+
_api = new GenerateApi(TestConfiguration);
21+
}
22+
23+
[Test]
24+
public async Task TestBarcodeGenerateBarcodeTypeGet()
25+
{
26+
27+
Stream response = await _api.GenerateAsync(EncodeBarcodeType.Code128, "Hello!");
28+
29+
long contentLength = response.Length;
30+
Assert.True(contentLength > 0, "Content length is zero or negative");
31+
}
32+
33+
[Test]
34+
public async Task TestBarcodeGenerateBodyPost()
35+
{
36+
// Test case for barcode_generate_body_post
37+
// Generate barcode from params in body
38+
BarcodeImageParams imageParams = new BarcodeImageParams
39+
{
40+
ImageFormat = BarcodeImageFormat.Jpeg
41+
};
42+
43+
EncodeData encodeData = new EncodeData()
44+
{
45+
Data = "VGVzdA==",
46+
DataType = EncodeDataType.Base64Bytes
47+
};
48+
49+
GenerateParams generatorParams = new GenerateParams()
50+
{
51+
BarcodeType = EncodeBarcodeType.QR,
52+
EncodeData = encodeData,
53+
BarcodeImageParams = imageParams
54+
};
55+
56+
57+
Stream response = await _api.GenerateBodyAsync(generatorParams);
58+
59+
long contentLength = response.Length;
60+
Assert.True(contentLength > 0, "Content length is zero or negative");
61+
}
62+
63+
[Test]
64+
public async Task TestBarcodeGenerateMultipartPost()
65+
{
66+
67+
Stream response = await _api.GenerateMultipartAsync(EncodeBarcodeType.QR, "54657374", dataType: EncodeDataType.HexBytes);
68+
69+
long contentLength = response.Length;
70+
Assert.True(contentLength > 0, "Content length is zero or negative");
71+
}
72+
73+
}
74+
}

0 commit comments

Comments
 (0)