Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove override and corrected test
  • Loading branch information
Angelinsky7 committed Aug 4, 2023
commit bc835bfd40f341b5cd07cce47ef1c9c7ae60d020
Binary file added SqlLocalDB.msi
Binary file not shown.
Binary file added SqlLocalDBInstall.log
Binary file not shown.
8 changes: 6 additions & 2 deletions src/AutoMapper/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMappe
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.PropertyMapAction> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<System.Action<AutoMapper.PropertyMap, AutoMapper.IMemberConfigurationExpression>> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<System.Action<AutoMapper.PropertyMap, AutoMapper.IMemberConfigurationExpression>> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.Configuration.ICtorParamConfigurationExpression.ExplicitExpansion()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.IProjectionMemberConfiguration<TSource, TDestination, TMember>.ExplicitExpansion()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public void AutoMapper.IProjectionMemberConfiguration<TSource, TDestination, TMember>.ExplicitExpansion()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.IProjectionMemberConfiguration<TSource, TDestination, TMember>.ExplicitExpansion(System.Boolean)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.Configuration.ICtorParamConfigurationExpression.ExplicitExpansion(System.Boolean)' is present in the implementation but not in the contract.
MembersMustExist : Member 'public void AutoMapper.Configuration.MemberConfigurationExpression<TSource, TDestination, TMember>.ExplicitExpansion()' does not exist in the implementation but it does exist in the contract.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.IgnoreAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.MapAtRuntimeAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.MappingOrderAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
Expand All @@ -13,4 +17,4 @@ CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMappe
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueConverterAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueResolverAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
TypeCannotChangeClassification : Type 'AutoMapper.Execution.TypeMapPlanBuilder' is a 'ref struct' in the implementation but is a 'struct' in the contract.
Total Issues: 14
Total Issues: 18
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ public interface IProjectionMemberConfiguration<TSource, TDestination, TMember>
/// Ignore this member for LINQ projections unless explicitly expanded during projection
/// </summary>
/// <param name="value">Is explicitExpansion active</param>
/// <param name="overrideExpansion">Does explicitExpansion can override settings already set by another ExplicitExpansion call</param>
void ExplicitExpansion(bool value = true, Boolean overrideExpansion = true);
void ExplicitExpansion(bool value = true);
/// <summary>
/// Apply a transformation function after any resolved destination member value with the given type
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void PreConditionCore(Expression<Func<TSource, TDestination, ResolutionC
PropertyMapActions.Add(pm => pm.PreCondition = expr);
public void AddTransform(Expression<Func<TMember, TMember>> transformer) =>
PropertyMapActions.Add(pm => pm.AddValueTransformation(new ValueTransformerConfiguration(pm.DestinationType, transformer)));
public void ExplicitExpansion(bool value = true, bool overrideExpansion = true) => PropertyMapActions.Add(pm => pm.ExplicitExpansion = overrideExpansion || pm.ExplicitExpansion == null ? value : pm.ExplicitExpansion);
public void ExplicitExpansion(bool value = true) => PropertyMapActions.Add(pm => pm.ExplicitExpansion = pm.ExplicitExpansion == null ? value : pm.ExplicitExpansion);
public void Ignore() => Ignore(ignorePaths: true);
public void Ignore(bool ignorePaths)
{
Expand Down
59 changes: 7 additions & 52 deletions src/IntegrationTests/ExplicitExpansion/DisableExplicitExpansion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ public class Source
public String Name { get; set; }
public String Code { get; set; }
}
public class DtoWithoutOverride
public class Dto
{
public String Name { get; set; }
public String Code { get; set; }
public Nullable<int> Desc { get; set; }
}

public class DtoWithOverride {
public String Name { get; set; }
public String Code { get; set; }
public Nullable<int> Desc { get; set; }
}

public class Context : LocalDbContext
{
public List<string> Log = new List<string>();
Expand Down Expand Up @@ -55,72 +49,33 @@ protected override void Seed(Context context)

protected override MapperConfiguration CreateConfiguration() => new(cfg =>
{
cfg.CreateMap<Source, DtoWithOverride>()
.ForMember(dto => dto.Desc, conf => conf.ExplicitExpansion())
.ForMember(dto => dto.Name, conf => conf.MapFrom(src => src.Name))
cfg.CreateMap<Source, Dto>()
.ForMember(dto => dto.Code, conf => conf.ExplicitExpansion(false))
.ForAllMembers(conf => conf.ExplicitExpansion())
;

cfg.CreateMap<Source, DtoWithoutOverride>()
.ForMember(dto => dto.Desc, conf => conf.ExplicitExpansion())
.ForMember(dto => dto.Name, conf => conf.MapFrom(src => src.Name))
.ForMember(dto => dto.Code, conf => conf.ExplicitExpansion(false))
.ForAllMembers(conf => conf.ExplicitExpansion(overrideExpansion: false))
;});

[Fact]
public void NoExplicitExpansion() {
public void Should_CodeBeExpanded() {
using (var ctx = new Context()) {
var dto = ProjectTo<DtoWithOverride>(ctx.Sources).ToList().First();
var dto = ProjectTo<Dto>(ctx.Sources).ToList().First();
var sqlSelect = ctx.GetLastSelectSqlLogEntry();
sqlSelect.SqlFromShouldStartWith(nameof(ctx.Sources));
sqlSelect.ShouldNotContain("JOIN");

sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Name)); dto.Name.ShouldBeNull();
sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Code)); dto.Code.ShouldBeNull();
sqlSelect.SqlShouldSelectColumn(nameof(_iqf.Code)); dto.Code.ShouldBe(_iqf.Code);
sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Desc)); dto.Desc.ShouldBeNull();
}
}

