public SwapStepsCommandValidator(
            IJourneyValidator journeyValidator,
            IStepValidator stepValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingStepAsync(command.JourneyId, command.StepAId, token))
            .WithMessage(_ => "Journey and/or step doesn't exist!")
            .MustAsync((command, token) => BeAnExistingStepAsync(command.JourneyId, command.StepBId, token))
            .WithMessage(_ => "Journey and/or step doesn't exist!")
            .MustAsync((command, token) => BeAdjacentStepsInAJourneyAsync(command.JourneyId, command.StepAId, command.StepBId, token))
            .WithMessage(command => $"Steps are not adjacent! Steps={command.StepAId} and {command.StepBId}")
            .Must(command => HaveAValidRowVersion(command.StepARowVersion))
            .WithMessage(command => $"Not a valid row version! Row version{command.StepARowVersion}")
            .Must(command => HaveAValidRowVersion(command.StepBRowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.StepBRowVersion}");

            async Task <bool> BeAnExistingStepAsync(int journeyId, int stepId, CancellationToken token)
            => await journeyValidator.ExistsStepAsync(journeyId, stepId, token);

            async Task <bool> BeAdjacentStepsInAJourneyAsync(int journeyId, int stepAId, int stepBId, CancellationToken token)
            => await journeyValidator.AreAdjacentStepsInAJourneyAsync(journeyId, stepAId, stepBId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
Exemplo n.º 2
0
        public DeleteStepCommandValidator(
            IJourneyValidator journeyValidator,
            IStepValidator stepValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingStepAsync(command.JourneyId, command.StepId, token))
            .WithMessage(command => "Journey and/or step doesn't exist!")
            .MustAsync((command, token) => BeAVoidedStepAsync(command.StepId, token))
            .WithMessage(command => $"Step is not voided! Step={command.StepId}")
            .MustAsync((command, token) => JourneyForStepNotBeUsedAsync(command.JourneyId, token))
            .WithMessage(command => $"No steps can be deleted from journey when preservation tags exists in journey! Journey={command.JourneyId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingStepAsync(int journeyId, int stepId, CancellationToken token)
            => await journeyValidator.ExistsStepAsync(journeyId, stepId, token);

            async Task <bool> BeAVoidedStepAsync(int stepId, CancellationToken token)
            => await stepValidator.IsVoidedAsync(stepId, token);

            async Task <bool> JourneyForStepNotBeUsedAsync(int journeyId, CancellationToken token)
            => !await journeyValidator.IsAnyStepInJourneyInUseAsync(journeyId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
Exemplo n.º 3
0
        public UpdateJourneyCommandValidator(
            IJourneyValidator journeyValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingJourneyAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey doesn't exist! Journey={command.JourneyId}")
            .MustAsync((command, token) => HaveUniqueJourneyTitleAsync(command.JourneyId, command.Title, token))
            .WithMessage(command => $"Another journey with this title already exists! Journey={command.Title}")
            .MustAsync((command, token) => NotBeAVoidedJourneyAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey is voided! Journey={command.JourneyId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingJourneyAsync(int journeyId, CancellationToken token)
            => await journeyValidator.ExistsAsync(journeyId, token);
            async Task <bool> HaveUniqueJourneyTitleAsync(int journeyId, string journeyTitle, CancellationToken token) =>
            !await journeyValidator.ExistsWithSameTitleInAnotherJourneyAsync(journeyId, journeyTitle, token);
            async Task <bool> NotBeAVoidedJourneyAsync(int journeyId, CancellationToken token)
            => !await journeyValidator.IsVoidedAsync(journeyId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
Exemplo n.º 4
0
        public DeleteJourneyCommandValidator(
            IJourneyValidator journeyValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingJourneyAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey doesn't exist! Journey={command.JourneyId}")
            .MustAsync((command, token) => BeAVoidedJourneyAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey is not voided! Journey={command.JourneyId}")
            .MustAsync((command, token) => NotBeUsedAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey is used! Journey={command.JourneyId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingJourneyAsync(int journeyId, CancellationToken token)
            => await journeyValidator.ExistsAsync(journeyId, token);

            async Task <bool> BeAVoidedJourneyAsync(int journeyId, CancellationToken token)
            => await journeyValidator.IsVoidedAsync(journeyId, token);

            async Task <bool> NotBeUsedAsync(int journeyId, CancellationToken token)
            => !await journeyValidator.IsInUseAsync(journeyId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
        public CreateJourneyCommandValidator(IJourneyValidator journeyValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => HaveUniqueJourneyTitleAsync(command.Title, token))
            .WithMessage(command => "Journey with title already exists!");

            async Task <bool> HaveUniqueJourneyTitleAsync(string journeyTitle, CancellationToken token)
            => !await journeyValidator.ExistsWithSameTitleAsync(journeyTitle, token);
        }
        public UpdateStepCommandValidator(
            IJourneyValidator journeyValidator,
            IStepValidator stepValidator,
            IModeValidator modeValidator,
            IResponsibleValidator responsibleValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingStepAsync(command.JourneyId, command.StepId, token))
            .WithMessage(_ => "Journey and/or step doesn't exist!")
            .MustAsync((command, token) => HaveUniqueStepTitleInJourneyAsync(command.JourneyId, command.StepId, command.Title, token))
            .WithMessage(command => $"Another step with title already exists in a journey! Step={command.Title}")
            .MustAsync((command, token) => NotBeAVoidedStepAsync(command.StepId, token))
            .WithMessage(command => $"Step is voided! Step={command.StepId}")
            .MustAsync((command, token) => BeAnExistingModeAsync(command.ModeId, token))
            .WithMessage(command => $"Mode doesn't exist! Mode={command.ModeId}")
            .MustAsync((command, token) => NotChangedToAVoidedModeAsync(command.ModeId, command.StepId, token))
            .WithMessage(command => $"Mode is voided! Mode={command.ModeId}")
            .MustAsync((command, token) => NotBeAnExistingAndVoidedResponsibleAsync(command.ResponsibleCode, token))
            .WithMessage(command => $"Responsible is voided! ResponsibleCode={command.ResponsibleCode}")
            .MustAsync((command, token) => NotHaveOtherStepsWithSameAutoTransferMethodInJourneyAsync(command.JourneyId, command.StepId, command.AutoTransferMethod, token))
            .WithMessage(command => $"Same auto transfer method can not be set on multiple steps in a journey! Method={command.AutoTransferMethod}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingStepAsync(int journeyId, int stepId, CancellationToken token)
            => await journeyValidator.ExistsStepAsync(journeyId, stepId, token);

            async Task <bool> HaveUniqueStepTitleInJourneyAsync(int journeyId, int stepId, string stepTitle, CancellationToken token) =>
            !await journeyValidator.OtherStepExistsWithSameTitleAsync(journeyId, stepId, stepTitle, token);

            async Task <bool> NotBeAVoidedStepAsync(int stepId, CancellationToken token)
            => !await stepValidator.IsVoidedAsync(stepId, token);

            async Task <bool> BeAnExistingModeAsync(int modeId, CancellationToken token)
            => await modeValidator.ExistsAsync(modeId, token);

            async Task <bool> NotChangedToAVoidedModeAsync(int modeId, int stepId, CancellationToken token)
            => await stepValidator.HasModeAsync(modeId, stepId, token) ||
            !await modeValidator.IsVoidedAsync(modeId, token);

            async Task <bool> NotBeAnExistingAndVoidedResponsibleAsync(string responsibleCode, CancellationToken token)
            => !await responsibleValidator.ExistsAndIsVoidedAsync(responsibleCode, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);

            async Task <bool> NotHaveOtherStepsWithSameAutoTransferMethodInJourneyAsync(int journeyId, int stepId, AutoTransferMethod autoTransferMethod, CancellationToken token)
            => autoTransferMethod == AutoTransferMethod.None || !await journeyValidator.HasOtherStepWithAutoTransferMethodAsync(journeyId, stepId, autoTransferMethod, token);
        }
        public DuplicateJourneyCommandValidator(IJourneyValidator journeyValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingJourneyAsync(command.JourneyId, token))
            .WithMessage(command => $"Journey doesn't exist! Journey={command.JourneyId}")
            .MustAsync((command, token) => HaveUniqueJourneyTitleForDuplicateAsync(command.JourneyId, token))
            .WithMessage(command => "Journey with title for the copy already exists!");

            async Task <bool> BeAnExistingJourneyAsync(int journeyId, CancellationToken token)
            => await journeyValidator.ExistsAsync(journeyId, token);
            async Task <bool> HaveUniqueJourneyTitleForDuplicateAsync(int journeyId, CancellationToken token)
            => !await journeyValidator.ExistsWithDuplicateTitleAsync(journeyId, token);
        }
Exemplo n.º 8
0
        public CreateStepCommandValidator(
            IJourneyValidator journeyValidator,
            IModeValidator modeValidator,
            IResponsibleValidator responsibleValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingJourney(command.JourneyId, token))
            .WithMessage(command => $"Journey doesn't exist! Journey={command.JourneyId}")
            .MustAsync((command, token) => NotBeAVoidedJourney(command.JourneyId, token))
            .WithMessage(command => $"Journey is voided! Journey={command.JourneyId}")
            .MustAsync((command, token) => BeAnExistingModeAsync(command.ModeId, token))
            .WithMessage(command => $"Mode doesn't exist! Mode={command.ModeId}")
            .MustAsync((command, token) => NotBeAVoidedModeAsync(command.ModeId, token))
            .WithMessage(command => $"Mode is voided! Mode={command.ModeId}")
            .MustAsync((command, token) => NotBeAnExistingAndVoidedResponsibleAsync(command.ResponsibleCode, token))
            .WithMessage(command => $"Responsible is voided! Responsible={command.ResponsibleCode}")
            .MustAsync((command, token) => HaveUniqueStepTitleAsync(command.JourneyId, command.Title, token))
            .WithMessage(command => $"Step with title already exists in journey! Step={command.Title}")
            .MustAsync((command, token) => NotBeAnyStepWithSameAutoTransferMethodInJourneyAsync(command.JourneyId, command.AutoTransferMethod, token))
            .WithMessage(command => $"Same auto transfer method can not be set on multiple steps in a journey! Method={command.AutoTransferMethod}");

            async Task <bool> HaveUniqueStepTitleAsync(int journeyId, string stepTitle, CancellationToken token)
            => !await journeyValidator.AnyStepExistsWithSameTitleAsync(journeyId, stepTitle, token);

            async Task <bool> BeAnExistingJourney(int journeyId, CancellationToken token)
            => await journeyValidator.ExistsAsync(journeyId, token);

            async Task <bool> BeAnExistingModeAsync(int modeId, CancellationToken token)
            => await modeValidator.ExistsAsync(modeId, token);

            async Task <bool> NotBeAnExistingAndVoidedResponsibleAsync(string responsibleCode, CancellationToken token)
            => !await responsibleValidator.ExistsAndIsVoidedAsync(responsibleCode, token);

            async Task <bool> NotBeAVoidedJourney(int journeyId, CancellationToken token)
            => !await journeyValidator.IsVoidedAsync(journeyId, token);

            async Task <bool> NotBeAVoidedModeAsync(int modeId, CancellationToken token)
            => !await modeValidator.IsVoidedAsync(modeId, token);

            async Task <bool> NotBeAnyStepWithSameAutoTransferMethodInJourneyAsync(int journeyId, AutoTransferMethod autoTransferMethod, CancellationToken token)
            => autoTransferMethod == AutoTransferMethod.None || !await journeyValidator.HasAnyStepWithAutoTransferMethodAsync(journeyId, autoTransferMethod, token);
        }
        public UnvoidStepCommandValidator(
            IJourneyValidator journeyValidator,
            IStepValidator stepValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingStepAsync(command.JourneyId, command.StepId, token))
            .WithMessage(command => "Journey and/or step doesn't exist!")
            .MustAsync((command, token) => BeAVoidedStepAsync(command.StepId, token))
            .WithMessage(command => $"Step is not voided! Step={command.StepId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> BeAnExistingStepAsync(int journeyId, int stepId, CancellationToken token)
            => await journeyValidator.ExistsStepAsync(journeyId, stepId, token);
            async Task <bool> BeAVoidedStepAsync(int stepId, CancellationToken token)
            => await stepValidator.IsVoidedAsync(stepId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }