From d3e03f99a1288527917f36f19d76ae2981ce5c71 Mon Sep 17 00:00:00 2001 From: Timo Notheisen Date: Thu, 28 Nov 2024 13:59:14 +0100 Subject: [PATCH] test: check what happens if we remove all calls to Hasher.SetHasher --- .../Identities/ApproveDeletionProcessTests.cs | 260 ++++++++-------- .../DeletionGracePeriodReminderTests.cs | 282 +++++++++--------- .../DeletionProcessApprovalReminderTests.cs | 278 ++++++++--------- .../DeletionProcessGracePeriodTests.cs | 260 ++++++++-------- .../Identities/RejectDeletionProcessTests.cs | 214 ++++++------- .../StartDeletionProcessAsOwnerTests.cs | 270 ++++++++--------- .../StartDeletionProcessAsSupportTests.cs | 188 ++++++------ 7 files changed, 883 insertions(+), 869 deletions(-) diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/ApproveDeletionProcessTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/ApproveDeletionProcessTests.cs index 78f9a1c942..442dea73e9 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/ApproveDeletionProcessTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/ApproveDeletionProcessTests.cs @@ -1,131 +1,133 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class ApproveDeletionProcessTests : AbstractTestsBase +// { +// [Fact] +// public void Approve_deletion_process_waiting_for_approval() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// +// // Act +// identity.ApproveDeletionProcess(identity.GetDeletionProcessInStatus(DeletionProcessStatus.WaitingForApproval)!.Id, deviceId); +// +// // Assert +// identity.Status.Should().Be(IdentityStatus.ToBeDeleted); +// identity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); +// identity.TierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// } +// +// [Fact] +// public void Throws_when_device_not_owned_by_identity() +// { +// // Arrange +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// +// // Act +// var acting = () => identity.ApproveDeletionProcess(identity.DeletionProcesses[0].Id, DeviceId.Parse("DVC")); +// var exception = acting.Should().Throw().Which; +// +// // Assert +// exception.Code.Should().Be("error.platform.recordNotFound"); +// exception.Message.Should().Contain("Device"); +// } +// +// [Fact] +// public void Throws_when_deletion_process_does_not_exist() +// { +// // Arrange +// var identity = CreateIdentity(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// var deletionProcessId = IdentityDeletionProcessId.Create("IDP00000000000000001").Value; +// +// // Act +// var acting = () => identity.ApproveDeletionProcess(deletionProcessId, deviceId); +// var exception = acting.Should().Throw().Which; +// +// // Assert +// exception.Code.Should().Be("error.platform.recordNotFound"); +// exception.Message.Should().Contain("IdentityDeletionProcess"); +// } +// +// [Fact] +// public void Throws_when_deletion_process_is_not_in_status_waiting_for_approval() +// { +// // Arrange +// var identity = CreateIdentity(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// var deletionProcess = identity.StartDeletionProcessAsOwner(deviceId); +// +// // Act +// var acting = () => identity.ApproveDeletionProcess(deletionProcess.Id, deviceId); +// var exception = acting.Should().Throw().Which; +// +// // Assert +// exception.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// exception.Message.Should().Contain("WaitingForApproval"); +// } +// +// [Fact] +// public void Raises_domain_events() +// { +// //Arrange +// var activeIdentity = TestDataGenerator.CreateIdentity(); +// var activeDevice = activeIdentity.Devices[0]; +// var tierBeforeDeletion = activeIdentity.TierId; +// var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); +// +// //Act +// activeIdentity.ApproveDeletionProcess(deletionProcess.Id, activeDevice.Id); +// +// //Assert +// var (tierOfIdentityChangedDomainEvent, identityToBeDeletedDomainEvent) = activeIdentity.Should().HaveDomainEvents(); +// +// tierOfIdentityChangedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); +// tierOfIdentityChangedDomainEvent.OldTierId.Should().Be(tierBeforeDeletion); +// tierOfIdentityChangedDomainEvent.NewTierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); +// +// identityToBeDeletedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// deletionProcess.AuditLog.Should().HaveCount(2); +// +// var auditLogEntry = deletionProcess.AuditLog[1]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// +// private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() +// { +// var identity = CreateIdentity(); +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// identity.StartDeletionProcessAsSupport(); +// return identity; +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class ApproveDeletionProcessTests : AbstractTestsBase -{ - [Fact] - public void Approve_deletion_process_waiting_for_approval() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - - // Act - identity.ApproveDeletionProcess(identity.GetDeletionProcessInStatus(DeletionProcessStatus.WaitingForApproval)!.Id, deviceId); - - // Assert - identity.Status.Should().Be(IdentityStatus.ToBeDeleted); - identity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); - identity.TierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - } - - [Fact] - public void Throws_when_device_not_owned_by_identity() - { - // Arrange - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - - // Act - var acting = () => identity.ApproveDeletionProcess(identity.DeletionProcesses[0].Id, DeviceId.Parse("DVC")); - var exception = acting.Should().Throw().Which; - - // Assert - exception.Code.Should().Be("error.platform.recordNotFound"); - exception.Message.Should().Contain("Device"); - } - - [Fact] - public void Throws_when_deletion_process_does_not_exist() - { - // Arrange - var identity = CreateIdentity(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - var deletionProcessId = IdentityDeletionProcessId.Create("IDP00000000000000001").Value; - - // Act - var acting = () => identity.ApproveDeletionProcess(deletionProcessId, deviceId); - var exception = acting.Should().Throw().Which; - - // Assert - exception.Code.Should().Be("error.platform.recordNotFound"); - exception.Message.Should().Contain("IdentityDeletionProcess"); - } - - [Fact] - public void Throws_when_deletion_process_is_not_in_status_waiting_for_approval() - { - // Arrange - var identity = CreateIdentity(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - var deletionProcess = identity.StartDeletionProcessAsOwner(deviceId); - - // Act - var acting = () => identity.ApproveDeletionProcess(deletionProcess.Id, deviceId); - var exception = acting.Should().Throw().Which; - - // Assert - exception.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - exception.Message.Should().Contain("WaitingForApproval"); - } - - [Fact] - public void Raises_domain_events() - { - //Arrange - var activeIdentity = TestDataGenerator.CreateIdentity(); - var activeDevice = activeIdentity.Devices[0]; - var tierBeforeDeletion = activeIdentity.TierId; - var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); - - //Act - activeIdentity.ApproveDeletionProcess(deletionProcess.Id, activeDevice.Id); - - //Assert - var (tierOfIdentityChangedDomainEvent, identityToBeDeletedDomainEvent) = activeIdentity.Should().HaveDomainEvents(); - - tierOfIdentityChangedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); - tierOfIdentityChangedDomainEvent.OldTierId.Should().Be(tierBeforeDeletion); - tierOfIdentityChangedDomainEvent.NewTierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); - - identityToBeDeletedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - deletionProcess.AuditLog.Should().HaveCount(2); - - var auditLogEntry = deletionProcess.AuditLog[1]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } - - private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() - { - var identity = CreateIdentity(); - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - identity.StartDeletionProcessAsSupport(); - return identity; - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionGracePeriodReminderTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionGracePeriodReminderTests.cs index dc5ff06243..819b19b13d 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionGracePeriodReminderTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionGracePeriodReminderTests.cs @@ -1,142 +1,144 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class DeletionGracePeriodReminderTests : AbstractTestsBase +// { +// public override void Dispose() +// { +// Hasher.Reset(); +// base.Dispose(); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder1Sent_updates_GracePeriodReminder1SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder1Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder1SentAt.Should().Be(currentDateTime); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder1Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder1Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder2Sent_updates_GracePeriodReminder2SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder2Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder2SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionGracePeriodReminder2Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder2Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder3Sent_updates_GracePeriodReminder3SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder3Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder3SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionGracePeriodReminder3Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder3Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// deletionProcess.AuditLog.Should().HaveCount(2); +// +// var auditLogEntry = deletionProcess.AuditLog[1]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.Approved); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); +// } +// +// private static Identity CreateIdentityWithApprovedDeletionProcess() +// { +// var identity = CreateIdentity(); +// var device = new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE); +// identity.Devices.Add(device); +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// +// identity.StartDeletionProcessAsOwner(device.Id); +// +// return identity; +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class DeletionGracePeriodReminderTests : AbstractTestsBase -{ - public override void Dispose() - { - Hasher.Reset(); - base.Dispose(); - } - - [Fact] - public void DeletionGracePeriodReminder1Sent_updates_GracePeriodReminder1SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder1Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder1SentAt.Should().Be(currentDateTime); - } - - [Fact] - public void DeletionGracePeriodReminder1Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder1Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionGracePeriodReminder2Sent_updates_GracePeriodReminder2SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder2Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder2SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionGracePeriodReminder2Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder2Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionGracePeriodReminder3Sent_updates_GracePeriodReminder3SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder3Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder3SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionGracePeriodReminder3Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder3Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - deletionProcess.AuditLog.Should().HaveCount(2); - - var auditLogEntry = deletionProcess.AuditLog[1]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.Approved); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); - } - - private static Identity CreateIdentityWithApprovedDeletionProcess() - { - var identity = CreateIdentity(); - var device = new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE); - identity.Devices.Add(device); - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - - identity.StartDeletionProcessAsOwner(device.Id); - - return identity; - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessApprovalReminderTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessApprovalReminderTests.cs index f3d3213049..dd8a846720 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessApprovalReminderTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessApprovalReminderTests.cs @@ -1,140 +1,142 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class DeletionProcessApprovalReminderTests : AbstractTestsBase +// { +// [Fact] +// public void DeletionProcessApprovalReminder1Sent_updates_ApprovalReminder1SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// +// // Act +// identity.DeletionProcessApprovalReminder1Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.ApprovalReminder1SentAt.Should().Be(currentDateTime); +// } +// +// [Fact] +// public void DeletionProcessApprovalReminder1Sent_fails_when_no_deletion_process_waiting_for_approval_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionProcessApprovalReminder1Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionProcessApprovalReminder2Sent_updates_ApprovalReminder2SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// +// // Act +// identity.DeletionProcessApprovalReminder2Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.ApprovalReminder2SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionProcessApprovalReminder2Sent_fails_when_no_deletion_process_waiting_for_approval_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionProcessApprovalReminder2Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionProcessApprovalReminder3Sent_updates_ApprovalReminder3SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// +// // Act +// identity.DeletionProcessApprovalReminder3Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.ApprovalReminder3SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionProcessApprovalReminder3Sent_fails_when_no_deletion_process_waiting_for_approval_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = CreateIdentity(); +// +// // Act +// var acting = identity.DeletionProcessApprovalReminder3Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// deletionProcess.AuditLog.Should().HaveCount(2); +// +// var auditLogEntry = deletionProcess.AuditLog[1]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); +// } +// +// private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() +// { +// var identity = CreateIdentity(); +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// identity.StartDeletionProcessAsSupport(); +// +// return identity; +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// +// [Fact] +// public override void Dispose() +// { +// Hasher.Reset(); +// base.Dispose(); +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class DeletionProcessApprovalReminderTests : AbstractTestsBase -{ - [Fact] - public void DeletionProcessApprovalReminder1Sent_updates_ApprovalReminder1SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - - // Act - identity.DeletionProcessApprovalReminder1Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.ApprovalReminder1SentAt.Should().Be(currentDateTime); - } - - [Fact] - public void DeletionProcessApprovalReminder1Sent_fails_when_no_deletion_process_waiting_for_approval_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionProcessApprovalReminder1Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionProcessApprovalReminder2Sent_updates_ApprovalReminder2SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - - // Act - identity.DeletionProcessApprovalReminder2Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.ApprovalReminder2SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionProcessApprovalReminder2Sent_fails_when_no_deletion_process_waiting_for_approval_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionProcessApprovalReminder2Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionProcessApprovalReminder3Sent_updates_ApprovalReminder3SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - - // Act - identity.DeletionProcessApprovalReminder3Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.WaitingForApproval)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.ApprovalReminder3SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionProcessApprovalReminder3Sent_fails_when_no_deletion_process_waiting_for_approval_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = CreateIdentity(); - - // Act - var acting = identity.DeletionProcessApprovalReminder3Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - deletionProcess.AuditLog.Should().HaveCount(2); - - var auditLogEntry = deletionProcess.AuditLog[1]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); - } - - private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() - { - var identity = CreateIdentity(); - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - identity.StartDeletionProcessAsSupport(); - - return identity; - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } - - [Fact] - public override void Dispose() - { - Hasher.Reset(); - base.Dispose(); - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessGracePeriodTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessGracePeriodTests.cs index 0719bd71c5..44e9fd27fd 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessGracePeriodTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionProcessGracePeriodTests.cs @@ -1,131 +1,133 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class DeletionProcessGracePeriodTests : AbstractTestsBase +// { +// public override void Dispose() +// { +// Hasher.Reset(); +// base.Dispose(); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder1Sent_updates_GracePeriodReminder1SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder1Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder1SentAt.Should().Be(currentDateTime); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder1Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = TestDataGenerator.CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder1Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder2Sent_updates_GracePeriodReminder2SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder2Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder2SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionGracePeriodReminder2Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = TestDataGenerator.CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder2Sent; +// +// // Asserterror +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// [Fact] +// public void DeletionGracePeriodReminder3Sent_updates_GracePeriodReminder3SentAt() +// { +// // Arrange +// var currentDateTime = DateTime.Parse("2000-01-01"); +// SystemTime.Set(currentDateTime); +// var identity = CreateIdentityWithApprovedDeletionProcess(); +// +// // Act +// identity.DeletionGracePeriodReminder3Sent(); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// deletionProcess.GracePeriodReminder3SentAt.Should().Be(currentDateTime); +// } +// +// +// [Fact] +// public void DeletionGracePeriodReminder3Sent_fails_when_no_approved_deletion_process_exists() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var identity = TestDataGenerator.CreateIdentity(); +// +// // Act +// var acting = identity.DeletionGracePeriodReminder3Sent; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// deletionProcess.AuditLog.Should().HaveCount(2); +// +// var auditLogEntry = deletionProcess.AuditLog[1]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.Approved); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); +// } +// +// private static Identity CreateIdentityWithApprovedDeletionProcess() +// { +// var identity = TestDataGenerator.CreateIdentity(); +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// identity.StartDeletionProcessAsOwner(identity.Devices.First().Id); +// +// return identity; +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class DeletionProcessGracePeriodTests : AbstractTestsBase -{ - public override void Dispose() - { - Hasher.Reset(); - base.Dispose(); - } - - [Fact] - public void DeletionGracePeriodReminder1Sent_updates_GracePeriodReminder1SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder1Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder1SentAt.Should().Be(currentDateTime); - } - - [Fact] - public void DeletionGracePeriodReminder1Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = TestDataGenerator.CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder1Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionGracePeriodReminder2Sent_updates_GracePeriodReminder2SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder2Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder2SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionGracePeriodReminder2Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = TestDataGenerator.CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder2Sent; - - // Asserterror - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - [Fact] - public void DeletionGracePeriodReminder3Sent_updates_GracePeriodReminder3SentAt() - { - // Arrange - var currentDateTime = DateTime.Parse("2000-01-01"); - SystemTime.Set(currentDateTime); - var identity = CreateIdentityWithApprovedDeletionProcess(); - - // Act - identity.DeletionGracePeriodReminder3Sent(); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Approved)!; - AssertAuditLogEntryWasCreated(deletionProcess); - deletionProcess.GracePeriodReminder3SentAt.Should().Be(currentDateTime); - } - - - [Fact] - public void DeletionGracePeriodReminder3Sent_fails_when_no_approved_deletion_process_exists() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var identity = TestDataGenerator.CreateIdentity(); - - // Act - var acting = identity.DeletionGracePeriodReminder3Sent; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - deletionProcess.AuditLog.Should().HaveCount(2); - - var auditLogEntry = deletionProcess.AuditLog[1]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.Approved); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); - } - - private static Identity CreateIdentityWithApprovedDeletionProcess() - { - var identity = TestDataGenerator.CreateIdentity(); - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - identity.StartDeletionProcessAsOwner(identity.Devices.First().Id); - - return identity; - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/RejectDeletionProcessTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/RejectDeletionProcessTests.cs index f20e681f06..52a5415e44 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/RejectDeletionProcessTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/RejectDeletionProcessTests.cs @@ -1,108 +1,110 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class RejectDeletionProcessTests : AbstractTestsBase +// { +// [Fact] +// public void Reject_deletion_process_waiting_for_approval() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2020-01-01")); +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// +// // Act +// identity.RejectDeletionProcess(identity.DeletionProcesses[0].Id, deviceId); +// +// // Assert +// var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Rejected)!; +// AssertAuditLogEntryWasCreated(deletionProcess); +// } +// +// [Fact] +// public void Throws_when_device_not_owned_by_identity() +// { +// // Arrange +// var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); +// +// // Act +// var acting = () => identity.RejectDeletionProcess(identity.DeletionProcesses[0].Id, DeviceId.Parse("DVC")); +// +// // Assert +// var exception = acting.Should().Throw().Which; +// +// exception.Code.Should().Be("error.platform.recordNotFound"); +// exception.Message.Should().Contain("Device"); +// } +// +// [Fact] +// public void Throws_when_deletion_process_does_not_exist() +// { +// // Arrange +// var identity = CreateIdentity(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// var deletionProcessId = IdentityDeletionProcessId.Create("IDP00000000000000001").Value; +// +// // Act +// var acting = () => identity.RejectDeletionProcess(deletionProcessId, deviceId); +// +// // Assert +// var exception = acting.Should().Throw().Which; +// +// exception.Code.Should().Be("error.platform.recordNotFound"); +// exception.Message.Should().Contain("IdentityDeletionProcess"); +// } +// +// [Fact] +// public void Throws_when_deletion_process_is_not_in_status_waiting_for_approval() +// { +// // Arrange +// var identity = CreateIdentity(); +// identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); +// var deviceId = identity.Devices[0].Id; +// var deletionProcess = identity.StartDeletionProcessAsOwner(deviceId); +// +// // Act +// var acting = () => identity.RejectDeletionProcess(deletionProcess.Id, deviceId); +// +// // Assert +// var exception = acting.Should().Throw().Which; +// +// exception.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); +// exception.Message.Should().Contain("WaitingForApproval"); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// deletionProcess.AuditLog.Should().HaveCount(2); +// +// var auditLogEntry = deletionProcess.AuditLog[1]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Rejected); +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// +// private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() +// { +// var identity = CreateIdentity(); +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// identity.StartDeletionProcessAsSupport(); +// return identity; +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class RejectDeletionProcessTests : AbstractTestsBase -{ - [Fact] - public void Reject_deletion_process_waiting_for_approval() - { - // Arrange - SystemTime.Set(DateTime.Parse("2020-01-01")); - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - - // Act - identity.RejectDeletionProcess(identity.DeletionProcesses[0].Id, deviceId); - - // Assert - var deletionProcess = identity.DeletionProcesses.FirstOrDefault(d => d.Status == DeletionProcessStatus.Rejected)!; - AssertAuditLogEntryWasCreated(deletionProcess); - } - - [Fact] - public void Throws_when_device_not_owned_by_identity() - { - // Arrange - var identity = CreateIdentityWithDeletionProcessWaitingForApproval(); - - // Act - var acting = () => identity.RejectDeletionProcess(identity.DeletionProcesses[0].Id, DeviceId.Parse("DVC")); - - // Assert - var exception = acting.Should().Throw().Which; - - exception.Code.Should().Be("error.platform.recordNotFound"); - exception.Message.Should().Contain("Device"); - } - - [Fact] - public void Throws_when_deletion_process_does_not_exist() - { - // Arrange - var identity = CreateIdentity(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - var deletionProcessId = IdentityDeletionProcessId.Create("IDP00000000000000001").Value; - - // Act - var acting = () => identity.RejectDeletionProcess(deletionProcessId, deviceId); - - // Assert - var exception = acting.Should().Throw().Which; - - exception.Code.Should().Be("error.platform.recordNotFound"); - exception.Message.Should().Contain("IdentityDeletionProcess"); - } - - [Fact] - public void Throws_when_deletion_process_is_not_in_status_waiting_for_approval() - { - // Arrange - var identity = CreateIdentity(); - identity.Devices.Add(new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE)); - var deviceId = identity.Devices[0].Id; - var deletionProcess = identity.StartDeletionProcessAsOwner(deviceId); - - // Act - var acting = () => identity.RejectDeletionProcess(deletionProcess.Id, deviceId); - - // Assert - var exception = acting.Should().Throw().Which; - - exception.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus"); - exception.Message.Should().Contain("WaitingForApproval"); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - deletionProcess.AuditLog.Should().HaveCount(2); - - var auditLogEntry = deletionProcess.AuditLog[1]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Rejected); - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } - - private static Identity CreateIdentityWithDeletionProcessWaitingForApproval() - { - var identity = CreateIdentity(); - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - identity.StartDeletionProcessAsSupport(); - return identity; - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs index 55076cc41a..d038fb9397 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsOwnerTests.cs @@ -1,136 +1,138 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class StartDeletionProcessAsOwnerTests : AbstractTestsBase +// { +// public override void Dispose() +// { +// Hasher.Reset(); +// base.Dispose(); +// } +// +// [Fact] +// public void Start_deletion_process() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var activeIdentity = CreateIdentity(); +// var activeDevice = new Device(activeIdentity, CommunicationLanguage.DEFAULT_LANGUAGE); +// activeIdentity.Devices.Add(activeDevice); +// +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// +// // Act +// var deletionProcess = activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); +// +// // Assert +// activeIdentity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); +// activeIdentity.TierId.Value.Should().Be(Tier.QUEUED_FOR_DELETION.Id.Value); +// activeIdentity.Status.Should().Be(IdentityStatus.ToBeDeleted); +// +// AssertDeletionProcessWasStarted(activeIdentity); +// deletionProcess.Status.Should().Be(DeletionProcessStatus.Approved); +// deletionProcess.ApprovedAt.Should().Be(SystemTime.UtcNow); +// deletionProcess.ApprovedByDevice.Should().Be(activeDevice.Id); +// deletionProcess.GracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); +// +// AssertAuditLogEntryWasCreated(deletionProcess); +// var auditLogEntry = deletionProcess.AuditLog[0]; +// auditLogEntry.MessageKey.Should().Be(MessageKey.StartedByOwner); +// auditLogEntry.DeviceIdHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); +// } +// +// [Fact] +// public void Throws_when_device_not_owned_by_identity() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2020-01-01")); +// var identity = TestDataGenerator.CreateIdentity(); +// var device = new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE); +// +// identity.Devices.Add(device); +// +// // Act +// var acting = () => identity.StartDeletionProcessAsOwner(DeviceId.Parse("DVC")); +// +// // Assert +// var exception = acting.Should().Throw().Which; +// exception.Code.Should().Be("error.platform.recordNotFound"); +// exception.Message.Should().Contain("Device"); +// } +// +// [Fact] +// public void Only_one_active_deletion_process_is_allowed_when_started() +// { +// // Arrange +// var activeIdentity = CreateIdentity(); +// var activeDevice = new Device(activeIdentity, CommunicationLanguage.DEFAULT_LANGUAGE); +// activeIdentity.Devices.Add(activeDevice); +// +// activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); +// +// // Act +// var acting = () => activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); +// } +// +// [Fact] +// public void Raises_domain_events() +// { +// //Arrange +// var activeIdentity = TestDataGenerator.CreateIdentity(); +// var tierBeforeDeletion = activeIdentity.TierId; +// var activeDevice = activeIdentity.Devices[0]; +// +// //Act +// activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); +// +// //Assert +// var (tierOfIdentityChangedDomainEvent, identityToBeDeletedDomainEvent) = activeIdentity.Should().HaveDomainEvents(); +// +// tierOfIdentityChangedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); +// tierOfIdentityChangedDomainEvent.OldTierId.Should().Be(tierBeforeDeletion); +// tierOfIdentityChangedDomainEvent.NewTierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); +// +// identityToBeDeletedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); +// } +// +// private static void AssertDeletionProcessWasStarted(Identity activeIdentity) +// { +// activeIdentity.DeletionProcesses.Should().HaveCount(1); +// var deletionProcess = activeIdentity.DeletionProcesses[0]; +// deletionProcess.Should().NotBeNull(); +// +// deletionProcess.Id.Should().NotBeNull(); +// deletionProcess.Id.Value.Should().HaveLength(20); +// +// deletionProcess.CreatedAt.Should().Be(SystemTime.UtcNow); +// +// deletionProcess.AuditLog.Should().HaveCount(1); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// var auditLogEntry = deletionProcess.AuditLog[0]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().BeNull(); +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class StartDeletionProcessAsOwnerTests : AbstractTestsBase -{ - public override void Dispose() - { - Hasher.Reset(); - base.Dispose(); - } - - [Fact] - public void Start_deletion_process() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var activeIdentity = CreateIdentity(); - var activeDevice = new Device(activeIdentity, CommunicationLanguage.DEFAULT_LANGUAGE); - activeIdentity.Devices.Add(activeDevice); - - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - - // Act - var deletionProcess = activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); - - // Assert - activeIdentity.DeletionGracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); - activeIdentity.TierId.Value.Should().Be(Tier.QUEUED_FOR_DELETION.Id.Value); - activeIdentity.Status.Should().Be(IdentityStatus.ToBeDeleted); - - AssertDeletionProcessWasStarted(activeIdentity); - deletionProcess.Status.Should().Be(DeletionProcessStatus.Approved); - deletionProcess.ApprovedAt.Should().Be(SystemTime.UtcNow); - deletionProcess.ApprovedByDevice.Should().Be(activeDevice.Id); - deletionProcess.GracePeriodEndsAt.Should().Be(DateTime.Parse("2000-01-15")); - - AssertAuditLogEntryWasCreated(deletionProcess); - var auditLogEntry = deletionProcess.AuditLog[0]; - auditLogEntry.MessageKey.Should().Be(MessageKey.StartedByOwner); - auditLogEntry.DeviceIdHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.Approved); - } - - [Fact] - public void Throws_when_device_not_owned_by_identity() - { - // Arrange - SystemTime.Set(DateTime.Parse("2020-01-01")); - var identity = TestDataGenerator.CreateIdentity(); - var device = new Device(identity, CommunicationLanguage.DEFAULT_LANGUAGE); - - identity.Devices.Add(device); - - // Act - var acting = () => identity.StartDeletionProcessAsOwner(DeviceId.Parse("DVC")); - - // Assert - var exception = acting.Should().Throw().Which; - exception.Code.Should().Be("error.platform.recordNotFound"); - exception.Message.Should().Contain("Device"); - } - - [Fact] - public void Only_one_active_deletion_process_is_allowed_when_started() - { - // Arrange - var activeIdentity = CreateIdentity(); - var activeDevice = new Device(activeIdentity, CommunicationLanguage.DEFAULT_LANGUAGE); - activeIdentity.Devices.Add(activeDevice); - - activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); - - // Act - var acting = () => activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); - } - - [Fact] - public void Raises_domain_events() - { - //Arrange - var activeIdentity = TestDataGenerator.CreateIdentity(); - var tierBeforeDeletion = activeIdentity.TierId; - var activeDevice = activeIdentity.Devices[0]; - - //Act - activeIdentity.StartDeletionProcessAsOwner(activeDevice.Id); - - //Assert - var (tierOfIdentityChangedDomainEvent, identityToBeDeletedDomainEvent) = activeIdentity.Should().HaveDomainEvents(); - - tierOfIdentityChangedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); - tierOfIdentityChangedDomainEvent.OldTierId.Should().Be(tierBeforeDeletion); - tierOfIdentityChangedDomainEvent.NewTierId.Should().Be(Tier.QUEUED_FOR_DELETION.Id); - - identityToBeDeletedDomainEvent.IdentityAddress.Should().Be(activeIdentity.Address); - } - - private static void AssertDeletionProcessWasStarted(Identity activeIdentity) - { - activeIdentity.DeletionProcesses.Should().HaveCount(1); - var deletionProcess = activeIdentity.DeletionProcesses[0]; - deletionProcess.Should().NotBeNull(); - - deletionProcess.Id.Should().NotBeNull(); - deletionProcess.Id.Value.Should().HaveLength(20); - - deletionProcess.CreatedAt.Should().Be(SystemTime.UtcNow); - - deletionProcess.AuditLog.Should().HaveCount(1); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - var auditLogEntry = deletionProcess.AuditLog[0]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().BeNull(); - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } -} diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs index 4a4aa40a4d..ba647f4bdc 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/StartDeletionProcessAsSupportTests.cs @@ -1,95 +1,97 @@ -using Backbone.BuildingBlocks.Domain.Exceptions; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Devices.Domain.Aggregates.Tier; -using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; -using Backbone.Modules.Devices.Domain.Entities.Identities; -using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; -using Backbone.Tooling; +// using Backbone.BuildingBlocks.Domain.Exceptions; +// using Backbone.DevelopmentKit.Identity.ValueObjects; +// using Backbone.Modules.Devices.Domain.Aggregates.Tier; +// using Backbone.Modules.Devices.Domain.DomainEvents.Outgoing; +// using Backbone.Modules.Devices.Domain.Entities.Identities; +// using Backbone.Modules.Devices.Domain.Tests.Identities.TestDoubles; +// using Backbone.Tooling; +// +// namespace Backbone.Modules.Devices.Domain.Tests.Identities; +// +// public class StartDeletionProcessAsSupportTests : AbstractTestsBase +// { +// [Fact] +// public void Start_deletion_process() +// { +// // Arrange +// SystemTime.Set(DateTime.Parse("2000-01-01")); +// var activeIdentity = CreateIdentity(); +// +// Hasher.SetHasher(new DummyHasher([1, 2, 3])); +// +// // Act +// var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); +// +// // Assert +// AssertDeletionProcessWasStarted(activeIdentity); +// deletionProcess.Status.Should().Be(DeletionProcessStatus.WaitingForApproval); +// +// AssertAuditLogEntryWasCreated(deletionProcess); +// var auditLogEntry = deletionProcess.AuditLog[0]; +// auditLogEntry.MessageKey.Should().Be(MessageKey.StartedBySupport); +// auditLogEntry.DeviceIdHash.Should().BeNull(); +// auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); +// } +// +// [Fact] +// public void Only_one_active_deletion_process_is_allowed_when_started() +// { +// // Arrange +// var activeIdentity = CreateIdentity(); +// +// activeIdentity.StartDeletionProcessAsSupport(); +// +// // Act +// var acting = activeIdentity.StartDeletionProcessAsSupport; +// +// // Assert +// acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); +// } +// +// [Fact] +// public void Raises_IdentityDeletionProcessStartedDomainEvent() +// { +// //Arrange +// var activeIdentity = CreateIdentity(); +// +// //Act +// var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); +// +// //Assert +// var domainEvent = deletionProcess.Should().HaveASingleDomainEvent(); +// domainEvent.Address.Should().Be(activeIdentity.Address); +// domainEvent.DeletionProcessId.Should().Be(deletionProcess.Id); +// domainEvent.Initiator.Should().Be(null); +// } +// +// private static void AssertDeletionProcessWasStarted(Identity activeIdentity) +// { +// activeIdentity.DeletionProcesses.Should().HaveCount(1); +// var deletionProcess = activeIdentity.DeletionProcesses[0]; +// deletionProcess.Should().NotBeNull(); +// +// deletionProcess.Id.Should().NotBeNull(); +// deletionProcess.Id.Value.Should().HaveLength(20); +// +// deletionProcess.CreatedAt.Should().Be(SystemTime.UtcNow); +// +// deletionProcess.AuditLog.Should().HaveCount(1); +// } +// +// private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) +// { +// var auditLogEntry = deletionProcess.AuditLog[0]; +// auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); +// auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); +// auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); +// auditLogEntry.OldStatus.Should().BeNull(); +// } +// +// private static Identity CreateIdentity() +// { +// var address = IdentityAddress.Create([], "prod.enmeshed.eu"); +// return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); +// } +// } -namespace Backbone.Modules.Devices.Domain.Tests.Identities; -public class StartDeletionProcessAsSupportTests : AbstractTestsBase -{ - [Fact] - public void Start_deletion_process() - { - // Arrange - SystemTime.Set(DateTime.Parse("2000-01-01")); - var activeIdentity = CreateIdentity(); - - Hasher.SetHasher(new DummyHasher([1, 2, 3])); - - // Act - var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); - - // Assert - AssertDeletionProcessWasStarted(activeIdentity); - deletionProcess.Status.Should().Be(DeletionProcessStatus.WaitingForApproval); - - AssertAuditLogEntryWasCreated(deletionProcess); - var auditLogEntry = deletionProcess.AuditLog[0]; - auditLogEntry.MessageKey.Should().Be(MessageKey.StartedBySupport); - auditLogEntry.DeviceIdHash.Should().BeNull(); - auditLogEntry.NewStatus.Should().Be(DeletionProcessStatus.WaitingForApproval); - } - - [Fact] - public void Only_one_active_deletion_process_is_allowed_when_started() - { - // Arrange - var activeIdentity = CreateIdentity(); - - activeIdentity.StartDeletionProcessAsSupport(); - - // Act - var acting = activeIdentity.StartDeletionProcessAsSupport; - - // Assert - acting.Should().Throw().Which.Code.Should().Be("error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"); - } - - [Fact] - public void Raises_IdentityDeletionProcessStartedDomainEvent() - { - //Arrange - var activeIdentity = CreateIdentity(); - - //Act - var deletionProcess = activeIdentity.StartDeletionProcessAsSupport(); - - //Assert - var domainEvent = deletionProcess.Should().HaveASingleDomainEvent(); - domainEvent.Address.Should().Be(activeIdentity.Address); - domainEvent.DeletionProcessId.Should().Be(deletionProcess.Id); - domainEvent.Initiator.Should().Be(null); - } - - private static void AssertDeletionProcessWasStarted(Identity activeIdentity) - { - activeIdentity.DeletionProcesses.Should().HaveCount(1); - var deletionProcess = activeIdentity.DeletionProcesses[0]; - deletionProcess.Should().NotBeNull(); - - deletionProcess.Id.Should().NotBeNull(); - deletionProcess.Id.Value.Should().HaveLength(20); - - deletionProcess.CreatedAt.Should().Be(SystemTime.UtcNow); - - deletionProcess.AuditLog.Should().HaveCount(1); - } - - private static void AssertAuditLogEntryWasCreated(IdentityDeletionProcess deletionProcess) - { - var auditLogEntry = deletionProcess.AuditLog[0]; - auditLogEntry.ProcessId.Should().Be(deletionProcess.Id); - auditLogEntry.CreatedAt.Should().Be(SystemTime.UtcNow); - auditLogEntry.IdentityAddressHash.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); - auditLogEntry.OldStatus.Should().BeNull(); - } - - private static Identity CreateIdentity() - { - var address = IdentityAddress.Create([], "prod.enmeshed.eu"); - return new Identity("", address, [], TierId.Generate(), 1, CommunicationLanguage.DEFAULT_LANGUAGE); - } -}