예제 #1
0
        public UploadTagAttachmentCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => BeAnExistingTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag doesn't exist! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync((command, token) => NotHaveAttachmentWithFilenameAsync(command.TagId, command.FileName, token))
            .WithMessage(command => $"Tag already has an attachment with filename {command.FileName}! Please rename file or choose to overwrite")
            .When(c => !c.OverwriteIfExists, ApplyConditionTo.CurrentValidator);

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);
            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);
            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);
            async Task <bool> NotHaveAttachmentWithFilenameAsync(int tagId, string fileName, CancellationToken token)
            => !await tagValidator.AttachmentWithFilenameExistsAsync(tagId, fileName, token);
        }
        public DuplicateAreaTagCommandValidator(ITagValidator tagValidator, IProjectValidator projectValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project is closed! Tag={command.TagId}")
            .MustAsync((command, token) => BeAnExistingSourceTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag doesn't exist! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAnExistingTagWithinProjectAsync(command.GetTagNo(), command.TagId, token))
            .WithMessage(command => $"Tag already exists in scope for project! Tag={command.GetTagNo()}")
            .MustAsync((command, token) => IsReadyToBeDuplicatedAsync(command.TagId, token))
            .WithMessage(command => $"Tag can not be duplicated! Tag={command.TagId}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);

            async Task <bool> BeAnExistingSourceTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAnExistingTagWithinProjectAsync(string tagNo, int tagId, CancellationToken token)
            => !await tagValidator.ExistsAsync(tagNo, tagId, token);

            async Task <bool> IsReadyToBeDuplicatedAsync(int tagId, CancellationToken token)
            => await tagValidator.IsReadyToBeDuplicatedAsync(tagId, token);
        }
        public PreserveCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => BeAnExistingTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag doesn't exist! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTag(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync((command, token) => PreservationIsStartedAsync(command.TagId, token))
            .WithMessage(command => $"Tag must have status {PreservationStatus.Active} to preserve! Tag={command.TagId}")
            .MustAsync((command, token) => BeReadyToBePreservedAsync(command.TagId, token))
            .WithMessage(command => $"Tag is not ready to be preserved! Tag={command.TagId}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);

            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAVoidedTag(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> PreservationIsStartedAsync(int tagId, CancellationToken token)
            => await tagValidator.VerifyPreservationStatusAsync(tagId, PreservationStatus.Active, token);

            async Task <bool> BeReadyToBePreservedAsync(int tagId, CancellationToken token)
            => await tagValidator.IsReadyToBePreservedAsync(tagId, token);
        }
        public ProjectManager(IProjectValidator projectValidator, IProjectUpgrader projectUpgrader, IProjectRefresherSelector projectRefresherSelector,
                              IProjectSerializerSelector projectSerializerSelector, IProjectInitializer projectInitializer, IProjectManagementConfigurationService projectManagementConfigurationService,
                              IProjectManagementInitializationService projectManagementInitializationService, IProjectStateService projectStateService)
        {
            Argument.IsNotNull(() => projectValidator);
            Argument.IsNotNull(() => projectUpgrader);
            Argument.IsNotNull(() => projectRefresherSelector);
            Argument.IsNotNull(() => projectSerializerSelector);
            Argument.IsNotNull(() => projectInitializer);
            Argument.IsNotNull(() => projectManagementConfigurationService);
            Argument.IsNotNull(() => projectManagementInitializationService);
            Argument.IsNotNull(() => projectStateService);

            _projectValidator          = projectValidator;
            _projectUpgrader           = projectUpgrader;
            _projectRefresherSelector  = projectRefresherSelector;
            _projectSerializerSelector = projectSerializerSelector;
            _projectInitializer        = projectInitializer;
            _projectManagementInitializationService = projectManagementInitializationService;
            _projectStateSetter = (IProjectStateSetter)projectStateService;

            _projects          = new ListDictionary <string, IProject>();
            _projectRefreshers = new ConcurrentDictionary <string, IProjectRefresher>();

            ProjectManagementType = projectManagementConfigurationService.GetProjectManagementType();
        }
        public UpdateActionCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IActionValidator actionValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync(BeAnExistingActionAsync)
            .WithMessage(command => "Tag and/or action doesn't exist!")
            .MustAsync((command, token) => NotBeAClosedActionAsync(command.ActionId, token))
            .WithMessage(command => $"Action is closed! Action={command.ActionId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);
            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);
            async Task <bool> BeAnExistingActionAsync(UpdateActionCommand command, CancellationToken token)
            => await tagValidator.ExistsActionAsync(command.TagId, command.ActionId, token);
            async Task <bool> NotBeAClosedActionAsync(int actionId, CancellationToken token)
            => !await actionValidator.IsClosedAsync(actionId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
        public void CreateProjectCommandTest_SetUp()
        {
            _dbContext        = Substitute.For <IDbContext>();
            _projectValidator = Substitute.For <IProjectValidator>();

            _createProjectCommand = new CreateProjectCommand(_dbContext, _projectValidator);
        }
예제 #7
0
        public RescheduleCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command.Tags)
            .Must(ids => ids != null && ids.Any())
            .WithMessage("At least 1 tag must be given!")
            .Must(BeUniqueTags)
            .WithMessage("Tags must be unique!")
            .MustAsync(BeInSameProjectAsync)
            .WithMessage("Tags must be in same project!")
            .MustAsync(NotBeAClosedProjectForTagAsync)
            .WithMessage("Project is closed!");

            RuleFor(command => command.Weeks)
            .InclusiveBetween(1, MaxRescheduleWeeks)
            .WithMessage($"Rescheduling must be in range of 1 to {MaxRescheduleWeeks} week(s)!");

            When(command => command.Tags.Any() && BeUniqueTags(command.Tags), () =>
            {
                RuleForEach(command => command.Tags)
                .MustAsync((_, tag, __, token) => BeAnExistingTagAsync(tag.Id, token))
                .WithMessage((_, tag) => $"Tag doesn't exist! Tag={tag.Id}")
                .MustAsync((_, tag, __, token) => NotBeAVoidedTagAsync(tag.Id, token))
                .WithMessage((_, tag) => $"Tag is voided! Tag={tag.Id}")
                .MustAsync((_, tag, __, token) => IsReadyToBeRescheduledAsync(tag.Id, token))
                .WithMessage((_, tag) => $"Tag can not be rescheduled! Tag={tag.Id}")
                .Must(tag => HaveAValidRowVersion(tag.RowVersion))
                .WithMessage((_, tag) => $"Not a valid row version! Row version={tag.RowVersion}");
            });

            bool BeUniqueTags(IEnumerable <IdAndRowVersion> tags)
            {
                var ids = tags.Select(x => x.Id).ToList();

                return(ids.Distinct().Count() == ids.Count);
            }

            async Task <bool> BeInSameProjectAsync(IEnumerable <IdAndRowVersion> tags, CancellationToken token)
            => await projectValidator.AllTagsInSameProjectAsync(tags.Select(t => t.Id), token);

            async Task <bool> NotBeAClosedProjectForTagAsync(IEnumerable <IdAndRowVersion> tags, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tags.First().Id, token);

            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> IsReadyToBeRescheduledAsync(int tagId, CancellationToken token)
            => await tagValidator.IsReadyToBeRescheduledAsync(tagId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
예제 #8
0
 public ProjectEditorPresenter(Hierarchy hierarchy, ProjectContext context, IProjectController controller, IProjectValidator validator, IProjectScreen screen)
 {
     _hierarchy  = hierarchy;
     _context    = context;
     _controller = controller;
     _validator  = validator;
     _screen     = screen;
 }
예제 #9
0
        public BulkPreserveCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command.TagIds)
            .Must(ids => ids != null && ids.Any())
            .WithMessage("At least 1 tag must be given!")
            .Must(BeUniqueTags)
            .WithMessage("Tags must be unique!")
            .MustAsync(BeInSameProjectAsync)
            .WithMessage("Tags must be in same project!")
            .MustAsync(NotBeAClosedProjectForTagAsync)
            .WithMessage("Project is closed!");

            When(command => command.TagIds.Any() && BeUniqueTags(command.TagIds), () =>
            {
                RuleForEach(command => command.TagIds)
                .MustAsync((_, tagId, __, token) => BeAnExistingTagAsync(tagId, token))
                .WithMessage((_, id) => $"Tag doesn't exist! Tag={id}")
                .MustAsync((_, tagId, __, token) => NotBeAVoidedTagAsync(tagId, token))
                .WithMessage((_, id) => $"Tag is voided! Tag={id}")
                .MustAsync((_, tagId, __, token) => PreservationIsStartedAsync(tagId, token))
                .WithMessage((_, id) => $"Tag must have status {PreservationStatus.Active} to preserve! Tag={id}")
                .MustAsync((_, tagId, __, token) => BeReadyToBePreservedAsync(tagId, token))
                .WithMessage((_, id) => $"Tag is not ready to be bulk preserved! Tag={id}");
            });

            bool BeUniqueTags(IEnumerable <int> tagIds)
            {
                var ids = tagIds.ToList();

                return(ids.Distinct().Count() == ids.Count);
            }

            async Task <bool> BeInSameProjectAsync(IEnumerable <int> tagIds, CancellationToken token)
            => await projectValidator.AllTagsInSameProjectAsync(tagIds, token);

            async Task <bool> NotBeAClosedProjectForTagAsync(IEnumerable <int> tagIds, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagIds.First(), token);

            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> PreservationIsStartedAsync(int tagId, CancellationToken token)
            => await tagValidator.VerifyPreservationStatusAsync(tagId, PreservationStatus.Active, token);

            async Task <bool> BeReadyToBePreservedAsync(int tagId, CancellationToken token)
            => await tagValidator.IsReadyToBePreservedAsync(tagId, token);
        }
        public StartPreservationCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command.TagIds)
            .Must(ids => ids != null && ids.Any())
            .WithMessage("At least 1 tag must be given!")
            .Must(BeUniqueTags)
            .WithMessage("Tags must be unique!")
            .MustAsync(BeInSameProjectAsync)
            .WithMessage("Tags must be in same project!")
            .MustAsync(NotBeAClosedProjectForTagAsync)
            .WithMessage("Project is closed!");

            When(command => command.TagIds.Any() && BeUniqueTags(command.TagIds), () =>
            {
                RuleForEach(command => command.TagIds)
                .MustAsync((_, tagId, __, token) => BeAnExistingTagAsync(tagId, token))
                .WithMessage((_, id) => $"Tag doesn't exist! Tag={id}")
                .MustAsync((_, tagId, __, token) => NotBeAVoidedTagAsync(tagId, token))
                .WithMessage((_, id) => $"Tag is voided! Tag={id}")
                .MustAsync((_, tagId, __, token) => IsReadyToBeStartedAsync(tagId, token))
                .WithMessage((_, id) => $"Preservation on tag can not be started! Tag={id}")
                .MustAsync((_, tagId, __, token) => HaveAtLeastOneNonVoidedRequirementAsync(tagId, token))
                .WithMessage((_, id) => $"Tag do not have any non voided requirement! Tag={id}");
            });

            bool BeUniqueTags(IEnumerable <int> tagIds)
            {
                var ids = tagIds.ToList();

                return(ids.Distinct().Count() == ids.Count);
            }

            async Task <bool> BeInSameProjectAsync(IEnumerable <int> tagIds, CancellationToken token)
            => await projectValidator.AllTagsInSameProjectAsync(tagIds, token);

            async Task <bool> NotBeAClosedProjectForTagAsync(IEnumerable <int> tagIds, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagIds.First(), token);

            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> IsReadyToBeStartedAsync(int tagId, CancellationToken token)
            => await tagValidator.IsReadyToBeStartedAsync(tagId, token);

            async Task <bool> HaveAtLeastOneNonVoidedRequirementAsync(int tagId, CancellationToken token)
            => await tagValidator.HasANonVoidedRequirementAsync(tagId, token);
        }
