adding a test for enum mapping between equal enums of different types.
This commit is contained in:
@@ -172,6 +172,31 @@ namespace Umbraco.Tests.Mapping
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnumMap()
|
||||
{
|
||||
var definitions = new MapDefinitionCollection(new IMapDefinition[]
|
||||
{
|
||||
new MapperDefinition4(),
|
||||
});
|
||||
var mapper = new UmbracoMapper(definitions);
|
||||
|
||||
var thing5 = new Thing5()
|
||||
{
|
||||
Fruit1 = Thing5Enum.Apple,
|
||||
Fruit2 = Thing5Enum.Banana,
|
||||
Fruit3= Thing5Enum.Cherry
|
||||
};
|
||||
|
||||
var thing6 = mapper.Map<Thing5, Thing6>(thing5);
|
||||
|
||||
Assert.IsNotNull(thing6);
|
||||
Assert.AreEqual(Thing6Enum.Apple, thing6.Fruit1);
|
||||
Assert.AreEqual(Thing6Enum.Banana, thing6.Fruit2);
|
||||
Assert.AreEqual(Thing6Enum.Cherry, thing6.Fruit3);
|
||||
}
|
||||
|
||||
|
||||
private class Thing1
|
||||
{
|
||||
public string Value { get; set; }
|
||||
@@ -188,6 +213,34 @@ namespace Umbraco.Tests.Mapping
|
||||
private class Thing4
|
||||
{ }
|
||||
|
||||
private class Thing5
|
||||
{
|
||||
public Thing5Enum Fruit1 { get; set; }
|
||||
public Thing5Enum Fruit2 { get; set; }
|
||||
public Thing5Enum Fruit3 { get; set; }
|
||||
}
|
||||
|
||||
private enum Thing5Enum
|
||||
{
|
||||
Apple = 0,
|
||||
Banana = 1,
|
||||
Cherry = 2
|
||||
}
|
||||
|
||||
private class Thing6
|
||||
{
|
||||
public Thing6Enum Fruit1 { get; set; }
|
||||
public Thing6Enum Fruit2 { get; set; }
|
||||
public Thing6Enum Fruit3 { get; set; }
|
||||
}
|
||||
|
||||
private enum Thing6Enum
|
||||
{
|
||||
Apple = 0,
|
||||
Banana = 1,
|
||||
Cherry = 2
|
||||
}
|
||||
|
||||
private class MapperDefinition1 : IMapDefinition
|
||||
{
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
@@ -224,5 +277,22 @@ namespace Umbraco.Tests.Mapping
|
||||
mapper.Define<Property, object>();
|
||||
}
|
||||
}
|
||||
|
||||
private class MapperDefinition4 : IMapDefinition
|
||||
{
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
{
|
||||
mapper.Define<Thing5, Thing6>((source, context) => new Thing6(), Map);
|
||||
mapper.Define<Thing5Enum, Thing6Enum>(
|
||||
(source, context) => (Thing6Enum)source);
|
||||
}
|
||||
|
||||
private void Map(Thing5 source, Thing6 target, MapperContext context)
|
||||
{
|
||||
target.Fruit1 = context.Map<Thing6Enum>(source.Fruit1);
|
||||
target.Fruit2 = context.Map<Thing6Enum>(source.Fruit2);
|
||||
target.Fruit3 = context.Map<Thing6Enum>(source.Fruit3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user