38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
using Microsoft.AspNet.Testing;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|
{
|
|
public class RequiredAttributeAdapterTest
|
|
{
|
|
[Fact]
|
|
[ReplaceCulture]
|
|
public void GetClientValidationRules_ReturnsValidationParameters()
|
|
{
|
|
// Arrange
|
|
var expected = ValidationAttributeUtil.GetRequiredErrorMessage("Length");
|
|
var provider = TestModelMetadataProvider.CreateDefaultProvider();
|
|
var metadata = provider.GetMetadataForProperty(typeof(string), "Length");
|
|
|
|
var attribute = new RequiredAttribute();
|
|
var adapter = new RequiredAttributeAdapter(attribute, stringLocalizer: null);
|
|
|
|
var actionContext = new ActionContext();
|
|
var context = new ClientModelValidationContext(actionContext, metadata, provider);
|
|
|
|
// Act
|
|
var rules = adapter.GetClientValidationRules(context);
|
|
|
|
// Assert
|
|
var rule = Assert.Single(rules);
|
|
Assert.Equal("required", rule.ValidationType);
|
|
Assert.Empty(rule.ValidationParameters);
|
|
Assert.Equal(expected, rule.ErrorMessage);
|
|
}
|
|
}
|
|
}
|