public TemplateDetailsValidator() { RuleFor(x => x.Language).Custom((value, action) => { if (!LanguageValidator.IsValid(value)) { action.AddFailure($"{value} is not a valid language"); } }); }
public TemplateDeleteValidator() { RuleFor(x => x.Name).NotEmpty().WithMessage("Template name shoud not be empty."); RuleFor(x => x.Language).Custom((value, action) => { if (!LanguageValidator.IsValid(value)) { action.AddFailure($"{value} is not a valid language"); } }); }
public TemplateRenderValidator() { RuleFor(x => x.Template).NotEmpty().WithMessage("Template name shoud not be empty."); RuleFor(x => x.Language).Custom((value, action) => { if (!LanguageValidator.IsValid(value)) { action.AddFailure($"{value} is not a valid language"); } }); RuleFor(x => x.Model).NotNull().WithMessage("Model should not be null."); }
public TemplateCreateValidator() { RuleFor(x => x.Name).NotEmpty().WithMessage("Template name shoud not be empty."); RuleFor(x => x.Template).Custom((value, action) => { if (value == null || !Path.GetExtension(value.FileName).Equals(".cshtml", StringComparison.InvariantCultureIgnoreCase)) { action.AddFailure("Only cshtml files are allowed."); } }); RuleFor(x => x.Language).Custom((value, action) => { if (!LanguageValidator.IsValid(value)) { action.AddFailure($"{value} is not a valid language"); } }); }
public PaginatedListValidator() { RuleFor(x => x.Language).Custom((value, action) => { if (!LanguageValidator.IsValid(value)) { action.AddFailure($"{value} is not a valid language"); } }); When(x => !String.IsNullOrWhiteSpace(x.ContinuationToken), () => RuleFor(x => x.ContinuationToken).Custom((value, action) => { Span <byte> bytes = Encoding.UTF8.GetBytes(value); if (!Convert.TryFromBase64String(value, bytes, out int bytesWritten)) { action.AddFailure($"{value} is not a valid Base64 value"); } }) ); }
public void IsValid_VariousLanguageCodes_ReturnsBool(string languageCode, bool expectedResult) { var result = LanguageValidator.IsValid(languageCode); result.ShouldBe(expectedResult); }