-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathEnumExtensionTest.cs
73 lines (65 loc) · 2.31 KB
/
EnumExtensionTest.cs
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
using System;
using Fido2NetLib;
using Fido2NetLib.Objects;
using Xunit;
namespace fido2_net_lib.Test
{
public class EnumExtensionTest
{
[Fact]
public void TestToEnum()
{
var enumNames = Enum.GetNames(typeof(AttestationConveyancePreference));
foreach (var enumName in enumNames)
{
enumName.ToEnum<AttestationConveyancePreference>();
}
}
[Theory]
// ignoreCase true, valid
[InlineData("INDIRECT", true, false)]
[InlineData("indIrEcT", true, false)]
[InlineData("indirect", true, false)]
// invalid
[InlineData("Indirect_Invalid", true, true)]
// ignoreCase false, valid
[InlineData(nameof(AttestationConveyancePreference.Indirect), false, false)]
// invalid
[InlineData("Indirect_Invalid", false, true)]
[InlineData("INDIRECT", false, true)]
[InlineData("indIrEcT", false, true)]
public void TestToEnumWithIgnoringCase(string value, bool ignoreCase, bool shouldThrow)
{
var exception = Record.Exception(() => value.ToEnum<AttestationConveyancePreference>(ignoreCase));
if (shouldThrow)
{
Assert.IsType<ArgumentException>(exception);
}
else
{
Assert.Null(exception);
}
}
[Theory]
[InlineData("CROSS-PLATFORM", true, false)] // valid
[InlineData("cRoss-PlatfoRm", true, false)] // valid
[InlineData("cross-platform", true, false)] // valid
[InlineData("cross_platform", true, true)] // invalid
[InlineData("cross-platforms", true, true)] // invalid
[InlineData("CROSS_PLATFORM", true, true)] // invalid
[InlineData("CROSS-PLATFORM", false, true)] // invalid
[InlineData("cRoss-PlatfoRm", false, true)] // invalid
public void TestToEnumWithDashes(string value, bool ignoreCase, bool shouldThrow)
{
var exception = Record.Exception(() => value.ToEnum<AuthenticatorAttachment>(ignoreCase));
if (shouldThrow)
{
Assert.IsType<ArgumentException>(exception);
}
else
{
Assert.Null(exception);
}
}
}
}