Skip to content

Commit

Permalink
add test check Current Work From ImplicitOperator to Class
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSvartz committed Sep 30, 2023
1 parent e0204a6 commit 279c326
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions src/Mapster.Tests/WhenMappingRecordRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,30 @@ public void TSousreIsObjectUpdateUseDynamicCast()
_result.X.ShouldBe(123);
}

TestClassPublicCtr SomemapWithDynamic(object source)
/// <summary>
/// https://github.com/MapsterMapper/Mapster/issues/569
/// </summary>
[TestMethod]
public void ImplicitOperatorCurrentWorkFromClass()
{
var dest = new TestClassPublicCtr { X = 321 };
var dest1 = source.Adapt(dest,source.GetType(),dest.GetType());

return dest;
var guid = Guid.NewGuid();

var pocoWithGuid1 = new PocoWithGuid { Id = guid };
var pocoWithId2 = new PocoWithId { Id = new Id(guid) };

var pocoWithId1 = pocoWithGuid1.Adapt<PocoWithId>();
var pocoWithGuid2 = pocoWithId2.Adapt<PocoWithGuid>();

pocoWithId1.Id.ToString().Equals(guid.ToString()).ShouldBeTrue();
pocoWithGuid2.Id.Equals(guid).ShouldBeTrue();


var _result = pocoWithId1.Adapt(pocoWithGuid2);

_result.Id.ToString().Equals(guid.ToString()).ShouldBeTrue(); // Guid value transmitted
object.ReferenceEquals(_result, pocoWithGuid2).ShouldBeTrue(); // Not created new instanse from class pocoWithGuid2
_result.ShouldBeOfType<PocoWithGuid>();

}


Expand All @@ -225,6 +243,7 @@ public void DetectFakeRecord()
var _destination = new FakeRecord { X = 300 };
var _result = _source.Adapt(_destination);
_destination.X.ShouldBe(200);

object.ReferenceEquals(_destination, _result).ShouldBeTrue();
}

Expand Down Expand Up @@ -271,11 +290,51 @@ TestClassPublicCtr Somemap(object source)

#endregion NowNotWorking


#region TestMethods

TestClassPublicCtr SomemapWithDynamic(object source)
{
var dest = new TestClassPublicCtr { X = 321 };
var dest1 = source.Adapt(dest, source.GetType(), dest.GetType());

object.ReferenceEquals(dest,dest1).ShouldBeTrue(); // Is not new instanse

return dest;
}


#endregion TestMethods
}


#region TestClasses

class PocoWithGuid
{
public Guid Id { get; init; }
}

class PocoWithId
{
public Id Id { get; init; }
}

class Id
{
private readonly Guid _guid;

public Id(Guid id) => _guid = id;

public static implicit operator Id(Guid value) => new(value);
public static implicit operator Guid(Id value) => value._guid;

public override string ToString() => _guid.ToString();
}




public class FakeRecord
{
protected FakeRecord(FakeRecord fake) { }
Expand Down

0 comments on commit 279c326

Please sign in to comment.