forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementalValueProviderTest.cs
More file actions
85 lines (72 loc) · 3.27 KB
/
Copy pathElementalValueProviderTest.cs
File metadata and controls
85 lines (72 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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.Globalization;
using Microsoft.TestCommon;
namespace System.Web.Http.ValueProviders.Providers
{
public class ElementalValueProviderTest
{
[Theory]
[InlineData("MyProperty", "MyProperty")]
[InlineData("MyProperty.SubProperty", "MyProperty")]
[InlineData("MyProperty[0]", "MyProperty")]
public void ContainsPrefix_ReturnsTrue_IfElementNameStartsWithPrefix(string elementName, string prefix)
{
// Arrange
CultureInfo culture = new CultureInfo("en-US");
ElementalValueProvider elementalValueProvider = new ElementalValueProvider(elementName,
new object(),
culture);
// Act
bool containsPrefix = elementalValueProvider.ContainsPrefix(prefix);
// Assert
Assert.True(containsPrefix);
}
[Theory]
[InlineData("MyProperty", "MyProperty1")]
[InlineData("MyPropertyTest", "MyProperty")]
[InlineData("Random", "MyProperty")]
public void ContainsPrefix_ReturnsFalse_IfElementCannotSpecifyValuesForPrefix(string elementName, string prefix)
{
// Arrange
CultureInfo culture = new CultureInfo("en-US");
ElementalValueProvider elementalValueProvider = new ElementalValueProvider(elementName,
new object(),
culture);
// Act
bool containsPrefix = elementalValueProvider.ContainsPrefix(prefix);
// Assert
Assert.False(containsPrefix);
}
[Fact]
public void GetValue_NameDoesNotMatch_ReturnsNull()
{
// Arrange
CultureInfo culture = CultureInfo.GetCultureInfo("fr-FR");
DateTime rawValue = new DateTime(2001, 1, 2);
ElementalValueProvider valueProvider = new ElementalValueProvider("foo", rawValue, culture);
// Act
ValueProviderResult vpResult = valueProvider.GetValue("bar");
// Assert
Assert.Null(vpResult);
}
[Theory]
[InlineData("foo")]
[InlineData("FOO")]
[InlineData("FoO")]
public void GetValue_NameMatches_ReturnsValueProviderResult(string name)
{
// Arrange
CultureInfo culture = CultureInfo.GetCultureInfo("fr-FR");
DateTime rawValue = new DateTime(2001, 1, 2);
ElementalValueProvider valueProvider = new ElementalValueProvider("foo", rawValue, culture);
// Act
ValueProviderResult vpResult = valueProvider.GetValue(name);
// Assert
Assert.NotNull(vpResult);
Assert.Equal(rawValue, vpResult.RawValue);
Assert.Equal("02/01/2001 00:00:00", vpResult.AttemptedValue);
Assert.Equal(culture, vpResult.Culture);
}
}
}