Browse Source

Add source immutability test for Mapperly single-parameter Map

pull/25891/head
maliming 2 weeks ago
parent
commit
58f97db029
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 18
      framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/MapExtraPropertiesDefaultSeed_Tests.cs

18
framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/MapExtraPropertiesDefaultSeed_Tests.cs

@ -31,6 +31,21 @@ public class MapExtraPropertiesDefaultSeed_Tests : AbpIntegratedTest<MapperlyTes
dto.GetProperty("DtoOnly").ShouldBeNull();
}
[Fact]
public void Single_Parameter_Map_Should_Not_Change_The_Source_Extra_Properties()
{
var entity = new ExtensibleSeededEntity { Id = Guid.NewGuid() }
.SetProperty("Tag", "ok")
.SetProperty("CreatedBy", "leaked");
var originalReference = entity.ExtraProperties;
_objectMapper.Map<ExtensibleSeededEntity, ExtensibleSeededDto>(entity);
ReferenceEquals(entity.ExtraProperties, originalReference).ShouldBeTrue();
entity.GetProperty<string>("Tag").ShouldBe("ok");
entity.GetProperty<string>("CreatedBy").ShouldBe("leaked");
}
[Fact]
public void Single_Parameter_Map_Should_Not_Seed_Defaults_When_Destination_Disables_Them()
{
@ -53,8 +68,7 @@ public class MapExtraPropertiesDefaultSeed_Tests : AbpIntegratedTest<MapperlyTes
var dto = _objectMapper.Map<ExtensibleSeededEntity, ExtensibleNonSeededDto>(entity);
dto.GetProperty<string>("Tag").ShouldBe("ok"); //Defined in both classes
dto.HasProperty("DtoOnly").ShouldBeTrue(); //Reset to the registered default value
dto.GetProperty("DtoOnly").ShouldBeNull(); //The source value must not leak
dto.GetProperty("DtoOnly").ShouldBeNull(); //Not defined in the source, the source value must not leak
}
[Fact]

Loading…
Cancel
Save