File tree Expand file tree Collapse file tree 1 file changed +86
-0
lines changed
Filter options
src/ByteDecoder.Common.Tests Expand file tree Collapse file tree 1 file changed +86
-0
lines changed
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using Xunit ;
3
+
4
+ namespace ByteDecoder . Common . Tests
5
+ {
6
+ public class EnumExtensionsTests
7
+ {
8
+ private enum Testify
9
+ {
10
+ Aba ,
11
+ Opal ,
12
+ }
13
+
14
+ [ Fact ]
15
+ public void ToEnum_ReturnsAValidEnumType_WhenValueIsProvided ( )
16
+ {
17
+ // Arrange
18
+ var value = "Aba" ;
19
+
20
+ // Act
21
+ var result = value . ToEnum < Testify > ( ) ;
22
+
23
+ // Assert
24
+ Assert . Equal ( Testify . Aba , result ) ;
25
+ Assert . IsType < Testify > ( result ) ;
26
+ }
27
+
28
+ [ Fact ]
29
+ public void ToEnum_ThrowsAnException_WhenValueIsInvalid ( )
30
+ {
31
+ // Arrange
32
+ var value = "Abal" ;
33
+
34
+ // Act
35
+ var exception = Record . Exception ( ( ) =>
36
+ {
37
+ value . ToEnum < Testify > ( ) ;
38
+ } ) ;
39
+
40
+ // Assert
41
+ Assert . IsType < ArgumentException > ( exception ) ;
42
+ }
43
+
44
+ [ Fact ]
45
+ public void ToEnum_WithDefaultValue_ReturnsValidValue_WhenCurrentValueIsValid ( )
46
+ {
47
+ // Arrange
48
+ var value = "Aba" ;
49
+
50
+ // Act
51
+ var result = value . ToEnum ( Testify . Opal ) ;
52
+
53
+ // Assert
54
+ Assert . Equal ( Testify . Aba , result ) ;
55
+ Assert . IsType < Testify > ( result ) ;
56
+ }
57
+
58
+ [ Fact ]
59
+ public void ToEnum_WithDefaultValue_ReturnsDefaultValue_WhenCurrentValueIsInvalid ( )
60
+ {
61
+ // Arrange
62
+ var value = "Abal" ;
63
+
64
+ // Act
65
+ var result = value . ToEnum ( Testify . Opal ) ;
66
+
67
+ // Assert
68
+ Assert . Equal ( Testify . Opal , result ) ;
69
+ Assert . IsType < Testify > ( result ) ;
70
+ }
71
+
72
+ [ Fact ]
73
+ public void ToEnum_WithDefaultValue_ReturnsDefaultValue_WhenCurrentValueIsEmpty ( )
74
+ {
75
+ // Arrange
76
+ var value = string . Empty ;
77
+
78
+ // Act
79
+ var result = value . ToEnum ( Testify . Opal ) ;
80
+
81
+ // Assert
82
+ Assert . Equal ( Testify . Opal , result ) ;
83
+ Assert . IsType < Testify > ( result ) ;
84
+ }
85
+ }
86
+ }
You can’t perform that action at this time.
0 commit comments