Skip to content

Commit 9d7ed7e

Browse files
committed
Aligned EnumValueObject implementations.
1 parent ebaffc4 commit 9d7ed7e

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

CSharpFunctionalExtensions.Tests/ValueObjectTests/EnumValueObjectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public void GivenNullOrEmptyKey_WhenCreating_ThenException(string key)
8282
[InlineData("Four", false)]
8383
[InlineData(nameof(TestEnumValueObject.Two), true)]
8484
[InlineData(nameof(TestEnumValueObject.One), true)]
85-
public void GivenPossibleKey_WhenCheckingIfKeyIsEnumValueObject_ThenShouldReturnTrueIfKeyRecognized(string possibleKey, bool isIn)
85+
public void GivenPossibleKey_WhenCheckingIfKeyIsEnumValueObject_ThenShouldReturnTrueIfKeyRecognized(string possibleId, bool isIn)
8686
{
8787
// Act
88-
var isEnumValueObject = TestEnumValueObject.Is(possibleKey);
88+
var isEnumValueObject = TestEnumValueObject.Is(possibleId);
8989

9090
// Assert
9191
isEnumValueObject.Should().Be(isIn);

CSharpFunctionalExtensions/ValueObject/EnumValueObject.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ public static Maybe<TEnumeration> FromName(string name)
6565
? EnumerationsByName[name]
6666
: null;
6767
}
68-
68+
69+
public static IReadOnlyCollection<TEnumeration> All = EnumerationsById.Values;
70+
71+
public static bool Is(string possibleName) => All.Select(e => e.Name).Contains(possibleName);
72+
73+
public static bool Is(TId possibleId) => All.Select(e => e.Id).Contains(possibleId);
74+
75+
public override string ToString() => Name;
76+
6977
protected override IEnumerable<object> GetEqualityComponents()
7078
{
7179
yield return Id;
@@ -98,7 +106,7 @@ protected EnumValueObject(string id)
98106
Id = id;
99107
}
100108

101-
public static IEnumerable<TEnumeration> All = Enumerations.Values;
109+
public static IReadOnlyCollection<TEnumeration> All = Enumerations.Values;
102110

103111
public virtual string Id { get; protected set; }
104112

@@ -139,7 +147,7 @@ public static Maybe<TEnumeration> FromId(string id)
139147
: null;
140148
}
141149

142-
public static bool Is(string possibleKey) => All.Select(e => e.Id).Contains(possibleKey);
150+
public static bool Is(string possibleId) => All.Select(e => e.Id).Contains(possibleId);
143151

144152
public override string ToString() => Id;
145153

0 commit comments

Comments
 (0)