From d4655aa2cc2309ca9f17249f5211316fb0f7d6cb Mon Sep 17 00:00:00 2001 From: Timo Notheisen Date: Tue, 23 Jan 2024 10:48:48 +0100 Subject: [PATCH] refactor: several small refactorings --- .../UnitTestTools/Data/TestDataGenerator.cs | 2 +- .../DeleteIdentity/DeleteIdentityCommand.cs | 1 - .../Identities/IdentityDeleter.cs | 4 +- .../Repository/IPnsRegistrationsRepository.cs | 2 +- .../IdentityStatusChangedIntegrationEvent.cs | 4 +- ...eletePnsRegistrationsOfIdentityCommand.cs} | 6 +- .../Handler.cs | 8 +- .../Validator.cs | 4 +- .../Entities/Identities/Identity.cs | 4 +- .../Repository/PnsRegistrationsRepository.cs | 2 +- .../AssemblyInfo.cs | 3 - .../Devices.Jobs.IdentityDeletion/Program.cs | 25 +-- .../appsettings.override.json | 5 - .../UpdateDeletionProcesses/HandlerTests.cs | 1 + .../Identities/DeletionProcessTests.cs | 19 +- .../StartDeletionProcessAsOwnerTests.cs | 26 +-- .../StartDeletionProcessAsSupportTests.cs | 18 +- .../Tests/WorkerTests.cs | 28 +-- .../AnonymizeMessagesOfIdentity/Handler.cs | 6 +- .../Messages.Domain.Tests.csproj | 3 +- .../Messages/ReplaceIdentityAddressTests.cs | 49 ++--- .../Repository/IIdentitiesRepository.cs | 1 - .../Repository/IdentitiesRepository.cs | 6 - .../HandlerTests.cs | 2 +- .../GetIdentity/HandlerTests.cs | 2 +- .../IRelationshipTemplatesRepository.cs | 1 - .../Repository/IRelationshipsRepository.cs | 1 - .../FindRelationshipsOfIdentity/Handler.cs | 11 +- .../RelationshipTemplatesRepository.cs | 5 - .../Repository/RelationshipsRepository.cs | 5 - ...ionshipTemplateQueryableExtensionsTests.cs | 21 +- .../TestDataGenerator.cs | 15 +- .../Tests/Identities/IdentityDeleterTests.cs | 3 +- .../Tests/RelationshipTests.cs | 196 ++++++++++++++---- .../src/Tokens.Domain/Entities/Token.cs | 2 +- .../DeleteTokenOfIdentity/HandlerTests.cs | 3 +- 36 files changed, 279 insertions(+), 215 deletions(-) rename Modules/Devices/src/Devices.Application/PushNotifications/Commands/{DeleteRegistrationsOfIdentity/DeleteRegistrationsOfIdentityCommand.cs => DeletePnsRegistrationsOfIdentity/DeletePnsRegistrationsOfIdentityCommand.cs} (56%) rename Modules/Devices/src/Devices.Application/PushNotifications/Commands/{DeleteRegistrationsOfIdentity => DeletePnsRegistrationsOfIdentity}/Handler.cs (56%) rename Modules/Devices/src/Devices.Application/PushNotifications/Commands/{DeleteRegistrationsOfIdentity => DeletePnsRegistrationsOfIdentity}/Validator.cs (65%) delete mode 100644 Modules/Devices/src/Devices.Jobs.IdentityDeletion/AssemblyInfo.cs rename Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/{Commands => Queries}/GetIdentity/HandlerTests.cs (99%) diff --git a/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs b/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs index 338abb145d..7ddc0f0082 100644 --- a/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs +++ b/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs @@ -2,7 +2,7 @@ namespace Backbone.UnitTestTools.Data; -public static class TestDataGenerator +public class TestDataGenerator { public static string GenerateString(int resultLength, char[]? chars = null) { diff --git a/Modules/Devices/src/Devices.Application/Identities/Commands/DeleteIdentity/DeleteIdentityCommand.cs b/Modules/Devices/src/Devices.Application/Identities/Commands/DeleteIdentity/DeleteIdentityCommand.cs index c7a9709c5e..7ace504c22 100644 --- a/Modules/Devices/src/Devices.Application/Identities/Commands/DeleteIdentity/DeleteIdentityCommand.cs +++ b/Modules/Devices/src/Devices.Application/Identities/Commands/DeleteIdentity/DeleteIdentityCommand.cs @@ -4,7 +4,6 @@ namespace Backbone.Modules.Devices.Application.Identities.Commands.DeleteIdentity; public class DeleteIdentityCommand : IRequest { - public DeleteIdentityCommand(IdentityAddress identityAddress) { IdentityAddress = identityAddress; diff --git a/Modules/Devices/src/Devices.Application/Identities/IdentityDeleter.cs b/Modules/Devices/src/Devices.Application/Identities/IdentityDeleter.cs index 43a6195a27..4223d17381 100644 --- a/Modules/Devices/src/Devices.Application/Identities/IdentityDeleter.cs +++ b/Modules/Devices/src/Devices.Application/Identities/IdentityDeleter.cs @@ -1,7 +1,7 @@ using Backbone.BuildingBlocks.Application.Identities; using Backbone.DevelopmentKit.Identity.ValueObjects; using Backbone.Modules.Devices.Application.Identities.Commands.DeleteIdentity; -using Backbone.Modules.Devices.Application.PushNotifications.Commands.DeleteRegistrationsOfIdentity; +using Backbone.Modules.Devices.Application.PushNotifications.Commands.DeletePnsRegistrationsOfIdentity; using MediatR; namespace Backbone.Modules.Devices.Application.Identities; @@ -16,7 +16,7 @@ public IdentityDeleter(IMediator mediator) public async Task Delete(IdentityAddress identityAddress) { - await _mediator.Send(new DeleteRegistrationsOfIdentityCommand(identityAddress)); + await _mediator.Send(new DeletePnsRegistrationsOfIdentityCommand(identityAddress)); await _mediator.Send(new DeleteIdentityCommand(identityAddress)); } } diff --git a/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IPnsRegistrationsRepository.cs b/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IPnsRegistrationsRepository.cs index b2c6be6e46..2c5d1bb7b0 100644 --- a/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IPnsRegistrationsRepository.cs +++ b/Modules/Devices/src/Devices.Application/Infrastructure/Persistence/Repository/IPnsRegistrationsRepository.cs @@ -11,5 +11,5 @@ public interface IPnsRegistrationsRepository Task> FindWithAddress(IdentityAddress address, CancellationToken cancellationToken, bool track = false); Task FindByDeviceId(DeviceId deviceId, CancellationToken cancellationToken, bool track = false); Task Delete(List deviceIds, CancellationToken cancellationToken); - Task DeletePnsRegistrations(Expression> filter, CancellationToken cancellationToken); + Task Delete(Expression> filter, CancellationToken cancellationToken); } diff --git a/Modules/Devices/src/Devices.Application/IntegrationEvents/Outgoing/IdentityStatusChangedIntegrationEvent.cs b/Modules/Devices/src/Devices.Application/IntegrationEvents/Outgoing/IdentityStatusChangedIntegrationEvent.cs index 54abd8da53..0742766b7b 100644 --- a/Modules/Devices/src/Devices.Application/IntegrationEvents/Outgoing/IdentityStatusChangedIntegrationEvent.cs +++ b/Modules/Devices/src/Devices.Application/IntegrationEvents/Outgoing/IdentityStatusChangedIntegrationEvent.cs @@ -8,9 +8,9 @@ public class IdentityStatusChangedIntegrationEvent : IntegrationEvent public IdentityStatusChangedIntegrationEvent(IdentityAddress identityAddress, IdentityStatus newStatus) : base($"{identityAddress.StringValue}/StatusChanged") { IdentityAddress = identityAddress; - Status = newStatus; + NewStatus = newStatus; } public IdentityAddress IdentityAddress { get; set; } - public IdentityStatus Status { get; set; } + public IdentityStatus NewStatus { get; set; } } diff --git a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/DeleteRegistrationsOfIdentityCommand.cs b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/DeletePnsRegistrationsOfIdentityCommand.cs similarity index 56% rename from Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/DeleteRegistrationsOfIdentityCommand.cs rename to Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/DeletePnsRegistrationsOfIdentityCommand.cs index 7d48032cf9..33bf6b9a43 100644 --- a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/DeleteRegistrationsOfIdentityCommand.cs +++ b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/DeletePnsRegistrationsOfIdentityCommand.cs @@ -1,10 +1,10 @@ using Backbone.DevelopmentKit.Identity.ValueObjects; using MediatR; -namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeleteRegistrationsOfIdentity; -public class DeleteRegistrationsOfIdentityCommand : IRequest +namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeletePnsRegistrationsOfIdentity; +public class DeletePnsRegistrationsOfIdentityCommand : IRequest { - public DeleteRegistrationsOfIdentityCommand(IdentityAddress identityAddress) + public DeletePnsRegistrationsOfIdentityCommand(IdentityAddress identityAddress) { IdentityAddress = identityAddress; } diff --git a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Handler.cs b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Handler.cs similarity index 56% rename from Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Handler.cs rename to Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Handler.cs index 168180fdd8..cbef231839 100644 --- a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Handler.cs +++ b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Handler.cs @@ -2,8 +2,8 @@ using Backbone.Modules.Devices.Domain.Aggregates.PushNotifications; using MediatR; -namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeleteRegistrationsOfIdentity; -public class Handler : IRequestHandler +namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeletePnsRegistrationsOfIdentity; +public class Handler : IRequestHandler { private readonly IPnsRegistrationsRepository _pnsRegistrationRepository; @@ -12,8 +12,8 @@ public Handler(IPnsRegistrationsRepository pnsRegistrationRepository) _pnsRegistrationRepository = pnsRegistrationRepository; } - public async Task Handle(DeleteRegistrationsOfIdentityCommand request, CancellationToken cancellationToken) + public async Task Handle(DeletePnsRegistrationsOfIdentityCommand request, CancellationToken cancellationToken) { - await _pnsRegistrationRepository.DeletePnsRegistrations(PnsRegistration.HasAddress(request.IdentityAddress), cancellationToken); + await _pnsRegistrationRepository.Delete(PnsRegistration.HasAddress(request.IdentityAddress), cancellationToken); } } diff --git a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Validator.cs b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Validator.cs similarity index 65% rename from Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Validator.cs rename to Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Validator.cs index 08ed992905..21cdec7d1d 100644 --- a/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeleteRegistrationsOfIdentity/Validator.cs +++ b/Modules/Devices/src/Devices.Application/PushNotifications/Commands/DeletePnsRegistrationsOfIdentity/Validator.cs @@ -1,8 +1,8 @@ using Backbone.DevelopmentKit.Identity.ValueObjects; using FluentValidation; -namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeleteRegistrationsOfIdentity; -public class Validator : AbstractValidator +namespace Backbone.Modules.Devices.Application.PushNotifications.Commands.DeletePnsRegistrationsOfIdentity; +public class Validator : AbstractValidator { public Validator() => RuleFor(x => x.IdentityAddress).Must(x => IdentityAddress.IsValid(x)); } diff --git a/Modules/Devices/src/Devices.Domain/Entities/Identities/Identity.cs b/Modules/Devices/src/Devices.Domain/Entities/Identities/Identity.cs index 11812dac04..ae6236f1e5 100644 --- a/Modules/Devices/src/Devices.Domain/Entities/Identities/Identity.cs +++ b/Modules/Devices/src/Devices.Domain/Entities/Identities/Identity.cs @@ -22,11 +22,11 @@ public Identity(string? clientId, IdentityAddress address, byte[] publicKey, Tie _deletionProcesses = new List(); } - public IdentityStatus Status { get; internal set; } + public IdentityStatus Status { get; private set; } public string? ClientId { get; private set; } - public IdentityAddress Address { get; private set; } + public IdentityAddress Address { get; } public byte[] PublicKey { get; private set; } public DateTime CreatedAt { get; private set; } diff --git a/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/PnsRegistrationsRepository.cs b/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/PnsRegistrationsRepository.cs index 530e16f3bb..f7b07e6b43 100644 --- a/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/PnsRegistrationsRepository.cs +++ b/Modules/Devices/src/Devices.Infrastructure/Persistence/Repository/PnsRegistrationsRepository.cs @@ -59,7 +59,7 @@ public async Task Update(PnsRegistration registration, CancellationToken cancell await _dbContext.SaveChangesAsync(cancellationToken); } - public async Task DeletePnsRegistrations(Expression> filter, CancellationToken cancellationToken) + public async Task Delete(Expression> filter, CancellationToken cancellationToken) { await _registrations.Where(filter).ExecuteDeleteAsync(cancellationToken); } diff --git a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/AssemblyInfo.cs b/Modules/Devices/src/Devices.Jobs.IdentityDeletion/AssemblyInfo.cs deleted file mode 100644 index 334c7ced2a..0000000000 --- a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Backbone.Devices.Jobs.IdentityDeletion.Tests")] diff --git a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/Program.cs b/Modules/Devices/src/Devices.Jobs.IdentityDeletion/Program.cs index 57a8a8220e..b45e196c96 100644 --- a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/Program.cs +++ b/Modules/Devices/src/Devices.Jobs.IdentityDeletion/Program.cs @@ -53,20 +53,18 @@ private static IHostBuilder CreateHostBuilder(string[] args) var configuration = hostContext.Configuration; services.AddHostedService(); - services.AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration) - .AddModule(configuration); + services + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration) + .AddModule(configuration); services.AddTransient(); - services.AddFluentValidationAutoValidation(config => - { - config.DisableDataAnnotationsValidation = true; - }); + services.AddFluentValidationAutoValidation(config => { config.DisableDataAnnotationsValidation = true; }); services.AddCustomIdentity(hostContext.HostingEnvironment); @@ -84,12 +82,9 @@ private static IHostBuilder CreateHostBuilder(string[] args) var devicesConfiguration = new DevicesConfiguration(); configuration.GetSection("Modules:Devices").Bind(devicesConfiguration); services.AddPushNotifications(devicesConfiguration.Infrastructure.PushNotifications); - }) .UseServiceProviderFactory(new AutofacServiceProviderFactory()); - } - } public static class ServicesExtensions diff --git a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/appsettings.override.json b/Modules/Devices/src/Devices.Jobs.IdentityDeletion/appsettings.override.json index 18d0f76ca2..14c62c57b7 100644 --- a/Modules/Devices/src/Devices.Jobs.IdentityDeletion/appsettings.override.json +++ b/Modules/Devices/src/Devices.Jobs.IdentityDeletion/appsettings.override.json @@ -75,11 +75,6 @@ "Provider": "Postgres", "ConnectionString": "User ID=synchronization;Password=Passw0rd;Server=localhost;Port=5432;Database=enmeshed;" // postgres // "ConnectionString": "Server=localhost;Database=enmeshed;User Id=synchronization;Password=Passw0rd;TrustServerCertificate=True" // sqlserver - }, - "BlobStorage": { - "CloudProvider": "Azure", - "ConnectionInfo": "", - "ContainerName": "" } } }, diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs index 009f88e942..71666e0438 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs @@ -47,6 +47,7 @@ public async Task Response_contains_expected_identities() var result = await handler.Handle(command, CancellationToken.None); // Assert + result.IdentityAddresses.Should().HaveCount(1); result.IdentityAddresses.Single().Should().Be(anIdentity.Address); } diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessTests.cs index 2a09a6a42a..6bdb4957ec 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessTests.cs @@ -7,7 +7,7 @@ namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class DeletionProcessTests : IDisposable +public class DeletionProcessTests { [Fact] public void DeletionStarted_sets_status_and_creates_valid_DeletionProcess() @@ -15,16 +15,16 @@ public void DeletionStarted_sets_status_and_creates_valid_DeletionProcess() // Arrange var currentDateTime = DateTime.Parse("2000-01-01 06:00:00"); SystemTime.Set(currentDateTime); - var activeIdentity = CreateIdentity(); - activeIdentity.StartDeletionProcessAsOwner(new Device(activeIdentity).Id); + var identity = CreateIdentity(); + identity.StartDeletionProcessAsOwner(new Device(identity).Id); // Act - activeIdentity.DeletionStarted(); + identity.DeletionStarted(); // Assert - activeIdentity.Status.Should().Be(IdentityStatus.Deleting); - activeIdentity.DeletionProcesses.Should().HaveCount(1); - activeIdentity.DeletionProcesses.First().DeletionStartedAt.Should().Be(currentDateTime); + identity.Status.Should().Be(IdentityStatus.Deleting); + identity.DeletionProcesses.Should().HaveCount(1); + identity.DeletionProcesses.First().DeletionStartedAt.Should().Be(currentDateTime); } @@ -33,9 +33,4 @@ private static Identity CreateIdentity() var address = IdentityAddress.Create(Array.Empty(), "id1"); return new Identity("", address, Array.Empty(), TierId.Generate(), 1); } - - public void Dispose() - { - Hasher.Reset(); - } } diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs index 0454b1560f..11836c719d 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs @@ -16,21 +16,21 @@ public void Start_deletion_process() { // Arrange SystemTime.Set(DateTime.Parse("2000-01-01")); - var activeIdentity = CreateIdentity(); - var activeDevice = DeviceId.Parse("DVC"); + var identity = CreateIdentity(); + var device = DeviceId.Parse("DVC"); Hasher.SetHasher(new DummyHasher(new byte[] { 1, 2, 3 })); // Act - var deletionProcess = activeIdentity.StartDeletionProcessAsOwner(activeDevice); + var deletionProcess = identity.StartDeletionProcessAsOwner(device); // Assert - activeIdentity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-31")); + identity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-31")); - AssertDeletionProcessWasStarted(activeIdentity); + AssertDeletionProcessWasStarted(identity); deletionProcess.Status.Should().Be(DeletionProcessStatus.Approved); deletionProcess.ApprovedAt.Should().Be(SystemTime.UtcNow); - deletionProcess.ApprovedByDevice.Should().Be(activeDevice); + deletionProcess.ApprovedByDevice.Should().Be(device); deletionProcess.GracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-31")); AssertAuditLogEntryWasCreated(deletionProcess); @@ -44,22 +44,22 @@ public void Start_deletion_process() public void Only_one_active_deletion_process_is_allowed_when_started() { // Arrange - var activeIdentity = CreateIdentity(); - var activeDevice = DeviceId.Parse("DVC"); + var identity = CreateIdentity(); + var device = DeviceId.Parse("DVC"); - activeIdentity.StartDeletionProcessAsOwner(activeDevice); + identity.StartDeletionProcessAsOwner(device); // Act - var acting = () => activeIdentity.StartDeletionProcessAsOwner(activeDevice); + var acting = () => identity.StartDeletionProcessAsOwner(device); // Assert acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); } - private static void AssertDeletionProcessWasStarted(Identity activeIdentity) + private static void AssertDeletionProcessWasStarted(Identity identity) { - activeIdentity.DeletionProcesses.Should().HaveCount(1); - var deletionProcess = activeIdentity.DeletionProcesses[0]; + identity.DeletionProcesses.Should().HaveCount(1); + var deletionProcess = identity.DeletionProcesses[0]; deletionProcess.Should().NotBeNull(); deletionProcess.Id.Should().NotBeNull(); diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs index 373ebd526d..40889e2169 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs @@ -16,15 +16,15 @@ public void Start_deletion_process() { // Arrange SystemTime.Set(DateTime.Parse("2000-01-01")); - var activeIdentity = CreateIdentity(); + var identity = CreateIdentity(); Hasher.SetHasher(new DummyHasher(new byte[] { 1, 2, 3 })); // Act - var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); + var deletionProcess = identity.StartDeletionProcessAsSupport(); // Assert - AssertDeletionProcessWasStarted(activeIdentity); + AssertDeletionProcessWasStarted(identity); deletionProcess.Status.Should().Be(DeletionProcessStatus.WaitingForApproval); AssertAuditLogEntryWasCreated(deletionProcess); @@ -38,21 +38,21 @@ public void Start_deletion_process() public void Only_one_active_deletion_process_is_allowed_when_started() { // Arrange - var activeIdentity = CreateIdentity(); + var identity = CreateIdentity(); - activeIdentity.StartDeletionProcessAsSupport(); + identity.StartDeletionProcessAsSupport(); // Act - var acting = activeIdentity.StartDeletionProcessAsSupport; + var acting = identity.StartDeletionProcessAsSupport; // Assert acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); } - private static void AssertDeletionProcessWasStarted(Identity activeIdentity) + private static void AssertDeletionProcessWasStarted(Identity identity) { - activeIdentity.DeletionProcesses.Should().HaveCount(1); - var deletionProcess = activeIdentity.DeletionProcesses[0]; + identity.DeletionProcesses.Should().HaveCount(1); + var deletionProcess = identity.DeletionProcesses[0]; deletionProcess.Should().NotBeNull(); deletionProcess.Id.Should().NotBeNull(); diff --git a/Modules/Devices/test/Devices.Jobs.IdentityDeletion.Tests/Tests/WorkerTests.cs b/Modules/Devices/test/Devices.Jobs.IdentityDeletion.Tests/Tests/WorkerTests.cs index e222812766..eb710b3d2e 100644 --- a/Modules/Devices/test/Devices.Jobs.IdentityDeletion.Tests/Tests/WorkerTests.cs +++ b/Modules/Devices/test/Devices.Jobs.IdentityDeletion.Tests/Tests/WorkerTests.cs @@ -18,7 +18,7 @@ namespace Backbone.Modules.Devices.Jobs.IdentityDeletion.Tests.Tests; public class WorkerTests { [Fact] - public async Task Worker_Calls_Command_To_Get_Identities() + public async Task Proxies_deletion_to_command_handler() { // Arrange var mockMediator = A.Fake(); @@ -26,7 +26,7 @@ public async Task Worker_Calls_Command_To_Get_Identities() RegisterFindRipeDeletionProcessesCommand(mockMediator); var identityDeleters = new List(); - var worker = GetWorker(mockMediator, identityDeleters, null); + var worker = CreateWorker(mockMediator, identityDeleters, null); // Act await worker.StartProcessing(CancellationToken.None); @@ -36,7 +36,7 @@ public async Task Worker_Calls_Command_To_Get_Identities() } [Fact] - public async Task Worker_Calls_Deleters_For_Each_Identity() + public async Task Calls_Deleters_For_Each_Identity() { // Arrange var mediator = A.Fake(); @@ -46,7 +46,7 @@ public async Task Worker_Calls_Deleters_For_Each_Identity() var mockIdentityDeleter = A.Dummy(); var identityDeleters = new List([mockIdentityDeleter]); - var worker = GetWorker(mediator, identityDeleters, null); + var worker = CreateWorker(mediator, identityDeleters, null); A.CallTo(() => mediator.Send(A._, A._)).Returns(new FindRelationshipsOfIdentityResponse() { Relationships = new List() }); @@ -54,11 +54,11 @@ public async Task Worker_Calls_Deleters_For_Each_Identity() await worker.StartProcessing(CancellationToken.None); // Assert - A.CallTo(() => mockIdentityDeleter.Delete(A._)).MustHaveHappened(2, Times.Exactly); + A.CallTo(() => mockIdentityDeleter.Delete(A._)).MustHaveHappenedTwiceExactly(); } [Fact] - public async Task Worker_Calls_FindRelationshipsByIdentityCommand_For_Each_Identity() + public async Task Calls_FindRelationshipsByIdentityCommand_For_Each_Identity() { // Arrange var mockMediator = A.Fake(); @@ -68,7 +68,7 @@ public async Task Worker_Calls_FindRelationshipsByIdentityCommand_For_Each_Ident RegisterFindRipeDeletionProcessesCommand(mockMediator, identityAddress1, identityAddress2, identityAddress3); A.CallTo(() => mockMediator.Send(A._, A._)).Returns(new FindRelationshipsOfIdentityResponse() { Relationships = new List() }); - var worker = GetWorker(mockMediator, null, null); + var worker = CreateWorker(mockMediator, null, null); // Act await worker.StartProcessing(CancellationToken.None); @@ -78,7 +78,7 @@ public async Task Worker_Calls_FindRelationshipsByIdentityCommand_For_Each_Ident } [Fact] - public async Task Worker_Publishes_PeerIdentityDeletedIntegrationEvent_For_Each_Pair_Identity_Relationship() + public async Task Publishes_PeerIdentityDeletedIntegrationEvent_For_Each_Pair_Identity_Relationship() { // Arrange var fakeMediator = A.Fake(); @@ -87,7 +87,7 @@ public async Task Worker_Publishes_PeerIdentityDeletedIntegrationEvent_For_Each_ RegisterFindRipeDeletionProcessesCommand(fakeMediator, identityAddress1, identityAddress2); var mockEventBus = A.Fake(); - var worker = GetWorker(fakeMediator, null, mockEventBus); + var worker = CreateWorker(fakeMediator, null, mockEventBus); A.CallTo(() => fakeMediator.Send(A.That.Matches(x => x.IdentityAddress == identityAddress1), A._) @@ -105,8 +105,8 @@ public async Task Worker_Publishes_PeerIdentityDeletedIntegrationEvent_For_Each_ await worker.StartProcessing(CancellationToken.None); // Assert - A.CallTo(() => mockEventBus.Publish(A.That.Matches(x => x.IdentityAddress == identityAddress1))).MustHaveHappened(1, Times.Exactly); - A.CallTo(() => mockEventBus.Publish(A.That.Matches(x => x.IdentityAddress == identityAddress2))).MustHaveHappened(2, Times.Exactly); + A.CallTo(() => mockEventBus.Publish(A.That.Matches(x => x.IdentityAddress == identityAddress1))).MustHaveHappenedOnceExactly(); + A.CallTo(() => mockEventBus.Publish(A.That.Matches(x => x.IdentityAddress == identityAddress2))).MustHaveHappenedTwiceExactly(); } private void RegisterFindRipeDeletionProcessesCommand(IMediator mediator, params string[] identityAddresses) @@ -119,7 +119,7 @@ private void RegisterFindRipeDeletionProcessesCommand(IMediator mediator, params A.CallTo(() => mediator.Send(A._, A._)).Returns(commandResponse); } - private static Worker GetWorker(IMediator mediator, List? identityDeleters, IEventBus? eventBus) + private static Worker CreateWorker(IMediator mediator, List? identityDeleters, IEventBus? eventBus) { var hostApplicationLifetime = A.Dummy(); identityDeleters ??= [A.Dummy()]; @@ -129,11 +129,11 @@ private static Worker GetWorker(IMediator mediator, List? iden return new Worker(hostApplicationLifetime, identityDeleters, mediator, pushNotificationSender, eventBus, logger); } - private static Relationship CreateRelationship(IdentityAddress identityAddress2) + private static Relationship CreateRelationship(IdentityAddress identityAddress) { var templateCreator = IdentityAddress.Create(new byte[2], "id0"); var template = new RelationshipTemplate(templateCreator, DeviceId.New(), 1, SystemTime.UtcNow, new byte[2]); - return new Relationship(template, identityAddress2, template.CreatedByDevice, TestDataGenerator.CreateRandomBytes()); + return new Relationship(template, identityAddress, template.CreatedByDevice, TestDataGenerator.CreateRandomBytes()); } } diff --git a/Modules/Messages/src/Messages.Application/Messages/Commands/AnonymizeMessagesOfIdentity/Handler.cs b/Modules/Messages/src/Messages.Application/Messages/Commands/AnonymizeMessagesOfIdentity/Handler.cs index ae49ab68c2..2e69aa437c 100644 --- a/Modules/Messages/src/Messages.Application/Messages/Commands/AnonymizeMessagesOfIdentity/Handler.cs +++ b/Modules/Messages/src/Messages.Application/Messages/Commands/AnonymizeMessagesOfIdentity/Handler.cs @@ -10,19 +10,19 @@ public class Handler : IRequestHandler { private const string DELETED_IDENTITY_STRING = "deleted identity"; private readonly IMessagesRepository _messagesRepository; - private readonly IOptions _applicationOptions; + private readonly ApplicationOptions _applicationOptions; public Handler(IMessagesRepository messagesRepository, IOptions applicationOptions) { _messagesRepository = messagesRepository; - _applicationOptions = applicationOptions; + _applicationOptions = applicationOptions.Value; } public async Task Handle(AnonymizeMessagesOfIdentityCommand request, CancellationToken cancellationToken) { var messages = await _messagesRepository.FindMessagesWithParticipant(request.IdentityAddress, cancellationToken); - var newIdentityAddress = IdentityAddress.Create(Encoding.Unicode.GetBytes(DELETED_IDENTITY_STRING), _applicationOptions.Value.AddressPrefix); + var newIdentityAddress = IdentityAddress.Create(Encoding.Unicode.GetBytes(DELETED_IDENTITY_STRING), _applicationOptions.AddressPrefix); foreach (var message in messages) { diff --git a/Modules/Messages/test/Messages.Domain.Tests/Messages.Domain.Tests.csproj b/Modules/Messages/test/Messages.Domain.Tests/Messages.Domain.Tests.csproj index 1da8b3b54e..7dd847648c 100644 --- a/Modules/Messages/test/Messages.Domain.Tests/Messages.Domain.Tests.csproj +++ b/Modules/Messages/test/Messages.Domain.Tests/Messages.Domain.Tests.csproj @@ -17,8 +17,7 @@ - - + diff --git a/Modules/Messages/test/Messages.Domain.Tests/Messages/ReplaceIdentityAddressTests.cs b/Modules/Messages/test/Messages.Domain.Tests/Messages/ReplaceIdentityAddressTests.cs index ecf500a6be..f23a6d7544 100644 --- a/Modules/Messages/test/Messages.Domain.Tests/Messages/ReplaceIdentityAddressTests.cs +++ b/Modules/Messages/test/Messages.Domain.Tests/Messages/ReplaceIdentityAddressTests.cs @@ -14,13 +14,13 @@ public class ReplaceIdentityAddressTests public void CreatedBy_gets_updated() { // Arrange - var createdByIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var createdByAddress = TestDataGenerator.CreateRandomIdentityAddress(); var newIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var message = CreateMessage(createdByIdentityAddress); + var message = CreateMessage(createdByAddress); // Act - message.ReplaceIdentityAddress(createdByIdentityAddress, newIdentityAddress); + message.ReplaceIdentityAddress(createdByAddress, newIdentityAddress); // Assert message.CreatedBy.Should().Be(newIdentityAddress); @@ -30,48 +30,45 @@ public void CreatedBy_gets_updated() public void Recipient_gets_updated() { // Arrange - var recipientIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var createdByIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var newIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var recipientAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var createdByAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var newAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var message = CreateMessage(createdByIdentityAddress, recipientIdentityAddress); + var message = CreateMessage(createdByAddress, recipientAddress); // Act - message.ReplaceIdentityAddress(recipientIdentityAddress, newIdentityAddress); + message.ReplaceIdentityAddress(recipientAddress, newAddress); // Assert - message.Recipients.Single().Address.Should().Be(newIdentityAddress); + message.Recipients.Single().Address.Should().Be(newAddress); } [Fact] public void Message_without_identity_to_be_replaced_stays_unaffected() { // Arrange - var recipient1IdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var recipient2IdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var createdByIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var recipient1Address = TestDataGenerator.CreateRandomIdentityAddress(); + var recipient2Address = TestDataGenerator.CreateRandomIdentityAddress(); + var createdByAddress = TestDataGenerator.CreateRandomIdentityAddress(); var erroneousIdentityIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var newIdentityAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var newAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var message = CreateMessage(createdByIdentityAddress, recipient1IdentityAddress, recipient2IdentityAddress); + var message = CreateMessage(createdByAddress, recipient1Address, recipient2Address); // Act - message.ReplaceIdentityAddress(erroneousIdentityIdentityAddress, newIdentityAddress); + message.ReplaceIdentityAddress(erroneousIdentityIdentityAddress, newAddress); // Assert - message.Recipients.First().Address.Should().Be(recipient1IdentityAddress); - message.Recipients.Second().Address.Should().Be(recipient2IdentityAddress); - message.CreatedBy.Should().Be(createdByIdentityAddress); + message.Recipients.First().Address.Should().Be(recipient1Address); + message.Recipients.Second().Address.Should().Be(recipient2Address); + message.CreatedBy.Should().Be(createdByAddress); } - private static Message CreateMessage(IdentityAddress createdBy, params IdentityAddress[] recipientsIdentityAddresses) + private static Message CreateMessage(IdentityAddress createdBy, params IdentityAddress[] recipientsAddresses) { - var recipientInformation = new List(); - - foreach (var recipientIdentityAddress in recipientsIdentityAddresses) - { - recipientInformation.Add(new RecipientInformation(recipientIdentityAddress, RelationshipId.New(), Array.Empty())); - } + var recipientInformation = recipientsAddresses.Select(recipientIdentityAddress => + new RecipientInformation(recipientIdentityAddress, RelationshipId.New(), []) + ).ToList(); return new Message( createdBy, @@ -82,6 +79,4 @@ private static Message CreateMessage(IdentityAddress createdBy, params IdentityA recipientInformation ); } - } - diff --git a/Modules/Quotas/src/Quotas.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs b/Modules/Quotas/src/Quotas.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs index ee28377737..57c9dfe995 100644 --- a/Modules/Quotas/src/Quotas.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs +++ b/Modules/Quotas/src/Quotas.Application/Infrastructure/Persistence/Repository/IIdentitiesRepository.cs @@ -11,6 +11,5 @@ public interface IIdentitiesRepository Task Update(Identity identity, CancellationToken cancellationToken); Task Find(string address, CancellationToken cancellationToken, bool track = false); Task> FindByAddresses(IReadOnlyCollection identityAddresses, CancellationToken cancellationToken, bool track = false); - Task Delete(Identity identity, CancellationToken cancellationToken); Task DeleteIdentities(Expression> expression, CancellationToken cancellationToken); } diff --git a/Modules/Quotas/src/Quotas.Infrastructure/Persistence/Repository/IdentitiesRepository.cs b/Modules/Quotas/src/Quotas.Infrastructure/Persistence/Repository/IdentitiesRepository.cs index b0caae77ae..6a159ec96a 100644 --- a/Modules/Quotas/src/Quotas.Infrastructure/Persistence/Repository/IdentitiesRepository.cs +++ b/Modules/Quotas/src/Quotas.Infrastructure/Persistence/Repository/IdentitiesRepository.cs @@ -28,12 +28,6 @@ public async Task Add(Identity identity, CancellationToken cancellationToken) await _dbContext.SaveChangesAsync(cancellationToken); } - public async Task Delete(Identity identity, CancellationToken cancellationToken) - { - _identitiesDbSet.Remove(identity); - await _dbContext.SaveChangesAsync(cancellationToken); - } - public async Task DeleteIdentities(Expression> filter, CancellationToken cancellationToken) { await _identitiesDbSet.Where(filter).ExecuteDeleteAsync(cancellationToken); diff --git a/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/DeleteIdentityCommandTests/HandlerTests.cs b/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/DeleteIdentityCommandTests/HandlerTests.cs index 021435bebe..cc7f3d9a87 100644 --- a/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/DeleteIdentityCommandTests/HandlerTests.cs +++ b/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/DeleteIdentityCommandTests/HandlerTests.cs @@ -22,7 +22,7 @@ public async Task Handler_calls_deletion_method_on_repository() A.CallTo(() => mockIdentitiesRepository.DeleteIdentities(A>>._, A._)).MustHaveHappenedOnceExactly(); } - private static Handler CreateHandler(IIdentitiesRepository identitiesRepository = null) + private static Handler CreateHandler(IIdentitiesRepository identitiesRepository) { return new Handler(identitiesRepository ?? A.Fake()); } diff --git a/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/GetIdentity/HandlerTests.cs b/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs similarity index 99% rename from Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/GetIdentity/HandlerTests.cs rename to Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs index d5ee166c66..d001c0f2b4 100644 --- a/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Commands/GetIdentity/HandlerTests.cs +++ b/Modules/Quotas/test/Quotas.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs @@ -11,7 +11,7 @@ using FluentAssertions; using Xunit; -namespace Backbone.Modules.Quotas.Application.Tests.Tests.Identities.Commands.GetIdentity; +namespace Backbone.Modules.Quotas.Application.Tests.Tests.Identities.Queries.GetIdentity; public class HandlerTests { diff --git a/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipTemplatesRepository.cs b/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipTemplatesRepository.cs index cccb41dd44..0828a255af 100644 --- a/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipTemplatesRepository.cs +++ b/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipTemplatesRepository.cs @@ -12,6 +12,5 @@ public interface IRelationshipTemplatesRepository Task Find(RelationshipTemplateId id, IdentityAddress identityAddress, CancellationToken cancellationToken, bool track = false, bool fillContent = true); Task Add(RelationshipTemplate template, CancellationToken cancellationToken); Task Update(RelationshipTemplate template); - Task Delete(IEnumerable templateIds, CancellationToken cancellationToken); Task DeleteTemplates(Expression> filter, CancellationToken cancellationToken); } diff --git a/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipsRepository.cs b/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipsRepository.cs index ab5e3c9537..5a4646c458 100644 --- a/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipsRepository.cs +++ b/Modules/Relationships/src/Relationships.Application/Infrastructure/Persistence/Repository/IRelationshipsRepository.cs @@ -17,7 +17,6 @@ Task> FindChangesWithIds(IEnumerable FindRelationshipChange(RelationshipChangeId id, IdentityAddress identityAddress, CancellationToken cancellationToken, bool track = false); Task Add(Relationship relationship, CancellationToken cancellationToken); Task Update(Relationship relationship); - Task Delete(IEnumerable relationshipIds, CancellationToken cancellationToken); Task RelationshipBetweenTwoIdentitiesExists(IdentityAddress identityAddressA, IdentityAddress identityAddressB, CancellationToken cancellationToken); Task DeleteRelationships(Expression> filter, CancellationToken cancellationToken); Task> FindRelationships(Expression> filter, CancellationToken cancellationToken); diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/FindRelationshipsOfIdentity/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/FindRelationshipsOfIdentity/Handler.cs index dd0e4ba90f..79a747ab0d 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/FindRelationshipsOfIdentity/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/FindRelationshipsOfIdentity/Handler.cs @@ -13,8 +13,13 @@ public Handler(IRelationshipsRepository relationshipsRepository) _relationshipsRepository = relationshipsRepository; } - public async Task Handle(FindRelationshipsOfIdentityQuery request, CancellationToken cancellationToken) => new() + public async Task Handle(FindRelationshipsOfIdentityQuery request, CancellationToken cancellationToken) { - Relationships = await _relationshipsRepository.FindRelationships(Relationship.HasParticipant(request.IdentityAddress), cancellationToken) - }; + var relationships = await _relationshipsRepository.FindRelationships(Relationship.HasParticipant(request.IdentityAddress), cancellationToken); + + return new FindRelationshipsOfIdentityResponse + { + Relationships = relationships + }; + } } diff --git a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipTemplatesRepository.cs b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipTemplatesRepository.cs index 60d43bff66..4e84d372dc 100644 --- a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipTemplatesRepository.cs +++ b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipTemplatesRepository.cs @@ -29,11 +29,6 @@ public async Task Add(RelationshipTemplate template, CancellationToken cancellat await _dbContext.SaveChangesAsync(cancellationToken); } - public async Task Delete(IEnumerable templateIds, CancellationToken cancellationToken) - { - await _templates.WithIdIn(templateIds).ExecuteDeleteAsync(cancellationToken); - } - public async Task DeleteTemplates(Expression> filter, CancellationToken cancellationToken) { await _templates.Where(filter).ExecuteDeleteAsync(cancellationToken); diff --git a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipsRepository.cs b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipsRepository.cs index 68a9bb0b03..946cd96b3e 100644 --- a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipsRepository.cs +++ b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/Repository/RelationshipsRepository.cs @@ -135,11 +135,6 @@ public async Task RelationshipBetweenTwoIdentitiesExists(IdentityAddress i .AnyAsync(cancellationToken); } - public async Task Delete(IEnumerable relationshipIds, CancellationToken cancellationToken) - { - await _relationships.WithIdIn(relationshipIds).ExecuteDeleteAsync(cancellationToken); - } - public async Task DeleteRelationships(Expression> filter, CancellationToken cancellationToken) { await _relationships.Where(filter).ExecuteDeleteAsync(cancellationToken); diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Extensions/RelationshipTemplateQueryableExtensionsTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Extensions/RelationshipTemplateQueryableExtensionsTests.cs index 4ded9d5e14..d30f2f9384 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Extensions/RelationshipTemplateQueryableExtensionsTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Extensions/RelationshipTemplateQueryableExtensionsTests.cs @@ -5,6 +5,7 @@ using Backbone.UnitTestTools.TestDoubles.Fakes; using FluentAssertions; using Xunit; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Relationships.Application.Tests.Extensions; @@ -52,18 +53,18 @@ public void NotExpiredFor_DoesNotFilterOutTemplatesForParticipants() public void NotExpiredFor_DoesNotFilterOutTemplatesWithoutExpiryDate() { // Arrange - var templateCreator = TestDataGenerator.CreateRandomAddress(); - var requestCreator = TestDataGenerator.CreateRandomAddress(); + var templateCreator = CreateRandomIdentityAddress(); + var requestCreator = CreateRandomIdentityAddress(); - var template = new RelationshipTemplate(templateCreator, DeviceId.New(), 1, null, TestDataGenerator.CreateRandomBytes()); - var relationship = new Relationship(template, requestCreator, DeviceId.New(), TestDataGenerator.CreateRandomBytes()); + var template = new RelationshipTemplate(templateCreator, DeviceId.New(), 1, null, CreateRandomBytes()); + var relationship = new Relationship(template, requestCreator, DeviceId.New(), CreateRandomBytes()); _arrangeContext.RelationshipTemplates.Add(template); _arrangeContext.Relationships.Add(relationship); _arrangeContext.SaveChanges(); - var accessor = TestDataGenerator.CreateRandomAddress(); + var accessor = CreateRandomIdentityAddress(); // Act @@ -82,18 +83,18 @@ public void NotExpiredFor_DoesNotFilterOutTemplatesWithoutExpiryDate() public void NotExpiredFor_FiltersOutExpiredTemplatesForNonParticipants() { // Arrange - var templateCreator = TestDataGenerator.CreateRandomAddress(); - var requestCreator = TestDataGenerator.CreateRandomAddress(); + var templateCreator = CreateRandomIdentityAddress(); + var requestCreator = CreateRandomIdentityAddress(); - var template = new RelationshipTemplate(templateCreator, DeviceId.New(), 1, YESTERDAY, TestDataGenerator.CreateRandomBytes()); - var relationship = new Relationship(template, requestCreator, DeviceId.New(), TestDataGenerator.CreateRandomBytes()); + var template = new RelationshipTemplate(templateCreator, DeviceId.New(), 1, YESTERDAY, CreateRandomBytes()); + var relationship = new Relationship(template, requestCreator, DeviceId.New(), CreateRandomBytes()); _arrangeContext.RelationshipTemplates.Add(template); _arrangeContext.Relationships.Add(relationship); _arrangeContext.SaveChanges(); - var accessor = TestDataGenerator.CreateRandomAddress(); + var accessor = CreateRandomIdentityAddress(); // Act diff --git a/Modules/Relationships/test/Relationships.Application.Tests/TestDataGenerator.cs b/Modules/Relationships/test/Relationships.Application.Tests/TestDataGenerator.cs index de94afd10a..1667673ac8 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/TestDataGenerator.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/TestDataGenerator.cs @@ -2,19 +2,6 @@ namespace Backbone.Modules.Relationships.Application.Tests; -public static class TestDataGenerator +public class TestDataGenerator : Backbone.UnitTestTools.Data.TestDataGenerator { - public static IdentityAddress CreateRandomAddress() - { - return IdentityAddress.Create(CreateRandomBytes(), "id0"); - } - - public static byte[] CreateRandomBytes() - { - var random = new Random(); - var bytes = new byte[10]; - random.NextBytes(bytes); - - return bytes; - } } diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Identities/IdentityDeleterTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Identities/IdentityDeleterTests.cs index f3b9dbdfe0..1eed4ea145 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Identities/IdentityDeleterTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Identities/IdentityDeleterTests.cs @@ -3,6 +3,7 @@ using FakeItEasy; using MediatR; using Xunit; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Relationships.Application.Tests.Tests.Identities; public class IdentityDeleterTests @@ -11,7 +12,7 @@ public class IdentityDeleterTests public async Task Deleter_calls_correct_command() { // Arrange - var identityAddress = UnitTestTools.Data.TestDataGenerator.CreateRandomIdentityAddress(); + var identityAddress = CreateRandomIdentityAddress(); var mockMediator = A.Fake(); var deleter = new IdentityDeleter(mockMediator); diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/RelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/RelationshipTests.cs index 310751aa03..73f5e4505e 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/RelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/RelationshipTests.cs @@ -30,8 +30,10 @@ public class RelationshipTests [Fact] public void New_Relationship_Has_Correct_Data() { + // Act var relationship = CreatePendingRelationship(); + // Assert relationship.From.Should().Be(FROM_IDENTITY); relationship.To.Should().Be(TO_IDENTITY); relationship.Status.Should().Be(RelationshipStatus.Pending); @@ -52,11 +54,14 @@ public void New_Relationship_Has_Correct_Data() [Fact] public void Accepting_CreationRequest_Changes_Relevant_Data() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + // Assert relationship.Status.Should().Be(RelationshipStatus.Active); change.Status.Should().Be(RelationshipChangeStatus.Accepted); @@ -70,31 +75,43 @@ public void Accepting_CreationRequest_Changes_Relevant_Data() [Fact] public void Cannot_Accept_CreationRequests_Without_Content() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ContentIsRequiredForCompletingRelationships()); } [Fact] public void Cannot_Accept_Already_Completed_CreationRequests() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + // Act Action acting = () => relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void Relationship_Cannot_Be_Accepted_By_Creator() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.AcceptChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCannotBeAcceptedByCreator()); } @@ -105,11 +122,14 @@ public void Relationship_Cannot_Be_Accepted_By_Creator() [Fact] public void Rejecting_CreationRequest_Sets_Relevant_Data() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + // Assert relationship.Status.Should().Be(RelationshipStatus.Rejected); change.Status.Should().Be(RelationshipChangeStatus.Rejected); @@ -123,31 +143,44 @@ public void Rejecting_CreationRequest_Sets_Relevant_Data() [Fact] public void Cannot_Reject_CreationRequests_Without_Content() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ContentIsRequiredForCompletingRelationships()); } [Fact] public void Cannot_Reject_Already_Completed_CreationRequests() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + // Act Action acting = () => relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void CreationRequest_Cannot_Be_Rejected_By_Creator() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.RejectChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCannotBeRejectedByCreator()); } @@ -158,11 +191,14 @@ public void CreationRequest_Cannot_Be_Rejected_By_Creator() [Fact] public void Revoking_CreationRequest_Sets_Relevant_Data() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + // Assert relationship.Status.Should().Be(RelationshipStatus.Revoked); change.Status.Should().Be(RelationshipChangeStatus.Revoked); @@ -176,31 +212,43 @@ public void Revoking_CreationRequest_Sets_Relevant_Data() [Fact] public void Cannot_Revoke_CreationRequests_Without_Content() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ContentIsRequiredForCompletingRelationships()); } [Fact] public void Cannot_Revoke_Already_Completed_CreationRequests() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + // Act Action acting = () => relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void CreationRequest_Cannot_Be_Revoked_By_Recipient() { + // Arrange var relationship = CreatePendingRelationship(); var change = relationship.Changes.GetOpenCreation(); + // Act Action acting = () => relationship.RevokeChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCanOnlyBeRevokedByCreator()); } @@ -213,27 +261,39 @@ public void CreationRequest_Cannot_Be_Revoked_By_Recipient() [Fact] public void Cannot_Accept_Non_Existent_ChangeRequests() { + // Arrange var relationship = CreatePendingRelationship(); + // Act Action acting = () => relationship.AcceptChange(RelationshipChangeId.New(), TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(GenericDomainErrors.NotFound()); } [Fact] public void Cannot_Reject_Non_Existent_ChangeRequests() { + // Arrange var relationship = CreatePendingRelationship(); + // Act Action acting = () => relationship.RejectChange(RelationshipChangeId.New(), TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(GenericDomainErrors.NotFound()); } [Fact] public void Cannot_Revoke_Non_Existent_ChangeRequests() { + // Arrange var relationship = CreatePendingRelationship(); + // Act Action acting = () => relationship.RevokeChange(RelationshipChangeId.New(), TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(GenericDomainErrors.NotFound()); } @@ -244,10 +304,13 @@ public void Cannot_Revoke_Non_Existent_ChangeRequests() [Fact] public void Requesting_Termination_Sets_Relevant_Data() { + // Arrange var relationship = CreateActiveRelationship(); + // Act relationship.RequestTermination(FROM_IDENTITY, FROM_DEVICE); + // Assert relationship.Changes.Should().HaveCount(2); var termination = relationship.Changes.GetOpenTermination(); @@ -263,9 +326,13 @@ public void Requesting_Termination_Sets_Relevant_Data() [Fact] public void Cannot_Request_Termination_For_Pending_Relationships() { + // Arrange var relationship = CreatePendingRelationship(); + // Act Action acting = () => relationship.RequestTermination(FROM_IDENTITY, FROM_DEVICE); + + // Assert acting.Should().Throw().WithError(DomainErrors.OnlyActiveRelationshipsCanBeTerminated()); } @@ -274,11 +341,14 @@ public void Cannot_Request_Termination_For_Pending_Relationships() [Fact] public void Accepting_TerminationRequest_Changes_Relevant_Data() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, null); + // Assert relationship.Status.Should().Be(RelationshipStatus.Terminated); change.Status.Should().Be(RelationshipChangeStatus.Accepted); @@ -291,22 +361,30 @@ public void Accepting_TerminationRequest_Changes_Relevant_Data() [Fact] public void Cannot_Accept_Already_Completed_TerminationRequests() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); Action acting = () => relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void TerminationRequest_Cannot_Be_Accepted_By_Creator() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act Action acting = () => relationship.AcceptChange(change.Id, FROM_IDENTITY, FROM_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCannotBeAcceptedByCreator()); } @@ -317,11 +395,14 @@ public void TerminationRequest_Cannot_Be_Accepted_By_Creator() [Fact] public void Rejecting_TerminationRequest_Changes_Relevant_Data() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, null); + // Assert relationship.Status.Should().Be(RelationshipStatus.Active); change.Status.Should().Be(RelationshipChangeStatus.Rejected); @@ -334,22 +415,30 @@ public void Rejecting_TerminationRequest_Changes_Relevant_Data() [Fact] public void Cannot_Reject_Already_Completed_TerminationRequests() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); Action acting = () => relationship.RejectChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void TerminationRequest_Cannot_Be_Rejected_By_Creator() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act Action acting = () => relationship.RejectChange(change.Id, FROM_IDENTITY, FROM_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCannotBeRejectedByCreator()); } @@ -360,11 +449,14 @@ public void TerminationRequest_Cannot_Be_Rejected_By_Creator() [Fact] public void Revoking_TerminationRequest_Sets_Relevant_Data() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, null); + // Assert relationship.Status.Should().Be(RelationshipStatus.Active); change.Status.Should().Be(RelationshipChangeStatus.Revoked); @@ -377,22 +469,30 @@ public void Revoking_TerminationRequest_Sets_Relevant_Data() [Fact] public void Cannot_Revoke_Already_Completed_TerminationRequests() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + // Act Action acting = () => relationship.RevokeChange(change.Id, FROM_IDENTITY, FROM_DEVICE, RESPONSE_CONTENT); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestIsAlreadyCompleted()); } [Fact] public void TerminationRequest_Cannot_Be_Revoked_By_Recipient() { + // Arrange var relationship = CreateRelationshipWithOpenTermination(); var change = relationship.Changes.GetOpenTermination(); + // Act Action acting = () => relationship.RevokeChange(change.Id, TO_IDENTITY, TO_DEVICE, null); + + // Assert acting.Should().Throw().WithError(DomainErrors.ChangeRequestCanOnlyBeRevokedByCreator()); } @@ -400,53 +500,12 @@ public void TerminationRequest_Cannot_Be_Revoked_By_Recipient() #endregion - #region Constructor Functions - - private static Relationship CreatePendingRelationship() - { - var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); - return relationship; - } - - private static Relationship CreateActiveRelationship() - { - var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); - var change = relationship.Changes.GetOpenCreation(); - relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); - return relationship; - } - - private static Relationship CreateActiveRelationship(IdentityAddress from = null, IdentityAddress to = null) - { - RelationshipTemplate template = null; - if (to is not null) - { - template = new(to, TO_DEVICE, 1, SystemTime.UtcNow.AddDays(1), [0]); - } - - var relationship = new Relationship(template ?? TEMPLATE, from ?? FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); - var change = relationship.Changes.GetOpenCreation(); - relationship.AcceptChange(change.Id, to ?? TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); - return relationship; - } - - private static Relationship CreateRelationshipWithOpenTermination() - { - var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); - var change = relationship.Changes.GetOpenCreation(); - relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); - - relationship.RequestTermination(FROM_IDENTITY, FROM_DEVICE); - return relationship; - } - - #endregion - #region Selectors [Fact] public void WithParticipant_From() { + // Arrange var id1 = TestDataGenerator.CreateRandomIdentityAddress(); var id2 = TestDataGenerator.CreateRandomIdentityAddress(); var id3 = TestDataGenerator.CreateRandomIdentityAddress(); @@ -460,14 +519,18 @@ public void WithParticipant_From() }; var filter = Relationship.HasParticipant(id1); + + // Act var filteredList = relationships.AsQueryable().Where(filter).ToList(); + // Assert filteredList.Should().HaveCount(2); } [Fact] public void WithParticipant_To() { + // Arrange var id1 = TestDataGenerator.CreateRandomIdentityAddress(); var id2 = TestDataGenerator.CreateRandomIdentityAddress(); var id3 = TestDataGenerator.CreateRandomIdentityAddress(); @@ -481,14 +544,18 @@ public void WithParticipant_To() }; var filter = Relationship.HasParticipant(id1); + + // Act var filteredList = relationships.AsQueryable().Where(filter).ToList(); + // Assert filteredList.Should().HaveCount(2); } [Fact] public void WithParticipant_Mixed() { + // Arrange var id1 = TestDataGenerator.CreateRandomIdentityAddress(); var id2 = TestDataGenerator.CreateRandomIdentityAddress(); var id3 = TestDataGenerator.CreateRandomIdentityAddress(); @@ -502,10 +569,55 @@ public void WithParticipant_Mixed() }; var filter = Relationship.HasParticipant(id1); + + // Act var filteredList = relationships.AsQueryable().Where(filter).ToList(); + // Assert filteredList.Should().HaveCount(2); } #endregion + + #region Constructor Functions + + private static Relationship CreatePendingRelationship() + { + var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); + return relationship; + } + + private static Relationship CreateActiveRelationship() + { + var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); + var change = relationship.Changes.GetOpenCreation(); + relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + return relationship; + } + + private static Relationship CreateActiveRelationship(IdentityAddress from, IdentityAddress to = null) + { + RelationshipTemplate template = null; + if (to is not null) + { + template = new RelationshipTemplate(to, TO_DEVICE, 1, SystemTime.UtcNow.AddDays(1), [0]); + } + + var relationship = new Relationship(template ?? TEMPLATE, from ?? FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); + var change = relationship.Changes.GetOpenCreation(); + relationship.AcceptChange(change.Id, to ?? TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + return relationship; + } + + private static Relationship CreateRelationshipWithOpenTermination() + { + var relationship = new Relationship(TEMPLATE, FROM_IDENTITY, FROM_DEVICE, REQUEST_CONTENT); + var change = relationship.Changes.GetOpenCreation(); + relationship.AcceptChange(change.Id, TO_IDENTITY, TO_DEVICE, RESPONSE_CONTENT); + + relationship.RequestTermination(FROM_IDENTITY, FROM_DEVICE); + return relationship; + } + + #endregion } diff --git a/Modules/Tokens/src/Tokens.Domain/Entities/Token.cs b/Modules/Tokens/src/Tokens.Domain/Entities/Token.cs index 91178b9533..2f585fff88 100644 --- a/Modules/Tokens/src/Tokens.Domain/Entities/Token.cs +++ b/Modules/Tokens/src/Tokens.Domain/Entities/Token.cs @@ -48,6 +48,6 @@ public void LoadContent(byte[] content) public static Expression> WasCreatedBy(IdentityAddress identityAddress) { - return i => i.CreatedBy == identityAddress; + return t => t.CreatedBy == identityAddress; } } diff --git a/Modules/Tokens/test/Tokens.Application.Tests/Tests/Tokens/DeleteTokenOfIdentity/HandlerTests.cs b/Modules/Tokens/test/Tokens.Application.Tests/Tests/Tokens/DeleteTokenOfIdentity/HandlerTests.cs index f5332fffc5..2c56bf1cbf 100644 --- a/Modules/Tokens/test/Tokens.Application.Tests/Tests/Tokens/DeleteTokenOfIdentity/HandlerTests.cs +++ b/Modules/Tokens/test/Tokens.Application.Tests/Tests/Tokens/DeleteTokenOfIdentity/HandlerTests.cs @@ -2,6 +2,7 @@ using Backbone.Modules.Tokens.Application.Infrastructure.Persistence.Repository; using Backbone.Modules.Tokens.Application.Tokens.Commands.DeleteTokensOfIdentity; using Backbone.Modules.Tokens.Domain.Entities; +using Backbone.UnitTestTools.Data; using FakeItEasy; using Xunit; @@ -15,7 +16,7 @@ public async Task Command_calls_delete_on_repository() var mockRelationshipTemplatesRepository = A.Fake(); var handler = new Handler(mockRelationshipTemplatesRepository); - var request = new DeleteTokensOfIdentityCommand(UnitTestTools.Data.TestDataGenerator.CreateRandomIdentityAddress()); + var request = new DeleteTokensOfIdentityCommand(TestDataGenerator.CreateRandomIdentityAddress()); // Act await handler.Handle(request, CancellationToken.None);