When using the MapDynamic an exception is thrown for enums. Example test case below.
var dynamicCustomers = new List<object>();
for (int i = 0; i < 5; i++)
{
dynamic customer = new ExpandoObject();
customer.Id = i;
customer.FirstName = "FirstName" + i;
customer.LastName = "LastName" + i;
customer.MaritalStatus = 2;
customer.Orders_Id = i;
customer.Orders_OrderTotal = i + 0m;
dynamicCustomers.Add(customer);
}
// Act
var customers = Slapper.AutoMapper.MapDynamic<Customer>(dynamicCustomers);
// Assert
Assert.That(customers.Count() == 5);
Assert.That(customers.First().Orders.Count == 1);
System.Exception : Invalid cast from 'System.Int32' to 'Slapper.Tests.MapDynamicTests+MaritalStatus'.: An error occurred while mapping the value '2' of type System.Int32 to the member name 'MaritalStatus' of type System.Nullable`1[Slapper.Tests.MapDynamicTests+MaritalStatus] on the Slapper.Tests.MapDynamicTests+Customer class.
----> System.InvalidCastException : Invalid cast from 'System.Int32' to 'Slapper.Tests.MapDynamicTests+MaritalStatus'.
When using the MapDynamic an exception is thrown for enums. Example test case below.
System.Exception : Invalid cast from 'System.Int32' to 'Slapper.Tests.MapDynamicTests+MaritalStatus'.: An error occurred while mapping the value '2' of type System.Int32 to the member name 'MaritalStatus' of type System.Nullable`1[Slapper.Tests.MapDynamicTests+MaritalStatus] on the Slapper.Tests.MapDynamicTests+Customer class. ----> System.InvalidCastException : Invalid cast from 'System.Int32' to 'Slapper.Tests.MapDynamicTests+MaritalStatus'.