예제 #11
0
        public ProjectModule(IDbContext dbContext, IProjectValidator projectValidator
                             , ICreateProjectCommand createProjectCommand, IDeleteProjectCommand deleteProjectCommand
                             , IProjectRepository projectRepo, ILogFileRepository logFileRepo, IRequestRepository requestRepo
                             , IProjectRequestAggregateRepository projectRequestAggregateRepo)
        {
            _dbContext                   = dbContext;
            _projectValidator            = projectValidator;
            _createProjectCommand        = createProjectCommand;
            _deleteProjectCommand        = deleteProjectCommand;
            _projectRepo                 = projectRepo;
            _logFileRepo                 = logFileRepo;
            _requestRepo                 = requestRepo;
            _projectRequestAggregateRepo = projectRequestAggregateRepo;

            Post[Actions.Project.Aggregates()] = x =>
            {
                return(Aggregates(x.projectId));
            };
            Post[Actions.Project.Files()] = x =>
            {
                return(Files(x.projectId));
            };

            Post[Actions.Project.AvgLoadTimes()] = x =>
            {
                return(AvgLoadTimes(x.projectId));
            };

            Post[Actions.Project.Delete()] = x =>
            {
                this.RequiresClaims(new[] { Claims.ProjectEdit });
                return(DeleteProject(x.projectId));
            };

            Get[Actions.Project.RequestsByAggregate()] = x =>
            {
                return(RequestsByAggregate(x.projectId));
            };
            Post[Actions.Project.RequestsByAggregateDetail()] = x =>
            {
                return(RequestsByAggregateDetail(x.projectId));
            };

            Get[Actions.Project.View()] = x =>
            {
                return(ProjectView(x.projectId));
            };

            Post[Actions.Project.Save] = x =>
            {
                this.RequiresClaims(new[] { Claims.ProjectEdit });
                return(ProjectSave());
            };
        }
