mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
3.5 KiB
74 lines
3.5 KiB
using Shouldly;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.ObjectExtending.TestObjects;
|
|
using Xunit;
|
|
|
|
namespace Volo.Abp.ObjectExtending
|
|
{
|
|
public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtendingTestBase
|
|
{
|
|
private readonly ExtensibleTestPerson _person;
|
|
private readonly ExtensibleTestPersonDto _personDto;
|
|
|
|
public HasExtraPropertiesObjectExtendingExtensions_Tests()
|
|
{
|
|
_person = new ExtensibleTestPerson()
|
|
.SetProperty("Name", "John")
|
|
.SetProperty("Age", 42)
|
|
.SetProperty("ChildCount", 2)
|
|
.SetProperty("Sex", "male");
|
|
|
|
_personDto = new ExtensibleTestPersonDto()
|
|
.SetProperty("ExistingDtoProperty", "existing-value");
|
|
}
|
|
|
|
[Fact]
|
|
public void MapExtraPropertiesTo_Should_Only_Map_Defined_Properties_By_Default()
|
|
{
|
|
_person.MapExtraPropertiesTo(_personDto);
|
|
|
|
_personDto.GetProperty<string>("Name").ShouldBe("John"); //Defined in both classes
|
|
_personDto.HasProperty("Age").ShouldBeFalse(); //Not defined on the destination
|
|
_personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source
|
|
_personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes
|
|
_personDto.GetProperty<string>("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values
|
|
}
|
|
|
|
[Fact]
|
|
public void MapExtraPropertiesTo_Should_Only_Map_Source_Defined_Properties_If_Requested()
|
|
{
|
|
_person.MapExtraPropertiesTo(_personDto, MappingPropertyDefinitionChecks.Source);
|
|
|
|
_personDto.GetProperty<string>("Name").ShouldBe("John"); //Defined in both classes
|
|
_personDto.GetProperty<int>("Age").ShouldBe(42); //Defined in source
|
|
_personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source
|
|
_personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes
|
|
_personDto.GetProperty<string>("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values
|
|
}
|
|
|
|
[Fact]
|
|
public void MapExtraPropertiesTo_Should_Only_Map_Destination_Defined_Properties_If_Requested()
|
|
{
|
|
_person.MapExtraPropertiesTo(_personDto, MappingPropertyDefinitionChecks.Destination);
|
|
|
|
_personDto.GetProperty<string>("Name").ShouldBe("John"); //Defined in both classes
|
|
_personDto.GetProperty<int>("ChildCount").ShouldBe(2); //Defined in destination
|
|
_personDto.HasProperty("Age").ShouldBeFalse(); //Not defined in destination
|
|
_personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes
|
|
_personDto.GetProperty<string>("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values
|
|
}
|
|
|
|
[Fact]
|
|
public void MapExtraPropertiesTo_Should_Copy_all_With_No_Property_Definition_Check()
|
|
{
|
|
_person.MapExtraPropertiesTo(_personDto, MappingPropertyDefinitionChecks.None);
|
|
|
|
_personDto.GetProperty<string>("Name").ShouldBe("John");
|
|
_personDto.GetProperty<int>("Age").ShouldBe(42);
|
|
_personDto.GetProperty<int>("ChildCount").ShouldBe(2);
|
|
_personDto.GetProperty<string>("Sex").ShouldBe("male");
|
|
_personDto.GetProperty<string>("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values
|
|
}
|
|
}
|
|
}
|