Skip to content

MapDynamic Enum Values causes error. #19

@codeplay87

Description

@codeplay87

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions