Skip to content

Commit

Permalink
Added tests for EnumExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
M3LiNdRu committed Oct 25, 2016
1 parent a2fe613 commit 7cc0f8d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,80 @@
namespace MoreDotNet.Tests.Extensions.Common.EnumExtensions
{
using System;
using System.ComponentModel;
using MoreDotNet.Extensions.Common;
using Xunit;

public class GetDescriptionTests
{
private enum TestEnumWithDescription
{
[Description("This is the default value.")]
Default = 0,
[Description("This is the second value")]
One = 1,
[Description("This is the third value")]
Two = 2
}

private enum TestEnumWithoutDescription
{
Default = 0,
One = 1,
Two = 2
}

[Fact]
public void IsLike_CompareBasicPatterns_ShouldPass()
public void GetDescription_GivenTestEnumWithDescription_ShouldReturnEnumDescriptionString()
{
string expected = "This is the default value.";
TestEnumWithDescription testEnum = TestEnumWithDescription.Default;

string enumDescription = testEnum.GetDescription();

Assert.Equal(enumDescription, expected);
}

[Fact]
public void GetDescription_GivenTestEnumWithoutDescription_ShouldReturnToStringMethodValue()
{
string expected = TestEnumWithoutDescription.Default.ToString();
TestEnumWithoutDescription testEnum = TestEnumWithoutDescription.Default;

string enumDescription = testEnum.GetDescription();

Assert.Equal(enumDescription, expected);
}

[Fact]
public void GetDescription_GivenInvalidTestEnumValue_ShouldReturnToStringMethodValue()
{
string expected = "4";
int value = 4;

string result = ((TestEnumWithoutDescription)value).GetDescription();

Assert.Equal(expected, result);
}

[Fact]
public void GetDescription_GivenInvalidEnumType_ShouldThrowException()
{
TestStruct structTest = default(TestStruct);

Assert.Throws<ArgumentException>(() => structTest.GetDescription());
}

private struct TestStruct
{
private int value;
private string name;

public TestStruct(int number, string key)
{
this.value = number;
this.name = key;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,33 @@

public class GetDisplayNameTests
{
private enum TestEnum
{
Default = 0,
One = 1,
Two = 2
}

[Fact]
public void GetDisplayName__GivenTestEnum_ShouldReturnEnumNameString()
{
string expected = "Default";
TestEnum testEnum = TestEnum.Default;

string enumName = testEnum.GetDisplayName();

Assert.Equal(enumName, expected);
}

[Fact]
public void GetDescription_GivenInvalidTestEnumValue_ShouldReturnStringValue()
{
string expected = "4";
int value = 4;

string result = ((TestEnum)value).GetDescription();

Assert.Equal(expected, result);
}
}
}

0 comments on commit 7cc0f8d

Please # to comment.