Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added project refs #29

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\blocktrust.Core\Blocktrust.Common\Blocktrust.Common.csproj" />
<ProjectReference Include="..\Blocktrust.CredentialWorkflow.Core\Blocktrust.CredentialWorkflow.Core.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDIDSecrets;
using Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.SavePeerDIDSecrets;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Xunit;

namespace Blocktrust.CredentialWorkflow.Core.Tests.DIDCommTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,63 @@
namespace Blocktrust.CredentialWorkflow.Core.Tests.DIDCommTests
using Blocktrust.Common.Models.DidDoc;
using Blocktrust.Common.Models.Secrets;
using Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.SavePeerDIDSecrets;
using FluentAssertions;

namespace Blocktrust.CredentialWorkflow.Core.Tests.DIDCommTests;

public class SavePeerDIDSecretsHandlerTests : TestSetup
{
using Blocktrust.Common.Models.DidDoc;
using Blocktrust.Common.Models.Secrets;
using Blocktrust.CredentialWorkflow.Core;
using Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.SavePeerDIDSecrets;
using Blocktrust.CredentialWorkflow.Core.Tests;
using FluentAssertions;
using Xunit;
private readonly DataContext _dataContext;
private readonly SavePeerDIDSecretsHandler _handler;

public class SavePeerDIDSecretsHandlerTests : TestSetup
public SavePeerDIDSecretsHandlerTests(TransactionalTestDatabaseFixture fixture) : base(fixture)
{
private readonly DataContext _dataContext;
private readonly SavePeerDIDSecretsHandler _handler;

public SavePeerDIDSecretsHandlerTests(TransactionalTestDatabaseFixture fixture) : base(fixture)
{
_dataContext = fixture.CreateContext();
_handler = new SavePeerDIDSecretsHandler(_dataContext);
}
_dataContext = fixture.CreateContext();
_handler = new SavePeerDIDSecretsHandler(_dataContext);
}

[Fact]
public async Task Handle_ValidRequest_ShouldSavePeerDIDSecret()
[Fact]
public async Task Handle_ValidRequest_ShouldSavePeerDIDSecret()
{
// Arrange
var secret = new Secret
{
// Arrange
var secret = new Secret
Type = VerificationMethodType.JsonWebKey2020,
VerificationMaterial = new VerificationMaterial
{
Type = VerificationMethodType.JsonWebKey2020,
VerificationMaterial = new VerificationMaterial
{
Format = VerificationMaterialFormat.Jwk,
Value = "{\"kty\":\"EC\",\"crv\":\"secp256k1\",\"x\":\"abc\",\"y\":\"123\"}" // Example JSON
}
};

var kid = "did:example:123#key-1";
var request = new SavePeerDIDSecretRequest(kid, secret);

// Act
var result = await _handler.Handle(request, CancellationToken.None);

// Assert
result.IsSuccess.Should().BeTrue("the request is valid, so saving should succeed");

// Verify that the secret was saved in the database
var savedSecret = _dataContext.PeerDIDSecrets.FirstOrDefault(x => x.Kid == kid);
savedSecret.Should().NotBeNull("we expect an entry to be created in PeerDIDSecretEntities table");
savedSecret!.Kid.Should().Be(kid);
savedSecret.Value.Should().Be(secret.VerificationMaterial.Value);
savedSecret.VerificationMaterialFormat.Should().Be((int)secret.VerificationMaterial.Format);
savedSecret.VerificationMethodType.Should().Be((int)secret.Type);
}
Format = VerificationMaterialFormat.Jwk,
Value = "{\"kty\":\"EC\",\"crv\":\"secp256k1\",\"x\":\"abc\",\"y\":\"123\"}" // Example JSON
}
};

var kid = "did:example:123#key-1";
var request = new SavePeerDIDSecretRequest(kid, secret);

// Act
var result = await _handler.Handle(request, CancellationToken.None);

// Assert
result.IsSuccess.Should().BeTrue("the request is valid, so saving should succeed");

// Verify that the secret was saved in the database
var savedSecret = _dataContext.PeerDIDSecrets.FirstOrDefault(x => x.Kid == kid);
savedSecret.Should().NotBeNull("we expect an entry to be created in PeerDIDSecretEntities table");
savedSecret!.Kid.Should().Be(kid);
savedSecret.Value.Should().Be(secret.VerificationMaterial.Value);
savedSecret.VerificationMaterialFormat.Should().Be((int)secret.VerificationMaterial.Format);
savedSecret.VerificationMethodType.Should().Be((int)secret.Type);
}

[Fact]
public async Task Handle_NullSecret_ShouldThrowOrFail()
{
// Arrange
var request = new SavePeerDIDSecretRequest("someKid", null!);
[Fact]
public async Task Handle_NullSecret_ShouldThrowOrFail()
{
// Arrange
var request = new SavePeerDIDSecretRequest("someKid", null!);

// Act
Func<Task> act = async () => await _handler.Handle(request, CancellationToken.None);
// Act
Func<Task> act = async () => await _handler.Handle(request, CancellationToken.None);

// Assert
await act.Should().ThrowAsync<NullReferenceException>("the Secret is null and code does not guard against it");
}
// Assert
await act.Should().ThrowAsync<NullReferenceException>("the Secret is null and code does not guard against it");
}
}
}
Loading