forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBindAttributeTest.cs
More file actions
99 lines (82 loc) · 2.99 KB
/
Copy pathBindAttributeTest.cs
File metadata and controls
99 lines (82 loc) · 2.99 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
// 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 Microsoft.TestCommon;
namespace System.Web.Mvc.Test
{
public class BindAttributeTest
{
[Fact]
public void PrefixProperty()
{
// Arrange
BindAttribute attr = new BindAttribute { Prefix = "somePrefix" };
// Act & assert
Assert.Equal("somePrefix", attr.Prefix);
}
[Fact]
public void PrefixPropertyDefaultsToNull()
{
// Arrange
BindAttribute attr = new BindAttribute();
// Act & assert
Assert.Null(attr.Prefix);
}
[Fact]
public void IncludePropertyDefaultsToEmptyString()
{
// Arrange
BindAttribute attr = new BindAttribute { Include = null };
// Act & assert
Assert.Equal(String.Empty, attr.Include);
}
[Fact]
public void ExcludePropertyDefaultsToEmptyString()
{
// Arrange
BindAttribute attr = new BindAttribute { Exclude = null };
// Act & assert
Assert.Equal(String.Empty, attr.Exclude);
}
[Fact]
public void IsPropertyAllowedReturnsFalseForBlacklistedPropertiesIfBindPropertiesIsExclude()
{
// Setup
BindAttribute attr = new BindAttribute { Exclude = "FOO,BAZ" };
// Act & assert
Assert.False(attr.IsPropertyAllowed("foo"));
Assert.True(attr.IsPropertyAllowed("bar"));
Assert.False(attr.IsPropertyAllowed("baz"));
}
[Fact]
public void IsPropertyAllowedReturnsTrueAlwaysIfBindPropertiesIsAll()
{
// Setup
BindAttribute attr = new BindAttribute();
// Act & assert
Assert.True(attr.IsPropertyAllowed("foo"));
Assert.True(attr.IsPropertyAllowed("bar"));
Assert.True(attr.IsPropertyAllowed("baz"));
}
[Fact]
public void IsPropertyAllowedReturnsTrueForWhitelistedPropertiesIfBindPropertiesIsInclude()
{
// Setup
BindAttribute attr = new BindAttribute { Include = "FOO,BAR" };
// Act & assert
Assert.True(attr.IsPropertyAllowed("foo"));
Assert.True(attr.IsPropertyAllowed("bar"));
Assert.False(attr.IsPropertyAllowed("baz"));
}
[Fact]
public void IsPropertyAllowedReturnsFalseForBlacklistOverridingWhitelistedProperties()
{
// Setup
BindAttribute attr = new BindAttribute { Include = "FOO,BAR", Exclude = "bar,QUx" };
// Act & assert
Assert.True(attr.IsPropertyAllowed("foo"));
Assert.False(attr.IsPropertyAllowed("bar"));
Assert.False(attr.IsPropertyAllowed("baz"));
Assert.False(attr.IsPropertyAllowed("qux"));
}
}
}