diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Basic_Tests.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Basic_Tests.cs new file mode 100644 index 0000000000..57215028b4 --- /dev/null +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Basic_Tests.cs @@ -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 + { + [Fact] + public void Should_Replace_ObjectMapper() + { + var objectMapper = ServiceProvider.GetRequiredService(); + Assert.True(objectMapper is AutoMapperObjectMapper); + } + + [Fact] + public void Should_Map_Objects_With_AutoMap_Attributes() + { + var objectMapper = ServiceProvider.GetRequiredService(); + + var dto = objectMapper.Map(new MyEntity {Number = 42}); + dto.Number.ShouldBe(42); + } + + [Fact] + public void Should_Not_Map_Objects_With_AutoMap_Attributes() + { + var objectMapper = ServiceProvider.GetRequiredService(); + + Assert.ThrowsAny(() => + { + objectMapper.Map(new MyEntity {Number = 42}); + }); + } + } +} diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Registration_Tests.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Registration_Tests.cs deleted file mode 100644 index 8ee6e6368a..0000000000 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Registration_Tests.cs +++ /dev/null @@ -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 - { - [Fact] - public void Should_Replace_ObjectMapper() - { - var objectMapper = ServiceProvider.GetRequiredService(); - Assert.True(objectMapper is AutoMapperObjectMapper); - } - } -} diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapper_Inheritance_Tests.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapper_Inheritance_Tests.cs index c1f823a543..8d010d829f 100644 --- a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapper_Inheritance_Tests.cs +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapper_Inheritance_Tests.cs @@ -54,20 +54,22 @@ namespace Volo.Abp.AutoMapper target2.Value.ShouldBe("42"); } - public class Entity + private class Entity { public string Value { get; set; } } - public class DerivedEntity : Entity { } - public class EntityProxy : DerivedEntity { } + + private class DerivedEntity : Entity { } + + private class EntityProxy : DerivedEntity { } [AutoMapFrom(typeof(Entity))] - public class EntityDto + private class EntityDto { public string Value { get; set; } } [AutoMapFrom(typeof(DerivedEntity))] - public class DerivedEntityDto : EntityDto { } + private class DerivedEntityDto : EntityDto { } } } diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs new file mode 100644 index 0000000000..0a0b2f6bf4 --- /dev/null +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.AutoMapper.SampleClasses +{ + public class MyEntity : Entity + { + public int Number { get; set; } + } +} diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs new file mode 100644 index 0000000000..3b5080a1da --- /dev/null +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs @@ -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; } + } +} \ No newline at end of file diff --git a/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs new file mode 100644 index 0000000000..5cb1f531c1 --- /dev/null +++ b/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Application.Services.Dtos; + +namespace Volo.Abp.AutoMapper.SampleClasses +{ + public class MyNotMappedDto : EntityDto + { + public int Number { get; set; } + } +} \ No newline at end of file