예제 #12
0
        public NewProjectPresenter(IProjectController controller, IScreenConductor conductor, IProjectValidator validator,
                                   IProjectScreen view)
        {
            _controller = controller;
            _conductor  = conductor;
            _validator  = validator;
            _view       = view;
            _project    = new Project();

            _view.BindTo(_project);

            _save   = new ActionCommand(save);
            _cancel = new ActionCommand(cancel);
        }
예제 #13
0
        public NewProjectPresenter(IProjectController controller, IScreenConductor conductor, IProjectValidator validator,
            IProjectScreen view)
        {
            _controller = controller;
            _conductor = conductor;
            _validator = validator;
            _view = view;
            _project = new Project();

            _view.BindTo(_project);

            _save = new ActionCommand(save);
            _cancel = new ActionCommand(cancel);
        }
예제 #14
0
 public ProjectService(
     IRegistryService registryService,
     ITemplateService templateService,
     IFileUtil fileUtil,
     IGitService gitService,
     ICompilerFactory compilerFactory,
     IProjectValidator projectValidator
     )
 {
     _registryService  = registryService;
     _templateService  = templateService;
     _fileUtil         = fileUtil;
     _gitService       = gitService;
     _compilerFactory  = compilerFactory;
     _projectValidator = projectValidator;
 }
