-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathSmartEnumCompareTo.cs
73 lines (59 loc) · 2.45 KB
/
SmartEnumCompareTo.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
namespace Ardalis.SmartEnum.UnitTests
{
using FluentAssertions;
using Xunit;
public class SmartEnumCompareTo
{
public static TheoryData<TestEnum, TestEnum, int> CompareToData =>
new TheoryData<TestEnum, TestEnum, int>
{
{ TestEnum.Two, TestEnum.One, 1 },
{ TestEnum.Two, TestEnum.Two, 0 },
{ TestEnum.Two, TestEnum.Three, -1 },
};
[Theory]
[MemberData(nameof(CompareToData))]
public void CompareToReturnsExpected(TestEnum left, TestEnum right, int expected)
{
var result = left.CompareTo(right);
result.Should().Be(expected);
}
public static TheoryData<TestEnum, TestEnum, bool, bool, bool> ComparisonOperatorsData =>
new TheoryData<TestEnum, TestEnum, bool, bool, bool>
{
{ TestEnum.Two, TestEnum.One, false, false, true },
{ TestEnum.Two, TestEnum.Two, false, true, false },
{ TestEnum.Two, TestEnum.Three, true, false, false },
};
#pragma warning disable xUnit1026 // Theory method does not use parameter
[Theory]
[MemberData(nameof(ComparisonOperatorsData))]
public void LessThanReturnsExpected(TestEnum left, TestEnum right, bool lessThan, bool equalTo, bool greaterThan)
{
var result = left < right;
result.Should().Be(lessThan);
}
[Theory]
[MemberData(nameof(ComparisonOperatorsData))]
public void LessThanOrEqualReturnsExpected(TestEnum left, TestEnum right, bool lessThan, bool equalTo, bool greaterThan)
{
var result = left <= right;
result.Should().Be(lessThan || equalTo);
}
[Theory]
[MemberData(nameof(ComparisonOperatorsData))]
public void GreaterThanReturnsExpected(TestEnum left, TestEnum right, bool lessThan, bool equalTo, bool greaterThan)
{
var result = left > right;
result.Should().Be(greaterThan);
}
[Theory]
[MemberData(nameof(ComparisonOperatorsData))]
public void GreaterThanOrEqualReturnsExpected(TestEnum left, TestEnum right, bool lessThan, bool equalTo, bool greaterThan)
{
var result = left >= right;
result.Should().Be(greaterThan || equalTo);
}
#pragma warning restore xUnit1026 // Theory method does not use parameter
}
}