mirror of https://github.com/abpframework/abp.git
6 changed files with 75 additions and 22 deletions
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Shouldly; |
|||
using Volo.Abp.AutoMapper.SampleClasses; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.TestBase; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AutoMapper |
|||
{ |
|||
public class AbpAutoMapperModule_Basic_Tests : AbpIntegratedTest<AutoMapperTestModule> |
|||
{ |
|||
[Fact] |
|||
public void Should_Replace_ObjectMapper() |
|||
{ |
|||
var objectMapper = ServiceProvider.GetRequiredService<IObjectMapper>(); |
|||
Assert.True(objectMapper is AutoMapperObjectMapper); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Map_Objects_With_AutoMap_Attributes() |
|||
{ |
|||
var objectMapper = ServiceProvider.GetRequiredService<IObjectMapper>(); |
|||
|
|||
var dto = objectMapper.Map<MyEntityDto>(new MyEntity {Number = 42}); |
|||
dto.Number.ShouldBe(42); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Map_Objects_With_AutoMap_Attributes() |
|||
{ |
|||
var objectMapper = ServiceProvider.GetRequiredService<IObjectMapper>(); |
|||
|
|||
Assert.ThrowsAny<Exception>(() => |
|||
{ |
|||
objectMapper.Map<MyNotMappedDto>(new MyEntity {Number = 42}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.TestBase; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AutoMapper |
|||
{ |
|||
public class AbpAutoMapperModule_Registration_Tests : AbpIntegratedTest<AutoMapperTestModule> |
|||
{ |
|||
[Fact] |
|||
public void Should_Replace_ObjectMapper() |
|||
{ |
|||
var objectMapper = ServiceProvider.GetRequiredService<IObjectMapper>(); |
|||
Assert.True(objectMapper is AutoMapperObjectMapper); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.AutoMapper.SampleClasses |
|||
{ |
|||
public class MyEntity : Entity |
|||
{ |
|||
public int Number { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
|
|||
namespace Volo.Abp.AutoMapper.SampleClasses |
|||
{ |
|||
[AutoMap(typeof(MyEntity))] |
|||
public class MyEntityDto : EntityDto |
|||
{ |
|||
public int Number { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
|
|||
namespace Volo.Abp.AutoMapper.SampleClasses |
|||
{ |
|||
public class MyNotMappedDto : EntityDto |
|||
{ |
|||
public int Number { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue