public PostDataAccess(IPostRepo postRepo, IPostValidator postValidator, IAuthorRepo authorRepo, IAuthorValidator authorValidator) { _postRepo = postRepo; _postValidator = postValidator; _authorRepo = authorRepo; _authorValidator = authorValidator; }
public AddAuthorCommandHandler(HandlerContext <AuthorViewModel> context, IUserService userService, IAuthorValidator authorValidator) { _dbContext = context.DbContext; _context = context; _userService = userService; _authorValidator = authorValidator; }
public AddBlogPostCommandValidator(IUserService userService, IAuthorValidator authorValidator, AppDbContext dbContext) { RuleFor(b => b.Subject).NotEmpty().MaximumLength(100); RuleFor(b => b.ContentIntro).NotEmpty().MaximumLength(120); RuleFor(b => b.Content).NotEmpty().MaximumLength(50000); RuleFor(b => b.Tags).Custom((tags, context) => { if (tags == null) { return; } var invalidTags = tags.Where(tag => string.IsNullOrWhiteSpace(tag)); foreach (var _ in invalidTags) { context.AddFailure(nameof(tags), "Empty tag not allowed."); } }); RuleFor(b => b.CategoryId).NotEmpty().CustomAsync(async(categoryId, context, cancellationToken) => { if (!await dbContext.Categories.AnyAsync(c => c.Id == categoryId)) { context.AddFailure("Category doesn't exit."); } }); RuleFor(b => b).CustomAsync(async(command, context, cancellationToken) => { if (!await authorValidator.Exists(userService)) { context.AddFailure("No author registered."); } }); }
public CreateBookRequestValidator(IAuthorValidator authorValidator) { RuleFor(q => q.AuthorId) .NotEmpty() .NotNull() .Must(q => authorValidator.AuthorExists(q)) .WithMessage(SharedValidationMessages.AuthorNotFound); RuleFor(q => q.Title) .NotNull() .NotEmpty() .MaximumLength(100); RuleFor(q => q.Pages) .NotNull() .InclusiveBetween(1, 99_999); RuleFor(q => q.MaxLoanDays.Value) .InclusiveBetween(1, 365) .When(q => q.MaxLoanDays.HasValue); RuleForEach(q => q.BookTags) .Length(1, 300); }
public static async Task <Author> Create(User user, AuthorProfile authorProfile, IAuthorValidator authorValidator) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (authorProfile == null) { throw new ArgumentNullException(nameof(authorProfile)); } if (authorValidator == null) { throw new ArgumentNullException(nameof(authorValidator)); } if (await authorValidator.Exists(user)) { throw new InvalidOperationException("Only one author can be created per user."); } return(new Author(user, authorProfile)); }
public AuthorValidatorTests() { _mockAuthorRepo = new MockAuthorRepo(); _authorValidator = new AuthorValidator(_mockAuthorRepo); }
public AuthorService(IMapper map, IAuthorValidator validator, IAuthorRepository repo) { mapper = map; authorValidator = validator; repository = repo; }
public AuthorLogic(IAuthorDAO authorDao, IAuthorValidator authorValidator, ILogger logger) { this.logger = logger; this.authorDAO = authorDao; this.authorValidator = authorValidator; }