mirror of https://github.com/abpframework/abp.git
7 changed files with 144 additions and 1 deletions
@ -0,0 +1,16 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.test.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.ObjectExtending\Volo.Abp.ObjectExtending.csproj" /> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
public abstract class AbpObjectExtendingTestBase : AbpIntegratedTest<AbpObjectExtendingTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.ObjectExtending.TestObjects; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
[DependsOn(typeof(AbpObjectExtendingModule))] |
|||
public class AbpObjectExtendingTestModule : AbpModule |
|||
{ |
|||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
|||
|
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
OneTimeRunner.Run(() => |
|||
{ |
|||
ObjectExtensionManager.Instance |
|||
.AddOrUpdateProperty<ExtensibleTestPerson, string>("Name") |
|||
.AddOrUpdateProperty<ExtensibleTestPerson, int>("Age") |
|||
.AddOrUpdateProperty<ExtensibleTestPersonDto, string>("Name") |
|||
.AddOrUpdateProperty<ExtensibleTestPersonDto, int>("ChildCount"); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
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; |
|||
|
|||
public HasExtraPropertiesObjectExtendingExtensions_Tests() |
|||
{ |
|||
_person = new ExtensibleTestPerson() |
|||
.SetProperty("Name", "John") |
|||
.SetProperty("Age", 42) |
|||
.SetProperty("ChildCount", 2) |
|||
.SetProperty("Sex", "male"); |
|||
} |
|||
|
|||
[Fact] |
|||
public void MapExtraPropertiesTo_Should_Only_Map_Defined_Properties_By_Default() |
|||
{ |
|||
var personDto = new ExtensibleTestPersonDto(); |
|||
|
|||
_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
|
|||
} |
|||
|
|||
[Fact] |
|||
public void MapExtraPropertiesTo_Should_Only_Map_Source_Defined_Properties_If_Requested() |
|||
{ |
|||
var personDto = new ExtensibleTestPersonDto(); |
|||
|
|||
_person.MapExtraPropertiesTo(personDto, MappingPropertyDefinitionCheck.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
|
|||
} |
|||
|
|||
[Fact] |
|||
public void MapExtraPropertiesTo_Should_Only_Map_Destination_Defined_Properties_If_Requested() |
|||
{ |
|||
var personDto = new ExtensibleTestPersonDto(); |
|||
|
|||
_person.MapExtraPropertiesTo(personDto, MappingPropertyDefinitionCheck.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
|
|||
} |
|||
|
|||
[Fact] |
|||
public void MapExtraPropertiesTo_Should_Copy_all_With_No_Property_Definition_Check() |
|||
{ |
|||
var personDto = new ExtensibleTestPersonDto(); |
|||
|
|||
_person.MapExtraPropertiesTo(personDto, MappingPropertyDefinitionCheck.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"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.ObjectExtending.TestObjects |
|||
{ |
|||
public class ExtensibleTestPerson : ExtensibleObject |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.ObjectExtending.TestObjects |
|||
{ |
|||
public class ExtensibleTestPersonDto : ExtensibleObject |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue