コード例 #1
0
 public TemplateDetailsValidator()
 {
     RuleFor(x => x.Language).Custom((value, action) =>
     {
         if (!LanguageValidator.IsValid(value))
         {
             action.AddFailure($"{value} is not a valid language");
         }
     });
 }
コード例 #2
0
 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");
         }
     });
 }
コード例 #3
0
 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.");
 }
コード例 #4
0
 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");
         }
     });
 }
コード例 #5
0
 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");
         }
     })
          );
 }
コード例 #6
0
        public void IsValid_VariousLanguageCodes_ReturnsBool(string languageCode, bool expectedResult)
        {
            var result = LanguageValidator.IsValid(languageCode);

            result.ShouldBe(expectedResult);
        }