Add GetDisplayName to enum extensions
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using UnitTests.Common.Utils;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using UnitTests.Common.Utils;
|
||||
using DescriptionAttribute = System.ComponentModel.DescriptionAttribute;
|
||||
|
||||
namespace UnitTests.Common.Extensions
|
||||
@@ -107,6 +108,22 @@ namespace UnitTests.Common.Extensions
|
||||
Assert.IsFalse(list.Any());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnDisplayNameOrStringRepresentation()
|
||||
{
|
||||
// arrange
|
||||
var enumWithDisplayName = TestEnum.Two;
|
||||
var enumWithoutDisplayName = TestEnum.Zero;
|
||||
|
||||
// act
|
||||
string displayName = enumWithDisplayName.GetDisplayName();
|
||||
string noDisplayName = enumWithoutDisplayName.GetDisplayName();
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("Zwei", displayName);
|
||||
Assert.AreEqual(enumWithoutDisplayName.ToString(), noDisplayName);
|
||||
}
|
||||
|
||||
internal enum TestEnum
|
||||
{
|
||||
[CustomMultiple("nix")]
|
||||
@@ -115,6 +132,7 @@ namespace UnitTests.Common.Extensions
|
||||
Zero,
|
||||
[Description("Eins")]
|
||||
One,
|
||||
[Display(Name = "Zwei")]
|
||||
Two,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user