-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathSmartEnumExtensionsTests.cs
54 lines (47 loc) · 1.81 KB
/
SmartEnumExtensionsTests.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
namespace Ardalis.SmartEnum.UnitTests
{
using System;
using FluentAssertions;
using Xunit;
public class SmartEnumExtensionsTests
{
public abstract class AbstractEnum : SmartEnum<AbstractEnum, int>
{
protected AbstractEnum(string name, int value) : base(name, value) { }
}
public class GenericEnum<T> :
SmartEnum<GenericEnum<T>, T>
where T : struct, IEquatable<T>, IComparable<T>
{
protected GenericEnum(string name, T value) : base(name, value) { }
}
public static TheoryData<Type, bool, Type[]> IsSmartEnumData =>
new TheoryData<Type, bool, Type[]>
{
{ typeof(int), false, null },
{ typeof(AbstractEnum), false, null },
{ typeof(GenericEnum<>), false, null },
{ typeof(TestEnum), true, new Type[] { typeof(TestEnum), typeof(int) }},
};
[Theory]
[MemberData(nameof(IsSmartEnumData))]
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
public void IsSmartEnumReturnsExpected(Type type, bool expectedResult, Type[] _)
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
{
var result = type.IsSmartEnum();
result.Should().Be(expectedResult);
}
[Theory]
[MemberData(nameof(IsSmartEnumData))]
public void IsSmartEnum2ReturnsExpected(Type type, bool expectedResult, Type[] expectedGenericArguments)
{
var result = type.IsSmartEnum(out var genericArguments);
result.Should().Be(expectedResult);
if (result)
{
genericArguments.Should().Equal(expectedGenericArguments);
}
}
}
}