예제 #15
0
        public void ProjectModuleTest_SetUp()
        {
            _dbContext                   = Substitute.For <IDbContext>();
            _createProjectCommand        = Substitute.For <ICreateProjectCommand>();
            _deleteProjectCommand        = Substitute.For <IDeleteProjectCommand>();
            _projectValidator            = Substitute.For <IProjectValidator>();
            _projectRepo                 = Substitute.For <IProjectRepository>();
            _logFileRepo                 = Substitute.For <ILogFileRepository>();
            _requestRepo                 = Substitute.For <IRequestRepository>();
            _projectRequestAggregateRepo = Substitute.For <IProjectRequestAggregateRepository>();

            Mapper.Initialize((cfg) =>
            {
                cfg.CreateMap <ProjectFormViewModel, ProjectModel>();
            });
        }
        public UploadFieldValueAttachmentCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IFieldValidator fieldValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync(BeAnExistingRequirementAsync)
            .WithMessage(command => "Tag and/or requirement doesn't exist!")
            .MustAsync(BeAnExistingFieldForRequirementAsync)
            .WithMessage(command => "Field doesn't exist in requirement!")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync((command, token) => HasRequirementWithActivePeriodAsync(command.TagId, command.RequirementId, token))
            .WithMessage(command =>
                         $"Tag doesn't have this requirement with active period! Tag={command.TagId}. Requirement={command.RequirementId}")
            .MustAsync((command, token) => BeAFieldForAttachmentAsync(command.FieldId, token))
            .WithMessage(command => $"Field values can not be recorded for field type! Field={command.FieldId}")
            .MustAsync((command, token) => NotBeAVoidedFieldAsync(command.FieldId, token))
            .WithMessage(command => $"Field is voided! Field={command.FieldId}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);

            async Task <bool> BeAnExistingRequirementAsync(UploadFieldValueAttachmentCommand command, CancellationToken token)
            => await tagValidator.ExistsRequirementAsync(command.TagId, command.RequirementId, token);

            async Task <bool> BeAnExistingFieldForRequirementAsync(UploadFieldValueAttachmentCommand command, CancellationToken token)
            => await tagValidator.ExistsFieldForRequirementAsync(command.TagId, command.RequirementId, command.FieldId, token);

            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> HasRequirementWithActivePeriodAsync(int tagId, int requirementId, CancellationToken token)
            => await tagValidator.HasRequirementWithActivePeriodAsync(tagId, requirementId, token);

            async Task <bool> NotBeAVoidedFieldAsync(int fieldId, CancellationToken token)
            => !await fieldValidator.IsVoidedAsync(fieldId, token);

            async Task <bool> BeAFieldForAttachmentAsync(int fieldId, CancellationToken token)
            => await fieldValidator.IsValidForAttachmentAsync(fieldId, token);
        }
예제 #17
0
        public CreateSavedFilterCommandValidator(
            ISavedFilterValidator savedFilterValidator,
            IProjectValidator projectValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotExistsASavedFilterWithSameTitleForPerson(command.Title, command.ProjectName, token))
            .WithMessage(command => $"A saved filter with this title already exists! Title={command.Title}");
            RuleFor(command => command)
            .MustAsync((command, token) => BeAnExistingProject(command.ProjectName, token))
            .WithMessage(command => $"Project doesn't exist! Project={command.ProjectName}");

            async Task <bool> NotExistsASavedFilterWithSameTitleForPerson(string title, string projectName, CancellationToken token)
            => !await savedFilterValidator.ExistsWithSameTitleForPersonInProjectAsync(title, projectName, token);
            async Task <bool> BeAnExistingProject(string projectName, CancellationToken token)
            => await projectValidator.ExistsAsync(projectName, token);
        }
예제 #18
0
        public AutoScopeTagsCommandValidator(
            ITagValidator tagValidator,
            IStepValidator stepValidator,
            IProjectValidator projectValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command.TagNos)
            .Must(r => r.Any())
            .WithMessage("At least 1 tag must be given!")
            .Must(BeUniqueTagNos)
            .WithMessage("Tags must be unique!");

            RuleForEach(command => command.TagNos)
            .MustAsync((command, tagNo, _, token) => NotBeAnExistingTagWithinProjectAsync(tagNo, command.ProjectName, token))
            .WithMessage((command, tagNo) => $"Tag already exists in scope for project! Tag={tagNo}");

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAnExistingAndClosedProjectAsync(command.ProjectName, token))
            .WithMessage(command => $"Project is closed! Project={command.ProjectName}")
            .MustAsync((command, token) => BeAnExistingStepAsync(command.StepId, token))
            .WithMessage(command => $"Step doesn't exist! Step={command.StepId}")
            .MustAsync((command, token) => NotBeAVoidedStepAsync(command.StepId, token))
            .WithMessage(command => $"Step is voided! Step={command.StepId}");

            bool BeUniqueTagNos(IEnumerable <string> tagNos)
            {
                var lowerTagNos = tagNos.Select(t => t.ToLower()).ToList();

                return(lowerTagNos.Distinct().Count() == lowerTagNos.Count);
            }

            async Task <bool> NotBeAnExistingTagWithinProjectAsync(string tagNo, string projectName, CancellationToken token) =>
            !await tagValidator.ExistsAsync(tagNo, projectName, token);

            async Task <bool> NotBeAnExistingAndClosedProjectAsync(string projectName, CancellationToken token)
            => !await projectValidator.IsExistingAndClosedAsync(projectName, token);

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

            async Task <bool> NotBeAVoidedStepAsync(int stepId, CancellationToken token)
            => !await stepValidator.IsVoidedAsync(stepId, token);
        }
예제 #19
0
        public CreateActionCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => BeAnExistingTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag doesn't exist! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);
            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);
            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);
        }
 public ProjectAppService(ApiContext apiContext, IMapperProvider mapper, IProjectValidator projectValidator)
 {
     _apiContext       = apiContext;
     _mapper           = mapper;
     _projectValidator = projectValidator;
 }
        public UpdateTagStepAndRequirementsCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IStepValidator stepValidator,
            IRequirementDefinitionValidator requirementDefinitionValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            WhenAsync((command, token) => IsASupplierStepAsync(command.StepId, token), () =>
            {
                WhenAsync((command, token) => NotBeAPoAreaTagAsync(command.TagId, token), () =>
                {
                    RuleFor(command => command)
                    .MustAsync((_, command, token) =>
                               RequirementUsageIsForAllJourneysAsync(
                                   command.TagId,
                                   command.UpdatedRequirements.Where(u => !u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.UpdatedRequirements.Where(u => u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.NewRequirements.Select(r => r.RequirementDefinitionId).ToList(),
                                   token))
                    .WithMessage(_ => "Requirements must include requirements to be used both for supplier and other than suppliers!");
                }).Otherwise(() =>
                {
                    RuleFor(command => command)
                    .MustAsync((_, command, token) =>
                               RequirementUsageIsForSupplierAsync(
                                   command.TagId,
                                   command.UpdatedRequirements.Where(u => !u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.UpdatedRequirements.Where(u => u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.NewRequirements.Select(r => r.RequirementDefinitionId).ToList(),
                                   token))
                    .WithMessage(_ => "Requirements must include requirements to be used for supplier!")
                    .MustAsync((command, token) => RequirementUsageIsNotForOtherThanSupplierAsync(
                                   command.TagId,
                                   command.UpdatedRequirements.Where(u => !u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.UpdatedRequirements.Where(u => u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                                   command.NewRequirements.Select(r => r.RequirementDefinitionId).ToList(),
                                   token))
                    .WithMessage(_ => "Requirements can not include requirements for other than suppliers!");
                });
            }).Otherwise(() =>
            {
                RuleFor(command => command)
                .MustAsync((command, token) => NotBeAPoAreaTagAsync(command.TagId, token))
                .WithMessage(_ => $"Step for a {TagType.PoArea.GetTagNoPrefix()} tag needs to be for supplier!")
                .MustAsync((_, command, token) =>
                           RequirementUsageIsForJourneysWithoutSupplierAsync(
                               command.TagId,
                               command.UpdatedRequirements.Where(u => !u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                               command.UpdatedRequirements.Where(u => u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                               command.NewRequirements.Select(r => r.RequirementDefinitionId).ToList(),
                               token))
                .WithMessage(_ => "Requirements must include requirements to be used for other than suppliers!");
            });

            WhenAsync((command, token) => IsAnAreaTagAsync(command.TagId, token), () =>
            {
                RuleFor(command => command)
                .Must(command => !string.IsNullOrEmpty(command.Description))
                .WithMessage(_ => "Description can not be blank!");
            }).Otherwise(() =>
            {
                RuleFor(command => command)
                .MustAsync((command, token)
                           => NotChangeDescriptionAsync(command.TagId, command.Description, token))
                .WithMessage(_ => "Tag must be an area tag to update description!");
            });

            RuleFor(command => command)
            .MustAsync((_, command, token) =>
                       RequirementsMustBeUniqueAfterUpdateAsync(
                           command.TagId,
                           command.NewRequirements.Select(r => r.RequirementDefinitionId).ToList(),
                           token))
            .WithMessage(_ => "Requirements must be unique!")
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => BeAnExistingTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag doesn't exist! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync((command, token) => NotChangedToAVoidedStepAsync(command.TagId, command.StepId, token))
            .WithMessage(command => $"Step is voided! Step={command.StepId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            RuleForEach(command => command.UpdatedRequirements)
            .MustAsync((command, req, _, token) => BeAnExistingTagRequirementAsync(command.TagId, req.TagRequirementId, token))
            .WithMessage((_, req) => $"Requirement doesn't exist! Requirement={req.TagRequirementId}");

            RuleForEach(command => command.DeletedRequirements)
            .MustAsync((command, req, _, token) => BeAnExistingTagRequirementAsync(command.TagId, req.TagRequirementId, token))
            .WithMessage((_, req) => $"Requirement doesn't exist! Requirement={req.TagRequirementId}")
            .MustAsync((command, req, _, token) => BeAVoidedTagRequirementAsync(
                           command.TagId,
                           req.TagRequirementId,
                           command.UpdatedRequirements.Where(u => u.IsVoided).Select(u => u.TagRequirementId).ToList(),
                           token))
            .WithMessage((_, req) => $"Requirement is not voided! Requirement={req.TagRequirementId}");

            RuleForEach(command => command.NewRequirements)
            .MustAsync((_, req, _, token) => BeAnExistingRequirementDefinitionAsync(req.RequirementDefinitionId, token))
            .WithMessage((_, req) =>
                         $"Requirement definition doesn't exist! Requirement definition={req.RequirementDefinitionId}")
            .MustAsync((_, req, _, token) => NotBeAVoidedRequirementDefinitionAsync(req.RequirementDefinitionId, token))
            .WithMessage((_, req) =>
                         $"Requirement definition is voided! Requirement definition={req.RequirementDefinitionId}");

            async Task <bool> RequirementsMustBeUniqueAfterUpdateAsync(
                int tagId,
                List <int> requirementDefinitionIdsToBeAdded,
                CancellationToken token)
            => requirementDefinitionIdsToBeAdded.Count == 0 ||
            await tagValidator.AllRequirementsWillBeUniqueAsync(tagId, requirementDefinitionIdsToBeAdded, token);

            async Task <bool> RequirementUsageIsNotForOtherThanSupplierAsync(
                int tagId,
                List <int> tagRequirementIdsToBeUnvoided,
                List <int> tagRequirementIdsToBeVoided,
                List <int> requirementDefinitionIdsToBeAdded,
                CancellationToken token)
            => !await tagValidator.RequirementHasAnyForOtherThanSuppliersUsageAsync(
                tagId,
                tagRequirementIdsToBeUnvoided,
                tagRequirementIdsToBeVoided,
                requirementDefinitionIdsToBeAdded,
                token);

            async Task <bool> RequirementUsageIsForSupplierAsync(
                int tagId,
                List <int> tagRequirementIdsToBeUnvoided,
                List <int> tagRequirementIdsToBeVoided,
                List <int> requirementDefinitionIdsToBeAdded,
                CancellationToken token)
            => await tagValidator.RequirementUsageWillCoverForSuppliersAsync(
                tagId,
                tagRequirementIdsToBeUnvoided,
                tagRequirementIdsToBeVoided,
                requirementDefinitionIdsToBeAdded,
                token);

            async Task <bool> RequirementUsageIsForAllJourneysAsync(
                int tagId,
                List <int> tagRequirementIdsToBeUnvoided,
                List <int> tagRequirementIdsToBeVoided,
                List <int> requirementDefinitionIdsToBeAdded,
                CancellationToken token)
            => await tagValidator.RequirementUsageWillCoverBothForSupplierAndOtherAsync(
                tagId,
                tagRequirementIdsToBeUnvoided,
                tagRequirementIdsToBeVoided,
                requirementDefinitionIdsToBeAdded,
                token);

            async Task <bool> RequirementUsageIsForJourneysWithoutSupplierAsync(
                int tagId,
                List <int> tagRequirementIdsToBeUnvoided,
                List <int> tagRequirementIdsToBeVoided,
                List <int> requirementDefinitionIdsToBeAdded,
                CancellationToken token)
            => await tagValidator.RequirementUsageWillCoverForOtherThanSuppliersAsync(
                tagId,
                tagRequirementIdsToBeUnvoided,
                tagRequirementIdsToBeVoided,
                requirementDefinitionIdsToBeAdded,
                token);

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

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);

            async Task <bool> IsAnAreaTagAsync(int tagId, CancellationToken token)
            => await tagValidator.VerifyTagIsAreaTagAsync(tagId, token);

            async Task <bool> BeAnExistingTagAsync(int tagId, CancellationToken token)
            => await tagValidator.ExistsAsync(tagId, token);

            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);

            async Task <bool> NotBeAPoAreaTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.VerifyTagTypeAsync(tagId, TagType.PoArea, token);

            async Task <bool> NotChangedToAVoidedStepAsync(int tagId, int stepId, CancellationToken token)
            => await tagValidator.HasStepAsync(tagId, stepId, token) ||
            !await stepValidator.IsVoidedAsync(stepId, token);

            async Task <bool> BeAnExistingRequirementDefinitionAsync(int requirementDefinitionId, CancellationToken token)
            => await requirementDefinitionValidator.ExistsAsync(requirementDefinitionId, token);

            async Task <bool> NotBeAVoidedRequirementDefinitionAsync(int requirementDefinitionId, CancellationToken token)
            => !await requirementDefinitionValidator.IsVoidedAsync(requirementDefinitionId, token);

            async Task <bool> BeAnExistingTagRequirementAsync(int tagId, int tagRequirementId, CancellationToken token)
            => await tagValidator.HasRequirementAsync(tagId, tagRequirementId, token);

            async Task <bool> BeAVoidedTagRequirementAsync(
                int tagId,
                int tagRequirementId,
                List <int> tagRequirementIdsToBeVoided,
                CancellationToken token)
            {
                if (tagRequirementIdsToBeVoided.Contains(tagRequirementId))
                {
                    return(true);
                }

                return(await tagValidator.IsRequirementVoidedAsync(tagId, tagRequirementId, token));
            }

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

            async Task <bool> NotChangeDescriptionAsync(int tagId, string description, CancellationToken token)
            => description == null || await tagValidator.VerifyTagDescriptionAsync(tagId, description, token);
        }
예제 #22
0
 public void ProjectValidatorTest_SetUp()
 {
     _projectValidator = new ProjectValidator();
 }
 public CreateProjectCommand(IDbContext dbContext, IProjectValidator projectValidator)
 {
     _dbContext        = dbContext;
     _projectValidator = projectValidator;
 }
예제 #24
0
 public ProjectService(IProjectRepository repository, IProjectValidator validator)
 {
     _repository = repository;
     _validator  = validator;
 }
예제 #25
0
        public CreateAreaTagCommandValidator(
            ITagValidator tagValidator,
            IStepValidator stepValidator,
            IProjectValidator projectValidator,
            IRequirementDefinitionValidator requirementDefinitionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            WhenAsync((command, token) => BeASupplierStepAsync(command.StepId, token), () =>
            {
                RuleFor(command => command)
                .MustAsync((command, token) => RequirementUsageIsForAllJourneysAsync(command.Requirements, token))
                .WithMessage(_ => "Requirements must include requirements to be used both for supplier and other than suppliers!")
                .When(command => command.TagType != TagType.PoArea, ApplyConditionTo.CurrentValidator)
                .MustAsync((command, token) => RequirementUsageIsForSupplierAsync(command.Requirements, token))
                .WithMessage(_ => "Requirements must include requirements to be used for supplier!")
                .When(command => command.TagType == TagType.PoArea, ApplyConditionTo.CurrentValidator)
                .MustAsync((command, token) => RequirementUsageIsNotForOtherThanSupplierAsync(command.Requirements, token))
                .WithMessage(_ => "Requirements can not include requirements for other than suppliers!")
                .When(command => command.TagType == TagType.PoArea, ApplyConditionTo.CurrentValidator);
            }).Otherwise(() =>
            {
                RuleFor(command => command)
                .Must(command => command.TagType != TagType.PoArea)
                .WithMessage(_ => $"Step for a {TagType.PoArea.GetTagNoPrefix()} tag needs to be for supplier!")
                .MustAsync((command, token) => RequirementUsageIsForJourneysWithoutSupplierAsync(command.Requirements, token))
                .WithMessage(_ => "Requirements must include requirements to be used for other than suppliers!")
                .MustAsync((command, token) => RequirementUsageIsNotForSupplierOnlyAsync(command.Requirements, token))
                .WithMessage(_ => "Requirements can not include requirements just for suppliers!");
            });

            RuleFor(command => command)
            .Must(command => BeUniqueRequirements(command.Requirements))
            .WithMessage(_ => "Requirement definitions must be unique!")
            .MustAsync((command, token) => NotBeAnExistingAndClosedProjectAsync(command.ProjectName, token))
            .WithMessage(command => $"Project is closed! Project={command.ProjectName}")
            .MustAsync((command, token) => NotBeAnExistingTagWithinProjectAsync(command.GetTagNo(), command.ProjectName, token))
            .WithMessage(command => $"Tag already exists in scope for project! Tag={command.GetTagNo()}")
            .MustAsync((command, token) => BeAnExistingStepAsync(command.StepId, token))
            .WithMessage(command => $"Step doesn't exist! Step={command.StepId}")
            .MustAsync((command, token) => NotBeAVoidedStepAsync(command.StepId, token))
            .WithMessage(command => $"Step is voided! Step={command.StepId}");

            RuleForEach(command => command.Requirements)
            .MustAsync((_, req, _, token) => BeAnExistingRequirementDefinitionAsync(req, token))
            .WithMessage((_, req) => $"Requirement definition doesn't exist! Requirement definition={req.RequirementDefinitionId}")
            .MustAsync((_, req, _, token) => NotBeAVoidedRequirementDefinitionAsync(req, token))
            .WithMessage((_, req) => $"Requirement definition is voided! Requirement definition={req.RequirementDefinitionId}");

            bool BeUniqueRequirements(IEnumerable <RequirementForCommand> requirements)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(reqIds.Distinct().Count() == reqIds.Count);
            }

            async Task <bool> RequirementUsageIsForAllJourneysAsync(IEnumerable <RequirementForCommand> requirements, CancellationToken token)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(await requirementDefinitionValidator.UsageCoversBothForSupplierAndOtherAsync(reqIds, token));
            }

            async Task <bool> RequirementUsageIsForSupplierAsync(IEnumerable <RequirementForCommand> requirements, CancellationToken token)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(await requirementDefinitionValidator.UsageCoversForSuppliersAsync(reqIds, token));
            }

            async Task <bool> RequirementUsageIsForJourneysWithoutSupplierAsync(IEnumerable <RequirementForCommand> requirements, CancellationToken token)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(await requirementDefinitionValidator.UsageCoversForOtherThanSuppliersAsync(reqIds, token));
            }

            async Task <bool> RequirementUsageIsNotForOtherThanSupplierAsync(IEnumerable <RequirementForCommand> requirements, CancellationToken token)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(!await requirementDefinitionValidator.HasAnyForForOtherThanSuppliersUsageAsync(reqIds, token));
            }

            async Task <bool> RequirementUsageIsNotForSupplierOnlyAsync(IEnumerable <RequirementForCommand> requirements, CancellationToken token)
            {
                var reqIds = requirements.Select(dto => dto.RequirementDefinitionId).ToList();

                return(!await requirementDefinitionValidator.HasAnyForSupplierOnlyUsageAsync(reqIds, token));
            }

            async Task <bool> NotBeAnExistingAndClosedProjectAsync(string projectName, CancellationToken token)
            => !await projectValidator.IsExistingAndClosedAsync(projectName, token);

            async Task <bool> NotBeAnExistingTagWithinProjectAsync(string tagNo, string projectName, CancellationToken token)
            => !await tagValidator.ExistsAsync(tagNo, projectName, token);

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

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

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

            async Task <bool> BeAnExistingRequirementDefinitionAsync(RequirementForCommand requirement, CancellationToken token)
            => await requirementDefinitionValidator.ExistsAsync(requirement.RequirementDefinitionId, token);

            async Task <bool> NotBeAVoidedRequirementDefinitionAsync(RequirementForCommand requirement, CancellationToken token)
            => !await requirementDefinitionValidator.IsVoidedAsync(requirement.RequirementDefinitionId, token);
        }