forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlAttributePropertyHelperTest.cs
More file actions
112 lines (90 loc) · 3.69 KB
/
Copy pathHtmlAttributePropertyHelperTest.cs
File metadata and controls
112 lines (90 loc) · 3.69 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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.Linq;
using System.Reflection;
using Microsoft.TestCommon;
namespace System.Web.WebPages.Test
{
public class HtmlAttributePropertyHelperTest
{
[Fact]
public void HtmlAttributePropertyHelperRenamesPropertyNames()
{
// Arrange
var anonymous = new { bar_baz = "foo" };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
HtmlAttributePropertyHelper helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("bar_baz", property.Name);
Assert.Equal("bar-baz", helper.Name);
}
[Fact]
public void HtmlAttributePropertyHelperReturnsNameCorrectly()
{
// Arrange
var anonymous = new { foo = "bar" };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
HtmlAttributePropertyHelper helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("foo", property.Name);
Assert.Equal("foo", helper.Name);
}
[Fact]
public void HtmlAttributePropertyHelperReturnsValueCorrectly()
{
// Arrange
var anonymous = new { bar = "baz" };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
HtmlAttributePropertyHelper helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("bar", helper.Name);
Assert.Equal("baz", helper.GetValue(anonymous));
}
[Fact]
public void HtmlAttributePropertyHelperReturnsValueCorrectlyForValueTypes()
{
// Arrange
var anonymous = new { foo = 32 };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
HtmlAttributePropertyHelper helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("foo", helper.Name);
Assert.Equal(32, helper.GetValue(anonymous));
}
[Fact]
public void HtmlAttributePropertyHelperReturnsCachedPropertyHelper()
{
// Arrange
var anonymous = new { foo = "bar" };
// Act
PropertyHelper[] helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
PropertyHelper[] helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous);
// Assert
Assert.Single(helpers1);
Assert.ReferenceEquals(helpers1, helpers2);
Assert.ReferenceEquals(helpers1[0], helpers2[0]);
}
[Fact]
public void HtmlAttributeDoesNotShareCacheWithPropertyHelper()
{
// Arrange
var anonymous = new { bar_baz1 = "foo" };
// Act
PropertyHelper[] helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
PropertyHelper[] helpers2 = PropertyHelper.GetProperties(anonymous);
// Assert
PropertyHelper helper1 = Assert.Single(helpers1);
PropertyHelper helper2 = Assert.Single(helpers2);
Assert.NotEqual(helpers1, helpers2);
Assert.NotEqual(helper1, helper2);
Assert.IsType<HtmlAttributePropertyHelper>(helper1);
Assert.IsNotType<HtmlAttributePropertyHelper>(helper2);
Assert.Equal("bar-baz1", helper1.Name);
Assert.Equal("bar_baz1", helper2.Name);
}
}
}