SlapperAutoMapper / Slapper.AutoMapper

Slapper.AutoMapper maps dynamic data to static types. Slap your data into submission!
MIT License
287 stars 76 forks source link

MapDynamic Enum Values causes error. #19

Closed codeplay87 closed 8 years ago

codeplay87 commented 8 years ago

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'.

odelvalle commented 8 years ago

Hi @codeplay87 I run your test and this don't fail me

codeplay87 commented 8 years ago

@geirsagberg pull request fixed this issue so if you merged that in maybe the case.

odelvalle commented 8 years ago

Fixed and merge your pull request