From 377261312f4a7a94770dabefaab84aff19e3488e Mon Sep 17 00:00:00 2001 From: wuyangfan Date: Mon, 25 May 2026 15:15:08 +0800 Subject: [PATCH] test: cover MapToTarget for types with read-only base properties (#918) Regression test for same-type Adapt(target) when the destination type inherits read-only members alongside writable properties. Co-authored-by: Cursor --- ...gMapToTargetMixedReadOnlyBaseRegression.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Mapster.Tests/WhenMappingMapToTargetMixedReadOnlyBaseRegression.cs diff --git a/src/Mapster.Tests/WhenMappingMapToTargetMixedReadOnlyBaseRegression.cs b/src/Mapster.Tests/WhenMappingMapToTargetMixedReadOnlyBaseRegression.cs new file mode 100644 index 00000000..d83f7f06 --- /dev/null +++ b/src/Mapster.Tests/WhenMappingMapToTargetMixedReadOnlyBaseRegression.cs @@ -0,0 +1,38 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; + +namespace Mapster.Tests +{ + /// + /// https://github.com/MapsterMapper/Mapster/issues/918 + /// + [TestClass] + public class WhenMappingMapToTargetMixedReadOnlyBaseRegression + { + [TestMethod] + public void MapToTarget_SameType_WithMixedReadOnlyBaseProperties_UpdatesDestination() + { + var source = new Station918 { RowNo = 100, Location = "Source" }; + var destination = new Station918 { RowNo = 0, Location = "Destination" }; + + source.Adapt(destination); + + destination.RowNo.ShouldBe(100); + destination.Location.ShouldBe("Source"); + } + + public abstract class ValidationBase918 + { + public bool HasErrors { get; } + + public string? ErrorMessage { get; } + } + + public class Station918 : ValidationBase918 + { + public int RowNo { get; set; } + + public string Location { get; set; } = string.Empty; + } + } +}