Skip to content

Commit f328195

Browse files
authored
Flags enums (#46)
* Start of flags enum support * Mapping numeric values to enums with IsDefined and a cast, instead of TryParse with the string value * Reusing Enum.IsDefined call creation method * Support for mapping numeric values to multi-value flags enums * Extending numeric to flags enum test coverage * Support for mapping a numeric string value to a flags enum * Expanding string -> flags enum test coverage * Test coverage for object strings and flags enums -> flags enums
1 parent 818d50c commit f328195

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

AgileMapper.UnitTests/SimpleTypeConversion/WhenConvertingToFlagsEnums.cs

+27
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,32 @@ public void ShouldMapAMultiValueMixedStringToAFlagsEnum()
8080

8181
result.Value.ShouldBe(New | InProgress | Completed);
8282
}
83+
84+
[Fact]
85+
public void ShouldMapAMultiValueMixedObjectStringToAFlagsEnum()
86+
{
87+
var source = new PublicProperty<object> { Value = "New, InProgress, LaLaLa, 32" };
88+
var result = Mapper.Map(source).ToANew<PublicField<Status>>();
89+
90+
result.Value.ShouldBe(New | InProgress | Removed);
91+
}
92+
93+
[Fact]
94+
public void ShouldMapASingleValueNullableFlagsEnumToAFlagsEnum()
95+
{
96+
var source = new PublicProperty<Status?> { Value = Cancelled };
97+
var result = Mapper.Map(source).ToANew<PublicField<Status>>();
98+
99+
result.Value.ShouldBe(Cancelled);
100+
}
101+
102+
[Fact]
103+
public void ShouldMapAMultiValueFlagsEnumToANullableFlagsEnum()
104+
{
105+
var source = new PublicProperty<Status> { Value = Assigned | Completed | Cancelled };
106+
var result = Mapper.Map(source).ToANew<PublicField<Status?>>();
107+
108+
result.Value.ShouldBe(Assigned | Completed | Cancelled);
109+
}
83110
}
84111
}

0 commit comments

Comments
 (0)