Skip to content

Commit

Permalink
add mapping init PropertyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSvartz committed Jan 4, 2025
1 parent cea3deb commit 4deea1a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Mapster.Tests/WhenMappingInitProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

namespace Mapster.Tests;

[TestClass]
public class WhenMappingInitProperty
{

#region Tests
/// <summary>
/// From Issue #672
/// https://github.com/MapsterMapper/Mapster/issues/672
/// </summary>
[TestMethod]
public void WhenMappingToHiddenandNewInitFieldDestination()
{
var source = new Source672() { Id = 156};
var c = source.Adapt<BDestination>();
var s = source.Adapt(new BDestination());

((ADestination)c).Id.ShouldBe(156);
s.Id.ShouldBe(156);
}

#endregion Tests


#region TestClasses

class Source672
{
public long Id { get; init; }
}

class ADestination
{
public int Id { get; init; }
}

class BDestination : ADestination
{
public new long Id { get; init; }
}


#endregion TestClasses
}

0 comments on commit 4deea1a

Please sign in to comment.