[Fact]
public void OnlyExplicitExpansionForCode()
{
using (var ctx = new Context())
{
var dto = ProjectTo<DtoWithoutOverride>(ctx.Sources).ToList().First();
var sqlSelect = ctx.GetLastSelectSqlLogEntry();
sqlSelect.SqlFromShouldStartWith(nameof(ctx.Sources));
sqlSelect.ShouldNotContain("JOIN");

sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Name)); dto.Name.ShouldBeNull();
sqlSelect.SqlShouldSelectColumn(nameof(_iqf.Code)); dto.Code.ShouldNotBeNull();
sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Desc)); dto.Desc.ShouldBeNull();
}
}

[Fact]
public void ProjectNoExplicit() {
public void Should_NameAndCodeBeExpanded() {
using (var ctx = new Context()) {
var dto = ProjectTo<DtoWithOverride>(ctx.Sources, null, _ => _.Name).First();
var dto = ProjectTo<Dto>(ctx.Sources, null, _ => _.Name).First();
var sqlSelect = ctx.GetLastSelectSqlLogEntry();
sqlSelect.SqlFromShouldStartWith(nameof(ctx.Sources));
sqlSelect.ShouldNotContain("JOIN");

dto.Name.ShouldBe(_iqf.Name); sqlSelect.SqlShouldSelectColumn(nameof(_iqf.Name));
dto.Code.ShouldBeNull(_iqf.Code); sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Code));
dto.Desc.ShouldBeNull(); sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Desc));
}
}

[Fact]
public void ProjectWithCodeImplicit() {
using (var ctx = new Context()) {
var dto = ProjectTo<DtoWithoutOverride>(ctx.Sources, null, _ => _.Name).First();
var sqlSelect = ctx.GetLastSelectSqlLogEntry();
sqlSelect.SqlFromShouldStartWith(nameof(ctx.Sources));
sqlSelect.ShouldNotContain("JOIN");

dto.Name.ShouldBe(_iqf.Name); sqlSelect.SqlShouldSelectColumn(nameof(_iqf.Name));
dto.Code.ShouldBe(_iqf.Code); sqlSelect.SqlShouldSelectColumn(nameof(_iqf.Code));
dto.Desc.ShouldBeNull(); sqlSelect.SqlShouldNotSelectColumn(nameof(_iqf.Desc));
Expand Down