36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. 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
|
|
{
|
|
public class RangeAttributeAdapterTest
|
|
{
|
|
[Fact]
|
|
[ReplaceCulture]
|
|
public void GetClientValidationRules_ReturnsValidationParameters()
|
|
{
|
|
// Arrange
|
|
var provider = new DataAnnotationsModelMetadataProvider();
|
|
var metadata = provider.GetMetadataForProperty(() => null, typeof(string), "Length");
|
|
var attribute = new RangeAttribute(typeof(decimal), "0", "100");
|
|
var adapter = new RangeAttributeAdapter(attribute);
|
|
var context = new ClientModelValidationContext(metadata, provider);
|
|
|
|
// Act
|
|
var rules = adapter.GetClientValidationRules(context);
|
|
|
|
// Assert
|
|
var rule = Assert.Single(rules);
|
|
Assert.Equal("range", rule.ValidationType);
|
|
Assert.Equal(2, rule.ValidationParameters.Count);
|
|
Assert.Equal(0m, rule.ValidationParameters["min"]);
|
|
Assert.Equal(100m, rule.ValidationParameters["max"]);
|
|
Assert.Equal(@"The field Length must be between 0 and 100.", rule.ErrorMessage);
|
|
}
|
|
}
|
|
}
|