89 lines
3.0 KiB
C#
89 lines
3.0 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;
|
|
using System.Globalization;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
|
{
|
|
public class ElementalValueProviderTest
|
|
{
|
|
[Theory]
|
|
[InlineData("MyProperty", "MyProperty")]
|
|
[InlineData("MyProperty.SubProperty", "MyProperty")]
|
|
[InlineData("MyProperty[0]", "MyProperty")]
|
|
public async Task ContainsPrefixAsync_ReturnsTrue_IfElementNameStartsWithPrefix(string elementName,
|
|
string prefix)
|
|
{
|
|
// Arrange
|
|
var culture = new CultureInfo("en-US");
|
|
var elementalValueProvider = new ElementalValueProvider(
|
|
elementName,
|
|
"hi",
|
|
culture);
|
|
|
|
// Act
|
|
var containsPrefix = await elementalValueProvider.ContainsPrefixAsync(prefix);
|
|
|
|
// Assert
|
|
Assert.True(containsPrefix);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("MyProperty", "MyProperty1")]
|
|
[InlineData("MyPropertyTest", "MyProperty")]
|
|
[InlineData("Random", "MyProperty")]
|
|
public async Task ContainsPrefixAsync_ReturnsFalse_IfElementCannotSpecifyValuesForPrefix(string elementName,
|
|
string prefix)
|
|
{
|
|
// Arrange
|
|
var culture = new CultureInfo("en-US");
|
|
var elementalValueProvider = new ElementalValueProvider(
|
|
elementName,
|
|
"hi",
|
|
culture);
|
|
|
|
// Act
|
|
var containsPrefix = await elementalValueProvider.ContainsPrefixAsync(prefix);
|
|
|
|
// Assert
|
|
Assert.False(containsPrefix);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetValueAsync_NameDoesNotMatch_ReturnsEmptyResult()
|
|
{
|
|
// Arrange
|
|
var culture = new CultureInfo("fr-FR");
|
|
var valueProvider = new ElementalValueProvider("foo", "hi", culture);
|
|
|
|
// Act
|
|
var result = await valueProvider.GetValueAsync("bar");
|
|
|
|
// Assert
|
|
Assert.Equal(ValueProviderResult.None, result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("foo")]
|
|
[InlineData("FOO")]
|
|
[InlineData("FoO")]
|
|
public async Task GetValueAsync_NameMatches_ReturnsValueProviderResult(string name)
|
|
{
|
|
// Arrange
|
|
var culture = new CultureInfo("fr-FR");
|
|
var valueProvider = new ElementalValueProvider("foo", "hi", culture);
|
|
|
|
// Act
|
|
var result = await valueProvider.GetValueAsync(name);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal("hi", (string)result);
|
|
Assert.Equal(culture, result.Culture);
|
|
}
|
|
}
|
|
}
|