From ca0f3bb799a79340ec54b4f38815568d0a9272a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 23 Dec 2024 01:28:17 +0100 Subject: [PATCH 1/3] fx --- .../Create/CreateDialogCommandValidator.cs | 4 +- .../Update/UpdateDialogCommandValidator.cs | 4 +- .../Activities/ActivityValidatorTests.cs | 58 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs index 42a867469..c7b0c55d0 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs @@ -434,8 +434,8 @@ public CreateDialogDialogActivityDtoValidator( .When(x => x.Type != DialogActivityType.Values.Information); RuleFor(x => x.TransmissionId) .Null() - .WithMessage($"A {nameof(DialogActivityType.Values.DialogOpened)} activity cannot reference a transmission.") - .When(x => x.Type == DialogActivityType.Values.DialogOpened); + .WithMessage($"Only {nameof(DialogActivityType.Values.TransmissionOpened)} activity can reference a transmission.") + .When(x => x.Type != DialogActivityType.Values.TransmissionOpened); RuleFor(x => x.TransmissionId) .NotEmpty() .WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs index 909d47e7a..c853763de 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs @@ -400,8 +400,8 @@ public UpdateDialogDialogActivityDtoValidator( .When(x => x.Type != DialogActivityType.Values.Information); RuleFor(x => x.TransmissionId) .Null() - .WithMessage($"A {nameof(DialogActivityType.Values.DialogOpened)} activity cannot reference a transmission.") - .When(x => x.Type == DialogActivityType.Values.DialogOpened); + .WithMessage($"Only {nameof(DialogActivityType.Values.TransmissionOpened)} activity can reference a transmission.") + .When(x => x.Type != DialogActivityType.Values.TransmissionOpened); RuleFor(x => x.TransmissionId) .NotEmpty() .WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") diff --git a/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs b/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs new file mode 100644 index 000000000..72e3a1cb2 --- /dev/null +++ b/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs @@ -0,0 +1,58 @@ +using AutoMapper; +using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Common.Actors; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update; +using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; +using Digdir.Library.Entity.Abstractions.Features.Identifiable; +using Digdir.Tool.Dialogporten.GenerateFakeData; +using FluentAssertions; +using ActivityDto = Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create.ActivityDto; + +namespace Digdir.Domain.Dialogporten.Application.Unit.Tests.Features.V1.ServiceOwner.Activities; + +public class ActivityValidatorTests +{ + + + public static IEnumerable ActivityTypes() => + from DialogActivityType.Values activityType in Enum.GetValues(typeof(DialogActivityType.Values)) + select new object[] { activityType, }; + + [Theory, MemberData(nameof(ActivityTypes))] + public void Only_TransmissionOpened_Is_Allowed_To_Set_TransmissionId( + DialogActivityType.Values activityType) + { + // Arrange + var mapper = new MapperConfiguration(cfg => cfg.CreateMap()).CreateMapper(); + var activity = DialogGenerator.GenerateFakeDialogActivity(type: activityType); + activity.TransmissionId = IdentifiableExtensions.CreateVersion7(); + + var localizationValidator = new LocalizationDtosValidator(); + var actorValidator = new ActorValidator(); + var createValidator = new CreateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); + var updateValidator = new UpdateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); + + // Act + var createValidation = createValidator.Validate(activity); + var updateValidation = updateValidator.Validate(mapper.Map(activity)); + + // Assert + if (activityType == DialogActivityType.Values.TransmissionOpened) + { + createValidation.IsValid.Should().BeTrue(); + updateValidation.IsValid.Should().BeTrue(); + } + else + { + createValidation.IsValid.Should().BeFalse(); + updateValidation.IsValid.Should().BeFalse(); + + createValidation.Errors.Should().ContainSingle(); + updateValidation.Errors.Should().ContainSingle(); + + createValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened"); + updateValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened"); + } + } +} From 45f4cc034d41464899729f5fea6796fabc53c08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 23 Dec 2024 01:31:33 +0100 Subject: [PATCH 2/3] fxx --- .../Activities/ActivityValidatorTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs b/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs index 72e3a1cb2..03e5bcb68 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs @@ -7,14 +7,16 @@ using Digdir.Library.Entity.Abstractions.Features.Identifiable; using Digdir.Tool.Dialogporten.GenerateFakeData; using FluentAssertions; -using ActivityDto = Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create.ActivityDto; + +using UpdateActivityDto = + Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update.ActivityDto; +using CreateActivityDto = + Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create.ActivityDto; namespace Digdir.Domain.Dialogporten.Application.Unit.Tests.Features.V1.ServiceOwner.Activities; public class ActivityValidatorTests { - - public static IEnumerable ActivityTypes() => from DialogActivityType.Values activityType in Enum.GetValues(typeof(DialogActivityType.Values)) select new object[] { activityType, }; @@ -24,18 +26,20 @@ public void Only_TransmissionOpened_Is_Allowed_To_Set_TransmissionId( DialogActivityType.Values activityType) { // Arrange - var mapper = new MapperConfiguration(cfg => cfg.CreateMap()).CreateMapper(); + var mapper = new MapperConfiguration(cfg => cfg.CreateMap()).CreateMapper(); + var activity = DialogGenerator.GenerateFakeDialogActivity(type: activityType); activity.TransmissionId = IdentifiableExtensions.CreateVersion7(); var localizationValidator = new LocalizationDtosValidator(); var actorValidator = new ActorValidator(); + var createValidator = new CreateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); var updateValidator = new UpdateDialogDialogActivityDtoValidator(localizationValidator, actorValidator); // Act var createValidation = createValidator.Validate(activity); - var updateValidation = updateValidator.Validate(mapper.Map(activity)); + var updateValidation = updateValidator.Validate(mapper.Map(activity)); // Assert if (activityType == DialogActivityType.Values.TransmissionOpened) From 672fa5f2e8820d53b631cd1f855e3da4175617a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 23 Dec 2024 01:33:49 +0100 Subject: [PATCH 3/3] words --- .../Dialogs/Commands/Create/CreateDialogCommandValidator.cs | 4 ++-- .../Dialogs/Commands/Update/UpdateDialogCommandValidator.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs index c7b0c55d0..e35be4053 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs @@ -434,11 +434,11 @@ public CreateDialogDialogActivityDtoValidator( .When(x => x.Type != DialogActivityType.Values.Information); RuleFor(x => x.TransmissionId) .Null() - .WithMessage($"Only {nameof(DialogActivityType.Values.TransmissionOpened)} activity can reference a transmission.") + .WithMessage($"Only activities of type {nameof(DialogActivityType.Values.TransmissionOpened)} can reference a transmission.") .When(x => x.Type != DialogActivityType.Values.TransmissionOpened); RuleFor(x => x.TransmissionId) .NotEmpty() - .WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") + .WithMessage($"An activity of type {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") .When(x => x.Type == DialogActivityType.Values.TransmissionOpened); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs index c853763de..f7ea74dff 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs @@ -400,11 +400,11 @@ public UpdateDialogDialogActivityDtoValidator( .When(x => x.Type != DialogActivityType.Values.Information); RuleFor(x => x.TransmissionId) .Null() - .WithMessage($"Only {nameof(DialogActivityType.Values.TransmissionOpened)} activity can reference a transmission.") + .WithMessage($"Only activities of type {nameof(DialogActivityType.Values.TransmissionOpened)} can reference a transmission.") .When(x => x.Type != DialogActivityType.Values.TransmissionOpened); RuleFor(x => x.TransmissionId) .NotEmpty() - .WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") + .WithMessage($"An activity of type {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.") .When(x => x.Type == DialogActivityType.Values.TransmissionOpened); } }