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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using Xunit;
namespace System.ComponentModel.DataAnnotations.Tests
{
public class EmailAddressAttributeTests : ValidationAttributeTestBase
{
protected override IEnumerable<TestCase> ValidValues()
{
yield return new TestCase(new EmailAddressAttribute(), null);
yield return new TestCase(new EmailAddressAttribute(), "someName@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "1234@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "firstName.lastName@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "\u00A0@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "!#$%&'*+-/=?^_`|~@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "\"firstName.lastName\"@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "someName@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "someName@some~domain.com");
yield return new TestCase(new EmailAddressAttribute(), "someName@some_domain.com");
yield return new TestCase(new EmailAddressAttribute(), "someName@1234.com");
yield return new TestCase(new EmailAddressAttribute(), "someName@someDomain\uFFEF.com");
}
protected override IEnumerable<TestCase> InvalidValues()
{
yield return new TestCase(new EmailAddressAttribute(), 0);
yield return new TestCase(new EmailAddressAttribute(), "");
yield return new TestCase(new EmailAddressAttribute(), " \r \t \n" );
yield return new TestCase(new EmailAddressAttribute(), "someName@[\r\n\tsomeDomain]");
yield return new TestCase(new EmailAddressAttribute(), "@someDomain.com");
yield return new TestCase(new EmailAddressAttribute(), "@someDomain@abc.com");
yield return new TestCase(new EmailAddressAttribute(), "someName");
yield return new TestCase(new EmailAddressAttribute(), "someName@");
yield return new TestCase(new EmailAddressAttribute(), "someName@a@b.com");
}
[Fact]
public static void DataType_CustomDataType_ReturnExpected()
{
var attribute = new EmailAddressAttribute();
Assert.Equal(DataType.EmailAddress, attribute.DataType);
Assert.Null(attribute.CustomDataType);
}
}
}
|