Browse Source

Implemented extension methods to ignore all audited properties for automapper.

pull/4164/head
Halil İbrahim Kalkan 6 years ago
parent
commit
66d53eff82
  1. 34
      framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperExpressionExtensions.cs
  2. 20
      framework/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapperExpressionExtensions_Tests.cs

34
framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperExpressionExtensions.cs

@ -59,5 +59,39 @@ namespace Volo.Abp.AutoMapper
.IgnoreCreationAuditedObjectProperties()
.IgnoreModificationAuditedObjectProperties();
}
public static IMappingExpression<TSource, TDestination> IgnoreSoftDeleteProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : ISoftDelete
{
return mappingExpression.Ignore(x => x.IsDeleted);
}
public static IMappingExpression<TSource, TDestination> IgnoreHasDeletionTimeProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IHasDeletionTime
{
return mappingExpression
.IgnoreSoftDeleteProperties()
.Ignore(x => x.DeletionTime);
}
public static IMappingExpression<TSource, TDestination> IgnoreDeletionAuditedObjectProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IDeletionAuditedObject
{
return mappingExpression
.IgnoreHasDeletionTimeProperties()
.Ignore(x => x.DeleterId);
}
public static IMappingExpression<TSource, TDestination> IgnoreFullAuditedObjectProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IFullAuditedObject
{
return mappingExpression
.IgnoreAuditedObjectProperties()
.IgnoreDeletionAuditedObjectProperties();
}
}
}

20
framework/test/Volo.Abp.AutoMapper.Tests/Volo/Abp/AutoMapper/AutoMapperExpressionExtensions_Tests.cs

@ -37,7 +37,7 @@ namespace Volo.Abp.AutoMapper
var mapper = CreateMapper(
cfg => cfg
.CreateMap<SimpleClassAudited1, SimpleClassAudited2>()
.IgnoreAuditedObjectProperties()
.IgnoreFullAuditedObjectProperties()
);
var obj2 = mapper.Map<SimpleClassAudited2>(
@ -46,7 +46,10 @@ namespace Volo.Abp.AutoMapper
CreationTime = DateTime.Now,
CreatorId = Guid.NewGuid(),
LastModificationTime = DateTime.Now,
LastModifierId = Guid.NewGuid()
LastModifierId = Guid.NewGuid(),
DeleterId = Guid.NewGuid(),
DeletionTime = DateTime.Now,
IsDeleted = true
}
);
@ -54,6 +57,9 @@ namespace Volo.Abp.AutoMapper
obj2.CreatorId.ShouldBeNull();
obj2.LastModificationTime.ShouldBe(default);
obj2.LastModifierId.ShouldBeNull();
obj2.DeleterId.ShouldBeNull();
obj2.DeletionTime.ShouldBeNull();
obj2.IsDeleted.ShouldBeFalse();
}
private static IMapper CreateMapper(Action<IMapperConfigurationExpression> configure)
@ -76,20 +82,26 @@ namespace Volo.Abp.AutoMapper
public string Value3 { get; set; }
}
public class SimpleClassAudited1 : IAuditedObject
public class SimpleClassAudited1 : IFullAuditedObject
{
public DateTime CreationTime { get; set; }
public Guid? CreatorId { get; set; }
public DateTime? LastModificationTime { get; set; }
public Guid? LastModifierId { get; set; }
public bool IsDeleted { get; set; }
public DateTime? DeletionTime { get; set; }
public Guid? DeleterId { get; set; }
}
public class SimpleClassAudited2 : IAuditedObject
public class SimpleClassAudited2 : IFullAuditedObject
{
public DateTime CreationTime { get; set; }
public Guid? CreatorId { get; set; }
public DateTime? LastModificationTime { get; set; }
public Guid? LastModifierId { get; set; }
public bool IsDeleted { get; set; }
public DateTime? DeletionTime { get; set; }
public Guid? DeleterId { get; set; }
}
}
}
Loading…
Cancel
Save