Skip to content

Commit a03e28f

Browse files
authored
Update testing to only test .NET Standard and LTS versions (#614)
* Update build configuration and tests to support .NET Framework 4.6.2 and .NET Core 2.1/3.1; refactor logo handling in tests * update
1 parent 446aa0c commit a03e28f

File tree

9 files changed

+98
-84
lines changed

9 files changed

+98
-84
lines changed

.github/workflows/wf-build-test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ jobs:
3636
strategy:
3737
matrix:
3838
dotnet-framework:
39-
- { name: ".NET 3.5", framework: "net35", coverage: false, no-build: true, sdk: "8.0.x" }
40-
- { name: ".NET 4.52", framework: "net452", coverage: false, no-build: true, sdk: "8.0.x" }
41-
- { name: ".NET Core 1.1", framework: "netcoreapp1.1", coverage: false, no-build: false, sdk: "1.0.x" }
42-
- { name: ".NET Core 2.0", framework: "netcoreapp2.0", coverage: true, no-build: false, sdk: "2.0.x" }
39+
- { name: ".NET Framework 4.6.2", framework: "net462", coverage: false, no-build: true, sdk: "8.0.x" }
40+
- { name: ".NET Core 2.1", framework: "netcoreapp2.1", coverage: true, no-build: false, sdk: "2.1.x" }
41+
- { name: ".NET Core 3.1", framework: "netcoreapp3.1", coverage: true, no-build: true, sdk: "3.1.x" }
4342
- { name: ".NET 5.0", framework: "net5.0", coverage: true, no-build: true, sdk: "5.0.x" }
4443
- { name: ".NET 5.0 Windows", framework: "net5.0-windows", coverage: true, no-build: true, sdk: "5.0.x" }
4544
- { name: ".NET 6.0", framework: "net6.0", coverage: true, no-build: true, sdk: "6.0.x" }

QRCoder.sln

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ EndProject
2424
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A402660A-59F5-43E2-B5B0-69CE5E56DEA1}"
2525
ProjectSection(SolutionItems) = preProject
2626
.editorconfig = .editorconfig
27-
.gitignore = .gitignore
2827
Directory.Build.props = Directory.Build.props
2928
global.json = global.json
30-
LICENSE.txt = LICENSE.txt
31-
readme.md = readme.md
3229
EndProjectSection
3330
EndProject
3431
Global

QRCoderTests/ArtQRCodeRendererTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void can_create_standard_qrcode_graphic_with_background()
5353
{
5454
var gen = new QRCodeGenerator();
5555
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
56-
var bmp = new ArtQRCode(data).GetGraphic((Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png"));
56+
var bmp = new ArtQRCode(data).GetGraphic(HelperFunctions.GetIconBitmap());
5757
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
5858

5959
var result = HelperFunctions.BitmapToHash(bmp);

QRCoderTests/Base64QRCodeRendererTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if !NETCOREAPP1_1
21
using System;
32
using System.Drawing;
43
using System.IO;
@@ -66,5 +65,3 @@ public void can_render_base64_qrcode_jpeg()
6665
}
6766
#endif
6867
}
69-
70-
#endif

QRCoderTests/Helpers/HelperFunctions.cs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using System.IO;
44
using System.Security.Cryptography;
55
using System.Reflection;
6-
#if !NETCOREAPP1_1
76
using System.Drawing;
8-
#endif
97
#if TEST_XAML
108
using SW = System.Windows;
119
using System.Windows.Media;
@@ -46,16 +44,10 @@ public static Bitmap BitmapSourceToBitmap(DrawingImage xamlImg)
4644
public static string GetAssemblyPath()
4745
#if NET5_0_OR_GREATER
4846
=> AppDomain.CurrentDomain.BaseDirectory;
49-
#elif NETFRAMEWORK
50-
=> Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "");
51-
#elif NETCOREAPP1_1
52-
=> Path.GetDirectoryName(typeof(HelperFunctions).GetTypeInfo().Assembly.Location).Replace("file:\\", "");
5347
#else
5448
=> Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Replace("file:\\", "");
5549
#endif
5650

57-
58-
#if !NETCOREAPP1_1
5951
/// <summary>
6052
/// Converts a bitmap to a hash string based on the pixel data
6153
/// using a deterministic algorithm that ignores compression algorithm
@@ -86,19 +78,66 @@ public static string BitmapToHash(Bitmap bitmap)
8678
// Hash the resulting byte array
8779
return ByteArrayToHash(rgbValues);
8880
}
89-
#endif
9081

9182
public static string ByteArrayToHash(byte[] data)
9283
{
93-
#if !NETCOREAPP1_1
9484
var md5 = MD5.Create();
9585
var hash = md5.ComputeHash(data);
96-
#else
97-
var hash = new SshNet.Security.Cryptography.MD5().ComputeHash(data);
98-
#endif
9986
return BitConverter.ToString(hash).Replace("-", "").ToLower();
10087
}
10188

10289
public static string StringToHash(string data)
10390
=> ByteArrayToHash(Encoding.UTF8.GetBytes(data));
91+
92+
/// <summary>
93+
/// Gets the embedded PNG icon as a Bitmap.
94+
/// </summary>
95+
public static Bitmap GetIconBitmap()
96+
{
97+
var assembly = Assembly.GetExecutingAssembly();
98+
var resourceName = "QRCoderTests.assets.noun_software engineer_2909346.png";
99+
using (var stream = assembly.GetManifestResourceStream(resourceName))
100+
{
101+
if (stream == null)
102+
throw new InvalidOperationException($"Embedded resource '{resourceName}' not found.");
103+
return new Bitmap(stream);
104+
}
105+
}
106+
107+
/// <summary>
108+
/// Gets the embedded PNG icon as a byte array.
109+
/// </summary>
110+
public static byte[] GetIconBytes()
111+
{
112+
var assembly = Assembly.GetExecutingAssembly();
113+
var resourceName = "QRCoderTests.assets.noun_software engineer_2909346.png";
114+
using (var stream = assembly.GetManifestResourceStream(resourceName))
115+
{
116+
if (stream == null)
117+
throw new InvalidOperationException($"Embedded resource '{resourceName}' not found.");
118+
using (var memoryStream = new MemoryStream())
119+
{
120+
stream.CopyTo(memoryStream);
121+
return memoryStream.ToArray();
122+
}
123+
}
124+
}
125+
126+
/// <summary>
127+
/// Gets the embedded SVG icon as a string.
128+
/// </summary>
129+
public static string GetIconSvg()
130+
{
131+
var assembly = Assembly.GetExecutingAssembly();
132+
var resourceName = "QRCoderTests.assets.noun_Scientist_2909361.svg";
133+
using (var stream = assembly.GetManifestResourceStream(resourceName))
134+
{
135+
if (stream == null)
136+
throw new InvalidOperationException($"Embedded resource '{resourceName}' not found.");
137+
using (var reader = new StreamReader(stream))
138+
{
139+
return reader.ReadToEnd();
140+
}
141+
}
142+
}
104143
}

QRCoderTests/PayloadGeneratorTests/BitcoinAddressTests.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,8 @@ public void bitcoin_address_generator_should_round_to_satoshi()
6969
[Fact]
7070
public void bitcoin_address_generator_disregards_current_culture()
7171
{
72-
#if NETCOREAPP1_1
73-
var currentCulture = CultureInfo.DefaultThreadCurrentCulture;
74-
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE");
75-
#else
7672
var currentCulture = Thread.CurrentThread.CurrentCulture;
7773
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
78-
#endif
7974

8075
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W";
8176
var amount = .123;
@@ -87,10 +82,6 @@ public void bitcoin_address_generator_disregards_current_culture()
8782
.ToString()
8883
.ShouldBe("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=.123");
8984

90-
#if NETCOREAPP1_1
91-
CultureInfo.DefaultThreadCurrentCulture = currentCulture;
92-
#else
9385
Thread.CurrentThread.CurrentCulture = currentCulture;
94-
#endif
9586
}
9687
}

QRCoderTests/QRCodeRendererTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void can_create_qrcode_with_transparent_logo_graphic()
5353
var gen = new QRCodeGenerator();
5454
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
5555

56-
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: (Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png"));
56+
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: HelperFunctions.GetIconBitmap());
5757
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
5858
var result = HelperFunctions.BitmapToHash(bmp);
5959
result.ShouldBe("c99a82b43ce48ddae18a75862c476a9e");
@@ -65,7 +65,7 @@ public void can_create_qrcode_with_non_transparent_logo_graphic()
6565
//Create QR code
6666
var gen = new QRCodeGenerator();
6767
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
68-
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.White, icon: (Bitmap)Bitmap.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png"));
68+
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.White, icon: HelperFunctions.GetIconBitmap());
6969
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
7070

7171
var result = HelperFunctions.BitmapToHash(bmp);
@@ -79,7 +79,7 @@ public void can_create_qrcode_with_logo_and_with_transparent_border()
7979
var gen = new QRCodeGenerator();
8080
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
8181

82-
var logo = (Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png");
82+
var logo = HelperFunctions.GetIconBitmap();
8383
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: logo, iconBorderWidth: 6);
8484
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
8585
var result = HelperFunctions.BitmapToHash(bmp);
@@ -93,7 +93,7 @@ public void can_create_qrcode_with_logo_and_with_standard_border()
9393
var gen = new QRCodeGenerator();
9494
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
9595

96-
var logo = (Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png");
96+
var logo = HelperFunctions.GetIconBitmap();
9797
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.White, icon: logo, iconBorderWidth: 6);
9898
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
9999
var result = HelperFunctions.BitmapToHash(bmp);
@@ -107,7 +107,7 @@ public void can_create_qrcode_with_logo_and_with_custom_border()
107107
var gen = new QRCodeGenerator();
108108
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
109109

110-
var logo = (Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png");
110+
var logo = HelperFunctions.GetIconBitmap();
111111
var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: logo, iconBorderWidth: 6, iconBackgroundColor: Color.DarkGreen);
112112
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
113113
var result = HelperFunctions.BitmapToHash(bmp);

QRCoderTests/QRCoderTests.csproj

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,55 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net35;net452;netcoreapp1.1;netcoreapp2.0;net5.0;net5.0-windows;net6.0;net6.0-windows</TargetFrameworks>
3+
<TargetFrameworks>net462;netcoreapp2.1;netcoreapp3.1;net5.0;net5.0-windows;net6.0;net6.0-windows</TargetFrameworks>
44
<UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWindowsForms>
55
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWPF>
6-
<DefineConstants Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'netcoreapp1.1'">$(DefineConstants);SYSTEM_DRAWING</DefineConstants>
7-
<DefineConstants Condition="'$(TargetFramework)' == 'net35' or '$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);TEST_XAML</DefineConstants>
6+
<DefineConstants Condition="'$(TargetFramework)' != 'net6.0'">$(DefineConstants);SYSTEM_DRAWING</DefineConstants>
7+
<DefineConstants Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);TEST_XAML</DefineConstants>
88
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
99
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
1010
<IsPackable>false</IsPackable>
1111
<IsTestProject>true</IsTestProject>
1212
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
13-
<NoWarn>$(NoWarn);NU1903</NoWarn>
13+
<NoWarn>$(NoWarn);CA1416</NoWarn>
14+
<SuppressTfmSupportBuildErrors>true</SuppressTfmSupportBuildErrors>
15+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
16+
</PropertyGroup>
17+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
18+
<RuntimeFrameworkVersion>2.1.30</RuntimeFrameworkVersion>
1419
</PropertyGroup>
15-
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net6.0-windows' ">
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
17-
<PackageReference Include="xunit" Version="2.4.1" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
19-
<PackageReference Include="shouldly" Version="4.0.3" />
20-
</ItemGroup>
21-
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' or '$(TargetFramework)' == 'net452' ">
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
23-
<PackageReference Include="xunit" Version="1.9.2" />
24-
<PackageReference Include="xunit.runner.visualstudio" Version="2.0.1" />
25-
<PackageReference Include="shouldly" Version="2.8.3" />
26-
</ItemGroup>
27-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' or '$(TargetFramework)' == 'netcoreapp2.0'">
28-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
29-
<PackageReference Include="xunit" Version="2.4.1" />
30-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
31-
<PackageReference Include="shouldly" Version="3.0.2" />
32-
</ItemGroup>
33-
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
34-
<Reference Include="PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
35-
<Reference Include="WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
36-
</ItemGroup>
37-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
38-
<Reference Include="PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
39-
<Reference Include="WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
40-
</ItemGroup>
4120
<ItemGroup>
42-
<PackageReference Include="coverlet.collector" Version="3.0.3">
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.3" />
22+
<PackageReference Include="xunit" Version="2.9.2" />
23+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
24+
<PackageReference Include="shouldly" Version="4.3.0" />
25+
<PackageReference Include="System.Drawing.Common" Version="6.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
26+
<PackageReference Include="System.Management" Version="6.0.1">
27+
<ExcludeAssets>buildTransitive</ExcludeAssets>
28+
</PackageReference>
29+
<PackageReference Include="System.CodeDom" Version="6.0.0">
30+
<ExcludeAssets>buildTransitive</ExcludeAssets>
31+
</PackageReference>
32+
<PackageReference Include="coverlet.collector" Version="6.0.4">
4333
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4434
<PrivateAssets>all</PrivateAssets>
4535
</PackageReference>
46-
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
36+
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
4737
<PrivateAssets>all</PrivateAssets>
4838
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4939
</PackageReference>
50-
<PackageReference Include="SshNet.Security.Cryptography" Version="1.3.0" />
40+
</ItemGroup>
41+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
42+
<Reference Include="PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
43+
<Reference Include="WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
44+
</ItemGroup>
45+
<ItemGroup>
5146
<ProjectReference Include="..\QRCoder\QRCoder.csproj" />
5247
</ItemGroup>
53-
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' or '$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows' ">
48+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows' ">
5449
<ProjectReference Include="..\QRCoder.Xaml\QRCoder.Xaml.csproj" />
5550
</ItemGroup>
5651
<ItemGroup>
57-
<None Update="assets\noun_Scientist_2909361.svg">
58-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
59-
</None>
60-
<None Update="assets\noun_software engineer_2909346.png">
61-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
62-
</None>
52+
<EmbeddedResource Include="assets\noun_Scientist_2909361.svg" />
53+
<EmbeddedResource Include="assets\noun_software engineer_2909346.png" />
6354
</ItemGroup>
6455
</Project>

0 commit comments

Comments
 (0)