Added more extension methods to ignore audit properties.

pull/4164/head
Halil İbrahim Kalkan 5 years ago
parent 6b25cfcaaa
commit dd35b19c4e

@ -12,11 +12,52 @@ namespace Volo.Abp.AutoMapper
return mappingExpression.ForMember(destinationMember, opts => opts.Ignore());
}
public static IMappingExpression<TSource, TDestination> IgnoreCreationTime<TSource, TDestination>(
public static IMappingExpression<TSource, TDestination> IgnoreHasCreationTimeProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IHasCreationTime
{
return mappingExpression.Ignore(x => x.CreationTime);
}
public static IMappingExpression<TSource, TDestination> IgnoreMayHaveCreatorProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IMayHaveCreator
{
return mappingExpression.Ignore(x => x.CreatorId);
}
public static IMappingExpression<TSource, TDestination> IgnoreCreationAuditedObjectProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : ICreationAuditedObject
{
return mappingExpression
.IgnoreHasCreationTimeProperties()
.IgnoreMayHaveCreatorProperties();
}
public static IMappingExpression<TSource, TDestination> IgnoreHasModificationTimeProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IHasModificationTime
{
return mappingExpression.Ignore(x => x.LastModificationTime);
}
public static IMappingExpression<TSource, TDestination> IgnoreModificationAuditedObjectProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IModificationAuditedObject
{
return mappingExpression
.IgnoreHasModificationTimeProperties()
.Ignore(x => x.LastModifierId);
}
public static IMappingExpression<TSource, TDestination> IgnoreAuditedObjectProperties<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> mappingExpression)
where TDestination : IAuditedObject
{
return mappingExpression
.IgnoreCreationAuditedObjectProperties()
.IgnoreModificationAuditedObjectProperties();
}
}
}

@ -12,7 +12,8 @@ namespace Volo.Abp.AutoMapper
public void Should_Ignore_Configured_Property()
{
var mapper = CreateMapper(
cfg => cfg.CreateMap<SimpleClass1, SimpleClass2>()
cfg => cfg
.CreateMap<SimpleClass1, SimpleClass2>()
.Ignore(x => x.Value2)
.Ignore(x => x.Value3)
);
@ -31,26 +32,33 @@ namespace Volo.Abp.AutoMapper
}
[Fact]
public void Should_Ignore_CreationTime()
public void Should_Ignore_Audit_Properties()
{
var mapper = CreateMapper(
cfg => cfg.CreateMap<SimpleClassWithCreationTime1, SimpleClassWithCreationTime2>()
.IgnoreCreationTime()
cfg => cfg
.CreateMap<SimpleClassAudited1, SimpleClassAudited2>()
.IgnoreAuditedObjectProperties()
);
var obj2 = mapper.Map<SimpleClassWithCreationTime2>(
new SimpleClassWithCreationTime1
var obj2 = mapper.Map<SimpleClassAudited2>(
new SimpleClassAudited1
{
CreationTime = DateTime.Now
CreationTime = DateTime.Now,
CreatorId = Guid.NewGuid(),
LastModificationTime = DateTime.Now,
LastModifierId = Guid.NewGuid()
}
);
obj2.CreationTime.ShouldBe(default);
obj2.CreatorId.ShouldBeNull();
obj2.LastModificationTime.ShouldBe(default);
obj2.LastModifierId.ShouldBeNull();
}
private static IMapper CreateMapper(Action<IMapperConfigurationExpression> configurer)
private static IMapper CreateMapper(Action<IMapperConfigurationExpression> configure)
{
var configuration = new MapperConfiguration(configurer);
var configuration = new MapperConfiguration(configure);
configuration.AssertConfigurationIsValid();
return configuration.CreateMapper();
}
@ -68,14 +76,20 @@ namespace Volo.Abp.AutoMapper
public string Value3 { get; set; }
}
public class SimpleClassWithCreationTime1 : IHasCreationTime
public class SimpleClassAudited1 : IAuditedObject
{
public DateTime CreationTime { get; set; }
public Guid? CreatorId { get; set; }
public DateTime? LastModificationTime { get; set; }
public Guid? LastModifierId { get; set; }
}
public class SimpleClassWithCreationTime2 : IHasCreationTime
public class SimpleClassAudited2 : IAuditedObject
{
public DateTime CreationTime { get; set; }
public Guid? CreatorId { get; set; }
public DateTime? LastModificationTime { get; set; }
public Guid? LastModifierId { get; set; }
}
}
}
Loading…
Cancel
Save