This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #8
- Loading branch information
Michael Hancock
committed
Apr 7, 2020
1 parent
33f8ccd
commit eb0f05e
Showing
3 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
test/EnumDisplayName.Test/EnumExtensionsGetFlagsDisplayNameTests.cs
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,99 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Enable.EnumDisplayName | ||
{ | ||
public class EnumExtensionsGetFlagsDisplayNameTests | ||
{ | ||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsEmptyStringWhenSourceIsNull() | ||
{ | ||
// Arrange | ||
Enum source = null; | ||
|
||
// Act | ||
var result = source.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsEnumDisplayNameAttributeDisplayName() | ||
{ | ||
// Act | ||
var result = MockFlagEnum.EnumDisplayNameAttribute.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(MockEnumDisplayNames.EnumDisplayNameAttribute, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsEnumDisplayNameAttributeWithResourceDisplayName() | ||
{ | ||
// Act | ||
var result = MockFlagEnum.EnumDisplayNameAttributeWithResource.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(Resources.MockEnum.EnumDisplayNameAttributeWithResource, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsDisplayAttributeDisplayName() | ||
{ | ||
// Act | ||
var result = MockFlagEnum.DisplayAttribute.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(MockEnumDisplayNames.DisplayAttribute, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsFieldName() | ||
{ | ||
// Act | ||
var result = MockFlagEnum.NoAttribute.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(MockEnumDisplayNames.NoAttribute, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsEmptyStringWithSpecialNameAttribute() | ||
{ | ||
// Act | ||
var result = MockFlagEnum.SpecialName.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsCommaSeperatedStringForFlagValues() | ||
{ | ||
// Arrange | ||
var sut = MockFlagEnum.DisplayAttribute | MockFlagEnum.EnumDisplayNameAttribute; | ||
|
||
// Act | ||
var result = sut.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
var expected = $"{MockEnumDisplayNames.EnumDisplayNameAttribute},{MockEnumDisplayNames.DisplayAttribute}"; | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void GetFlagsDisplayName_ReturnsCommaSeperatedStringForFlagValues_ExceptSpecialNameAttributes() | ||
{ | ||
// Arrange | ||
var sut = MockFlagEnum.DisplayAttribute | MockFlagEnum.SpecialName; | ||
|
||
// Act | ||
var result = sut.GetFlagsDisplayName(); | ||
|
||
// Assert | ||
var expected = $"{MockEnumDisplayNames.DisplayAttribute}"; | ||
Assert.Equal(expected, result); | ||
} | ||
} | ||
} |
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,25 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Enable.EnumDisplayName | ||
{ | ||
[Flags] | ||
public enum MockFlagEnum | ||
{ | ||
[EnumDisplayName(MockEnumDisplayNames.EnumDisplayNameAttribute)] | ||
EnumDisplayNameAttribute = 1, | ||
|
||
[EnumDisplayName(MockEnumDisplayNames.EnumDisplayNameAttributeWithResource, typeof(Resources.MockEnum))] | ||
EnumDisplayNameAttributeWithResource = 2, | ||
|
||
[Display(Name = MockEnumDisplayNames.DisplayAttribute)] | ||
DisplayAttribute = 4, | ||
|
||
NoAttribute = 8, | ||
|
||
[SpecialName] | ||
[EnumDisplayName(MockEnumDisplayNames.SpecialName)] | ||
SpecialName = 16 | ||
} | ||
} |