12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System.Xml;
- using Xunit;
- namespace VCommon.VAutoMapper.Tests
- {
- public class IgnoreMappingTest
- {
- [AutoMapFrom(typeof(Entity))]
- [AutoMapTo(typeof(Entity))]
- public class Dto
- {
- public int Id { get; set; }
- [AutoMapperIgnore]
- public string BothIgnoreValue { get; set; }
- [AutoMapperIgnore(AutoMapperIgnoreDirection.From)]
- public string ToDtoIgnoreValue { get; set; }
- [AutoMapperIgnore(AutoMapperIgnoreDirection.To)]
- public string ToEntityIgnoreValue { get; set; }
- }
- public class Entity
- {
- public int Id { get; set; }
- public string BothIgnoreValue { get; set; }
- public string ToDtoIgnoreValue { get; set; }
- public string ToEntityIgnoreValue { get; set; }
- }
- [Fact]
- public void DtoToEntityTest()
- {
- var dto = new Dto
- {
- Id = 114,
- BothIgnoreValue = "ShouldIgnoreBoth",
- ToDtoIgnoreValue = "ShouldIgnoreToDto",
- ToEntityIgnoreValue = "ShouldIgnoreToEntity",
- };
- var entity = dto.MapTo<Entity>();
- Assert.Equal(dto.Id, entity.Id);
- Assert.Equal(dto.ToDtoIgnoreValue, entity.ToDtoIgnoreValue);
- Assert.NotEqual(dto.BothIgnoreValue, entity.BothIgnoreValue);
- Assert.NotEqual(dto.ToEntityIgnoreValue, entity.ToEntityIgnoreValue);
- }
- [Fact]
- public void EntityToDtoTest()
- {
- var entity = new Entity
- {
- Id = 514,
- BothIgnoreValue = "ShouldIgnoreBoth",
- ToDtoIgnoreValue = "ShouldIgnoreToDto",
- ToEntityIgnoreValue = "ShouldIgnoreToEntity",
- };
- var dto = entity.MapTo<Dto>();
- Assert.Equal(entity.Id, dto.Id);
- Assert.Equal(entity.ToEntityIgnoreValue, dto.ToEntityIgnoreValue);
- Assert.NotEqual(entity.BothIgnoreValue, dto.BothIgnoreValue);
- Assert.NotEqual(entity.ToDtoIgnoreValue, dto.ToDtoIgnoreValue);
- }
- [Fact]
- public void EntityUpdateDtoTest()
- {
- var dto = new Dto
- {
- Id = 114,
- BothIgnoreValue = "ShouldIgnoreBoth",
- ToDtoIgnoreValue = "ShouldIgnoreToDto",
- ToEntityIgnoreValue = "ShouldIgnoreToEntity",
- };
- var entity = new Entity
- {
- Id = 514,
- BothIgnoreValue = "BOTH",
- ToDtoIgnoreValue = "ETD",
- ToEntityIgnoreValue = "DTE",
- };
- var r = dto.MapTo(entity);
- Assert.Equal(dto.Id, entity.Id);
- Assert.Equal(dto.ToDtoIgnoreValue, entity.ToDtoIgnoreValue);
- Assert.NotEqual(dto.ToEntityIgnoreValue, entity.ToEntityIgnoreValue);
- Assert.NotEqual(dto.BothIgnoreValue, entity.BothIgnoreValue);
- }
- }
- }
|