-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DomCR/extensions-refactor
Extensions refactor
- Loading branch information
Showing
7 changed files
with
165 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using CSUtilities.Attributes; | ||
using CSUtilities.Extensions; | ||
using System; | ||
using Xunit; | ||
|
||
namespace CSUtilities.Tests.Extensions | ||
{ | ||
public class EnumExtensionsTests | ||
{ | ||
private enum MockStringValues | ||
{ | ||
[StringValue("Undefined value for enum")] | ||
Undefined = 0, | ||
|
||
[StringValue("Enum String Value 1")] | ||
Value1 = 1, | ||
|
||
[StringValue("Enum String Value 2")] | ||
Value2, | ||
|
||
NoAttribute, | ||
} | ||
|
||
[Fact] | ||
public void GetStringValueTest() | ||
{ | ||
Assert.Equal("Undefined value for enum", MockStringValues.Undefined.GetStringValue()); | ||
Assert.Equal("Enum String Value 1", MockStringValues.Value1.GetStringValue()); | ||
Assert.Equal("Enum String Value 2", MockStringValues.Value2.GetStringValue()); | ||
Assert.Null(MockStringValues.NoAttribute.GetStringValue()); | ||
} | ||
|
||
[Fact] | ||
public void ParseTest() | ||
{ | ||
Assert.Equal(MockStringValues.Value1, EnumExtensions.Parse<MockStringValues>("Value1")); | ||
Assert.Equal(MockStringValues.Value1, EnumExtensions.Parse<MockStringValues>("value1", true)); | ||
Assert.Throws<ArgumentException>(() => EnumExtensions.Parse<MockStringValues>("value1", false)); | ||
} | ||
|
||
[Fact] | ||
public void TryParseTest() | ||
{ | ||
MockStringValues result = MockStringValues.Undefined; | ||
Assert.True(EnumExtensions.TryParse("Value1", out result)); | ||
Assert.Equal(MockStringValues.Value1, result); | ||
|
||
result = MockStringValues.Undefined; | ||
Assert.True(EnumExtensions.TryParse<MockStringValues>("value1", out result, true)); | ||
Assert.Equal(MockStringValues.Value1, result); | ||
|
||
Assert.False(EnumExtensions.TryParse<MockStringValues>("value1", out result, false)); | ||
Assert.Equal(default(MockStringValues), result); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CSUtilities.Attributes | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters