Browse Source

Added more automapper tests.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
5afe67a976
  1. 40
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Basic_Tests.cs
  2. 17
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Registration_Tests.cs
  3. 12
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapper_Inheritance_Tests.cs
  4. 9
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntity.cs
  5. 10
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyEntityDto.cs
  6. 9
      test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/SampleClasses/MyNotMappedDto.cs

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

17
test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AbpAutoMapperModule_Registration_Tests.cs

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

12
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 { }
}
}

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

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

9
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; }
}
}
Loading…
Cancel
Save