-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRegularExpressionAttributeTests.cs
More file actions
138 lines (101 loc) · 4.01 KB
/
RegularExpressionAttributeTests.cs
File metadata and controls
138 lines (101 loc) · 4.01 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
using Metalama.Patterns.Contracts.UnitTests.Assets;
using Xunit;
namespace Metalama.Patterns.Contracts.UnitTests;
// ReSharper disable InconsistentNaming
// ReSharper disable RedundantSuppressNullableWarningExpression
public sealed class RegularExpressionAttributeTests
{
[Fact]
public void Given_MethodWithRegexMatch_When_CorrectValuePassed_Then_Success()
{
var cut = new RegexTestClass();
cut.SetEmail( "test@postsharp.test" );
}
[Fact]
public void Given_MethodWithRegexMatch_When_IncorrectValuePassed_Then_ExceptionIsThrown()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.SetEmail( "asd" ) );
Assert.Contains( "email", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldWithRegexMatch_When_CorrectValuePassed_Then_Success()
{
var cut = new RegexTestClass();
cut.Email = "test@postsharp.test";
}
[Fact]
public void Given_FieldWithRegexMatch_When_IncorrectValuePassed_Then_ExceptionIsThrown()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.Email = "asd" );
Assert.Contains( "Email", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldWithEmail_When_CorrectValuePassed_Then_Success()
{
var cut = new RegexTestClass();
cut.Email2 = "test@postsharp.test";
}
[Fact]
public void Given_FieldEmail_When_IncorrectValuePassed_Then_ExceptionIsThrown()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.Email2 = "asd" );
Assert.Contains( "Email2", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldEmail_When_ValidValueWithSingleQuote_Then_Success()
{
var cut = new RegexTestClass();
cut.Email2 = "Spirit.O'Crowd@foobusiness.borg.uk";
}
[Fact]
public void Given_FieldEmail_When_ValidValueWithDoubleQuote_Then_Success()
{
var cut = new RegexTestClass();
cut.Email2 = "\"Spirit O'Crowd\"@foobusiness.borg.uk";
}
[Fact]
public void Given_FieldWithPhone_When_CorrectValuePassed_Then_Success()
{
var cut = new RegexTestClass();
cut.PhoneField = "644-14-90";
}
[Fact]
public void Given_FieldPhone_When_IncorrectValuePassed_Then_ExceptionIsThrown()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.PhoneField = "a123" );
Assert.Contains( "PhoneField", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldWithUrl_When_CorrectValuePassed_Then_Success()
{
var cut = new RegexTestClass();
cut.UrlField = "http://www.sharpcrafters.com/";
}
[Fact]
public void Given_FieldUrl_When_IncorrectValuePassed_Then_ExceptionIsThrown()
{
var cut = new RegexTestClass();
// ReSharper disable once StringLiteralTypo
var e = Assert.Throws<ArgumentException>( () => cut.UrlField = "dslkfusd" );
Assert.Contains( "UrlField", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldWithRegexMatch_When_IncorrectValuePassed_Then_ExceptionMessageIsCorrect_1()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.PatternEscaping1 = "hello" );
Assert.Contains( "must match the regular expression '^[a-z]{4}$'.", e.Message, StringComparison.Ordinal );
}
[Fact]
public void Given_FieldWithRegexMatch_When_IncorrectValuePassed_Then_ExceptionMessageIsCorrect_2()
{
var cut = new RegexTestClass();
var e = Assert.Throws<ArgumentException>( () => cut.PatternEscaping2 = "{hello}" );
Assert.Contains( "must match the regular expression '^\\{[a-z]{4}}$'.", e.Message, StringComparison.Ordinal );
}
}