/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Mvc/Mvc.DataAnnotations/test/ValidationAttributeAdapterProviderTest.cs
98 строк
3 KB
Shreyas Jejurkar
chore : Remove unwanted `using` statement (#39176)
02 янв 2022, 17:39
Не верифицирован
02 янв 2022, 17:39
c85baf8
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel.DataAnnotations; namespace Microsoft.AspNetCore.Mvc.DataAnnotations; public class ValidationAttributeAdapterProviderTest { private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider = new ValidationAttributeAdapterProvider(); public static TheoryData<ValidationAttribute, Type> DataAnnotationAdapters { get { return new TheoryData<ValidationAttribute, Type> { { new RegularExpressionAttribute("abc"), typeof(RegularExpressionAttributeAdapter) }, { new MaxLengthAttribute(), typeof(MaxLengthAttributeAdapter) }, { new MinLengthAttribute(1), typeof(MinLengthAttributeAdapter) }, { new RangeAttribute(1, 100), typeof(RangeAttributeAdapter) }, { new StringLengthAttribute(6), typeof(StringLengthAttributeAdapter) }, { new RequiredAttribute(), typeof(RequiredAttributeAdapter) }, { new CustomRegularExpressionAttribute("abc"), typeof(RegularExpressionAttributeAdapter) } }; } } [Theory] [MemberData(nameof(DataAnnotationAdapters))] public void AdapterFactory_RegistersAdapters_ForDataAnnotationAttributes( ValidationAttribute attribute, Type expectedAdapterType) { // Arrange and Act var adapter = _validationAttributeAdapterProvider.GetAttributeAdapter(attribute, stringLocalizer: null); // Assert Assert.IsType(expectedAdapterType, adapter); } public static TheoryData<ValidationAttribute, string> DataTypeAdapters { get { return new TheoryData<ValidationAttribute, string> { { new UrlAttribute(), "data-val-url" }, { new CreditCardAttribute(), "data-val-creditcard" }, { new EmailAddressAttribute(), "data-val-email" }, { new PhoneAttribute(), "data-val-phone" } }; } } [Theory] [MemberData(nameof(DataTypeAdapters))] public void AdapterFactory_RegistersAdapters_ForDataTypeAttributes( ValidationAttribute attribute, string expectedRuleName) { // Arrange & Act var adapter = _validationAttributeAdapterProvider.GetAttributeAdapter(attribute, stringLocalizer: null); // Assert var dataTypeAdapter = Assert.IsType<DataTypeAttributeAdapter>(adapter); Assert.Equal(expectedRuleName, dataTypeAdapter.RuleName); } class CustomRegularExpressionAttribute : RegularExpressionAttribute { public CustomRegularExpressionAttribute(string pattern) : base(pattern) { ErrorMessage = "Not valid."; } } }