-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for duplicate keys and a few unit tests
- Loading branch information
Showing
5 changed files
with
76 additions
and
15 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
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
25 changes: 25 additions & 0 deletions
25
test/Thinktecture.Runtime.Extensions.Tests/EnumTests/Initialization.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,25 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Thinktecture.TestEnums; | ||
using Xunit; | ||
|
||
namespace Thinktecture.EnumTests | ||
{ | ||
public class Initialization | ||
{ | ||
[Fact] | ||
public void Should_throw_if_enum_has_duplicate_key() | ||
{ | ||
Action action = () => EnumWithDuplicateKey.GetAll(); | ||
action.Should().Throw<ArgumentException>() | ||
.WithMessage($"The enumeration of type \"{typeof(EnumWithDuplicateKey).FullName}\" has multiple items with the key \"item\"."); | ||
} | ||
|
||
[Fact] | ||
public void Should_not_throw_if_enum_has_2_keys_that_differs_in_casing_only_if_comparer_honors_casing() | ||
{ | ||
Action action = () => TestEnumWithNonDefaultComparer.GetAll(); | ||
action.Should().NotThrow<Exception>(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/Thinktecture.Runtime.Extensions.Tests/TestEnums/EnumWithDuplicateKey.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,18 @@ | ||
namespace Thinktecture.TestEnums | ||
{ | ||
public class EnumWithDuplicateKey : Enum<EnumWithDuplicateKey> | ||
{ | ||
public static readonly EnumWithDuplicateKey Item = new EnumWithDuplicateKey("Item"); | ||
public static readonly EnumWithDuplicateKey Duplicate = new EnumWithDuplicateKey("item"); | ||
|
||
public EnumWithDuplicateKey(string key) | ||
: base(key) | ||
{ | ||
} | ||
|
||
protected override EnumWithDuplicateKey CreateInvalid(string key) | ||
{ | ||
return new EnumWithDuplicateKey(key); | ||
} | ||
} | ||
} |
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