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.
abp/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Basic_T...

41 lines
1.2 KiB

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});
});
}
}
}