Skip to content

Commit eeec12e

Browse files
committed
Update CI for .NET 10, add tests and project reference
- Update build-and-release.yml: use actions/checkout@v4, switch to .NET 10, fix asset paths, and replace deprecated set-output usage - Add ProjectReference to Reina.Cryptography in test project - Add LibraryTests.cs with xUnit tests for input validation and placeholders for future tests requiring mocks
1 parent db84f8c commit eeec12e

3 files changed

Lines changed: 82 additions & 12 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jobs:
1919
steps:
2020
# Checks-out the repository
2121
- name: Check out code
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323

2424
# Get the last commit message
2525
- name: Get the last commit message
2626
id: commit_message
2727
run: |
2828
$commitMessage = git log -1 --pretty=%B
29-
echo "::set-output name=message::$commitMessage"
29+
echo "message=$commitMessage" >> $env:GITHUB_OUTPUT
3030
3131
# Calculate version number
3232
- name: Calculate version
@@ -63,7 +63,7 @@ jobs:
6363
}
6464
$newVersion = "$major.$minor.$build"
6565
echo "New version: $newVersion"
66-
echo "::set-output name=version::$newVersion"
66+
echo "version=$newVersion" >> $env:GITHUB_OUTPUT
6767
6868
# Update .csproj file
6969
- name: Update project version
@@ -86,11 +86,11 @@ jobs:
8686
git commit -m "Update version to ${{ steps.version.outputs.version }}"
8787
git push
8888
89-
# Install dependencies and build for both target frameworks
90-
- name: Build Project for .NET Framework 4.8.1 and .NET 7
89+
# Install dependencies and build for .NET Framework 4.8.1 and .NET 10
90+
- name: Build Project for .NET Framework 4.8.1 and .NET 10
9191
run: |
92-
dotnet restore Reina.Cryptography.csproj
93-
dotnet build Reina.Cryptography.csproj --configuration Release
92+
dotnet restore Reina.Cryptography/Reina.Cryptography.csproj
93+
dotnet build Reina.Cryptography/Reina.Cryptography.csproj --configuration Release
9494
9595
# List build output for debugging purposes
9696
- name: List build output
@@ -115,17 +115,29 @@ jobs:
115115
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116116
with:
117117
upload_url: ${{ steps.create_release.outputs.upload_url }}
118-
asset_path: ./bin/Release/net481/Reina.Cryptography.net481.dll
118+
asset_path: ./Reina.Cryptography/bin/Release/net481/Reina.Cryptography.dll
119119
asset_name: Reina.Cryptography.net481.dll
120120
asset_content_type: application/octet-stream
121121

122-
# Upload .dll for .NET 7 as an asset to the release
123-
- name: Upload .NET 7 DLL
122+
123+
# Upload .dll for .NET 10 as an asset to the release
124+
- name: Upload .NET 10 DLL
125+
uses: actions/upload-release-asset@v1
126+
env:
127+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128+
with:
129+
upload_url: ${{ steps.create_release.outputs.upload_url }}
130+
asset_path: ./Reina.Cryptography/bin/Release/net10.0/Reina.Cryptography.dll
131+
asset_name: Reina.Cryptography.net10.0.dll
132+
asset_content_type: application/octet-stream
133+
134+
# Upload .dll for .NET 10 as an asset to the release
135+
- name: Upload .NET 10 DLL
124136
uses: actions/upload-release-asset@v1
125137
env:
126138
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127139
with:
128140
upload_url: ${{ steps.create_release.outputs.upload_url }}
129-
asset_path: ./bin/Release/net7.0/Reina.Cryptography.net7.0.dll
130-
asset_name: Reina.Cryptography.net7.0.dll
141+
asset_path: ./Reina.Cryptography/bin/Release/net10.0/Reina.Cryptography.dll
142+
asset_name: Reina.Cryptography.net10.0.dll
131143
asset_content_type: application/octet-stream
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Xunit;
4+
5+
namespace Reina.Cryptography.Tests;
6+
7+
public class LibraryTests
8+
{
9+
[Fact]
10+
public void Initialize_SetsInitializedFlag_DoesNotThrow()
11+
{
12+
// Should not throw if configuration is valid (assumes Config.Instance.ValidateConfiguration is safe)
13+
Library.Initialize();
14+
// No assert: just ensure no exception
15+
}
16+
17+
18+
19+
public static TheoryData<string?, string?, string?, string?> InvalidInputData => new()
20+
{
21+
{ null, "key1", "key2", "key3" },
22+
{ "", "key1", "key2", "key3" },
23+
{ "data", null, "key2", "key3" },
24+
{ "data", "", "key2", "key3" }
25+
};
26+
27+
[Theory]
28+
[MemberData(nameof(InvalidInputData))]
29+
public async Task EncryptAsync_InvalidInput_ThrowsArgumentNullException(string? data, string? k1, string? k2, string? k3)
30+
{
31+
await Assert.ThrowsAsync<ArgumentNullException>(() => Library.EncryptAsync(data!, k1!, k2!, k3!, TestContext.Current.CancellationToken));
32+
}
33+
34+
[Theory]
35+
[InlineData("data", "1invalid", "key2", "key3")]
36+
[InlineData("data", "key1", "-bad", "key3")]
37+
public async Task EncryptAsync_InvalidKeyFormat_ThrowsArgumentException(string data, string k1, string k2, string k3)
38+
{
39+
await Assert.ThrowsAsync<ArgumentException>(() => Library.EncryptAsync(data, k1, k2, k3, TestContext.Current.CancellationToken));
40+
}
41+
42+
[Fact(Skip = "Requires mocking KeyFactory and DataEncryptor")]
43+
public async Task EncryptAsync_ValidInput_ReturnsBase64()
44+
{
45+
// TODO: Mock KeyFactory.InstanceAsync and DataEncryptor to test happy path
46+
// var result = await Library.EncryptAsync("data", "key1", "key2", "key3");
47+
// Assert.NotNull(result);
48+
}
49+
50+
[Fact(Skip = "Requires mocking KeyFactory and DataDecryptor")]
51+
public async Task DecryptAsync_ValidInput_ReturnsPlainText()
52+
{
53+
// TODO: Mock KeyFactory.InstanceAsync and DataDecryptor to test happy path
54+
// var result = await Library.DecryptAsync("base64", "key1", "key2", "key3");
55+
// Assert.Equal("data", result);
56+
}
57+
}

Reina.Cryptography.Tests/Reina.Cryptography.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
</PackageReference>
2222
<PackageReference Include="xunit.v3" Version="3.2.2" />
23+
<ProjectReference Include="..\Reina.Cryptography\Reina.Cryptography.csproj" />
2324
</ItemGroup>
2425

2526
<ItemGroup>

0 commit comments

Comments
 (0)