Skip to content

Commit affeed4

Browse files
committed
test: add constructor mapping with inheritance
1 parent 328308b commit affeed4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/IntegrationTests/ExplicitExpansion/DisableExplicitExpansion.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,45 @@ public void Should_work() {
108108
dto = ProjectTo<Dto>(context.Entities, null, d => d.Name).Single();
109109
dto.Name.ShouldBe("Name");
110110
}
111+
}
112+
113+
public class ConstructorWithInheritanceNoExplicitExpansion : IntegrationTest<ConstructorWithInheritanceNoExplicitExpansion.DatabaseInitializer> {
114+
public class Entity {
115+
public int Id { get; set; }
116+
public string Name { get; set; }
117+
}
118+
119+
public class SubEntity : Entity {
120+
public string Caption { get; set; }
121+
}
122+
123+
record Dto(string Name) { }
124+
record SubDto(string Name, string Caption) : Dto(Name) { }
125+
126+
public class Context : LocalDbContext {
127+
public DbSet<SubEntity> Entities { get; set; }
128+
}
129+
public class DatabaseInitializer : DropCreateDatabaseAlways<Context> {
130+
protected override void Seed(Context context) {
131+
context.Entities.Add(new() { Name = "Name", Caption = "Caption" });
132+
base.Seed(context);
133+
}
134+
}
135+
protected override MapperConfiguration CreateConfiguration() => new(c => {
136+
c.CreateMap<Entity, Dto>().ForCtorParam("Name", o => o.ExplicitExpansion());
137+
c.CreateMap<SubEntity, SubDto>()
138+
.IncludeBase<Entity, Dto>()
139+
.ForCtorParam("Name", o => o.ExplicitExpansion(false))
140+
.ForCtorParam("Caption", o => o.ExplicitExpansion(false));
141+
});
142+
[Fact]
143+
public void Should_work() {
144+
using var context = new Context();
145+
var dto = ProjectTo<SubDto>(context.Entities).Single();
146+
dto.Name.ShouldBe("Name");
147+
dto.Caption.ShouldBe("Caption");
148+
dto = ProjectTo<SubDto>(context.Entities, null, d => d.Name, d => d.Caption).Single();
149+
dto.Name.ShouldBe("Name");
150+
dto.Caption.ShouldBe("Caption");
151+
}
111152
}

0 commit comments

Comments
 (0)