Skip to content

Unable to map struct from object in another object #615

@jankoci91

Description

@jankoci91

Hi! Am I right that failing assert in this test means bug?

In version 6.5.1 it works fine.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

namespace Mapster.Tests
{
    [TestClass]
    public class WhenMappingStructInObject
    {
        class Destination
        {
            public TestStruct TestStruct { get; set; }
        }

        class SourceWithClass
        {
            public SourceWithStruct SourceWithStruct { get; set; }
        }

        class SourceWithStruct
        {
            public TestStruct TestStruct { get; set; }
        }

        struct TestStruct
        {
            public string Property { get; }

            public TestStruct(string property) : this()
            {
                Property = property;
            }
        }

        [TestMethod]
        public void TestMapping()
        {
            TypeAdapterConfig<SourceWithClass, Destination>
                .ForType()
                .Map(x => x.TestStruct, x => x.SourceWithStruct.TestStruct);

            var source = new SourceWithClass
            {
                SourceWithStruct = new SourceWithStruct
                {
                    TestStruct = new TestStruct("A")
                }
            };

            var destination = source.Adapt<Destination>();

            destination.TestStruct.Property.ShouldBe("A");
        }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions