Skip to content

Commit

Permalink
added project refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ndigirigijohn committed Feb 17, 2025
1 parent 4a6e68d commit bc2e98f
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 218 deletions.
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

0 comments on commit bc2e98f

Please sign in to comment.