igor-tkachev/bltoolkit — Issue #66: MapObjectToDictionary with TypeExtension.GetExtensions work wrong
Author: b0bi79
Created: 2011-11-16 13:27:08+00:00
State: open

EnumToValueTest test work fine, ObjToDicTest discard

Test

public class MapEnumTest
{
public class TestObj
{
[MapField("country_code")]
public CountryCodeEnum Country { get; set; }
[MapField("other")]
public OtherEnum Other { get; set; }
}

public enum CountryCodeEnum
{
[MapValue("AFA")]
AF,
[MapValue("ALA")]
AL,
[MapValue("DZA")]
DZ,
[MapValue("ASA")]
AS,
[MapValue("ADA")]
AD
}

public enum OtherEnum
{
[MapValue("v1")]
EnumValue1,
[MapValue("v2")]
EnumValue2
}

[Test]
public void EnumToValueTest()
{
Map.Extensions = TypeExtension.GetExtensions("Map.xml");

Assert.AreEqual("AL", Map.EnumToValue(CountryCodeEnum.AL));
Assert.AreEqual(101, Map.EnumToValue(OtherEnum.EnumValue2));
}

[Test]
public void ObjToDicTest()
{
var obj = new TestObj();
obj.Country = CountryCodeEnum.DZ;
obj.Other = OtherEnum.EnumValue2;

var sh = new MappingSchema();
sh.Extensions = TypeExtension.GetExtensions("Map.xml");
var pars = sh.MapObjectToDictionary(obj);

Assert.AreEqual("DZ", pars["country_code"]);
Assert.AreEqual(101, pars["other"]);
}
}

Map.xml file:

?xml version="1.0" encoding="utf-8" ?>
Types
xmlns = "urn:schemas-bltoolkit-net:typeext"
xmlns:m = "urn:schemas-bltoolkit-net:mapping">

Type Name='CountryCodeEnum'>
Member Name='AF' MapValue='AF' MapValue-Type='System.String'/>
Member Name='AL' MapValue='AL' MapValue-Type='System.String'/>
Member Name='DZ' MapValue='DZ' MapValue-Type='System.String'/>
Member Name='AS' MapValue='AS' MapValue-Type='System.String'/>
Member Name='AD' MapValue='AD' MapValue-Type='System.String'/>
/Type>

Type Name='OtherEnum'>
Member Name='EnumValue1' MapValue='100' MapValue-Type='System.Int32' />
Member Name='EnumValue2' MapValue='101' MapValue-Type='System.Int32' />
/Type>

/Types>