Skip to content

Commit 3dbd6b5

Browse files
committed
Test Lazy Inherits
1 parent f922b45 commit 3dbd6b5

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/Mapster.Tests/WhenMappingWithExplicitInheritance.cs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,77 @@ public void Invalid_Destination_Cast_Throws_Exception()
130130

131131
}
132132

133+
[TestMethod]
134+
public void InheritsLasyLoad__IsWork()
135+
{
136+
TypeAdapterConfig<DerivedPoco, DerivedDto>.NewConfig()
137+
.Inherits<SimplePoco, SimpleDto>()
138+
.Compile();
139+
140+
TypeAdapterConfig<SimplePoco, SimpleDto>.NewConfig()
141+
.Inherits<RootPoco, RootDto>()
142+
.Ignore(dest => dest.Name)
143+
.Compile();
144+
145+
TypeAdapterConfig<RootPoco, RootDto>.NewConfig()
146+
.Map(dest => dest.NumberDto, src => 42)
147+
.Compile();
148+
149+
var source = new DerivedPoco
150+
{
151+
Id = new Guid(),
152+
Name = "SourceName"
153+
};
154+
155+
var dto = TypeAdapter.Adapt<DerivedDto>(source);
156+
157+
dto.Id.ShouldBe(source.Id);
158+
dto.Name.ShouldBe("SourceName"); // Inherits Ignore not work
159+
dto.NumberDto.ShouldBe(0); // Inherits not work
160+
161+
Setup(); // clean config
162+
163+
TypeAdapterConfig<DerivedPoco, DerivedDto>.NewConfig()
164+
.InheritsLazy<SimplePoco, SimpleDto>()
165+
.Compile();
166+
167+
TypeAdapterConfig<SimplePoco, SimpleDto>.NewConfig()
168+
.InheritsLazy<RootPoco, RootDto>()
169+
.Ignore(dest => dest.Name)
170+
.Compile();
171+
172+
TypeAdapterConfig<RootPoco, RootDto>.NewConfig()
173+
.Map(dest => dest.NumberDto, src => 42)
174+
.Compile();
175+
176+
dto = TypeAdapter.Adapt<DerivedDto>(source);
177+
178+
dto.Id.ShouldBe(source.Id);
179+
dto.Name.ShouldBeNull(); // InheritsLazy Ignore is work
180+
dto.NumberDto.ShouldBe(42); // InheritsLazy is work
181+
}
182+
183+
133184
#region TestMethod Classes
134185

135-
public class SimplePoco
186+
public class RootPoco
187+
{
188+
public int Number { get; set; }
189+
}
190+
191+
public class RootDto
192+
{
193+
public int NumberDto { get; set; }
194+
}
195+
196+
197+
public class SimplePoco: RootPoco
136198
{
137199
public Guid Id { get; set; }
138200
public string Name { get; set; }
139201
}
140202

141-
public class SimpleDto
203+
public class SimpleDto : RootDto
142204
{
143205
public Guid Id { get; set; }
144206
public string Name { get; set; }

0 commit comments

Comments
 (0)