|
3 | 3 | using System;
|
4 | 4 | using System.Collections.Generic;
|
5 | 5 | using System.Linq;
|
| 6 | +using System.Text.Json.Serialization; |
| 7 | +using Newtonsoft.Json; |
6 | 8 |
|
7 | 9 | namespace Mapster.Tests
|
8 | 10 | {
|
@@ -266,6 +268,27 @@ public void MappingToInteraceWithReadonlyProps_AllPropsInitialized()
|
266 | 268 | );
|
267 | 269 | }
|
268 | 270 |
|
| 271 | + [TestMethod] |
| 272 | + public void MappingToInterface_VerifyReadonlyPropsInterfaceRule() |
| 273 | + { |
| 274 | + SampleInterfaceCls source = new SampleInterfaceCls |
| 275 | + { |
| 276 | + ActivityData = new SampleActivityData |
| 277 | + { |
| 278 | + Data = new SampleActivityParsedData |
| 279 | + { |
| 280 | + Steps = new List<string> { "A", "B", "C" } |
| 281 | + } |
| 282 | + } |
| 283 | + }; |
| 284 | + |
| 285 | + SampleInterfaceCls target = source.Adapt<SampleInterfaceCls>(); |
| 286 | + target.ShouldNotBeNull(); |
| 287 | + target.ShouldSatisfyAllConditions( |
| 288 | + () => target.ActivityData.ShouldBe(source.ActivityData) |
| 289 | + ); |
| 290 | + } |
| 291 | + |
269 | 292 | public interface IInheritedDtoWithoutProperties : IInheritedDto
|
270 | 293 | {
|
271 | 294 | }
|
@@ -374,6 +397,42 @@ public class PropertyInitializationTestSource
|
374 | 397 | public int Property1 { get; set; }
|
375 | 398 | public int Property2 { get; set; }
|
376 | 399 | }
|
| 400 | + |
| 401 | + public interface IActivityData |
| 402 | + { |
| 403 | + |
| 404 | + } |
| 405 | + |
| 406 | + public class SampleInterfaceCls |
| 407 | + { |
| 408 | + [Newtonsoft.Json.JsonIgnore] |
| 409 | + public IActivityData? ActivityData { get; set; } |
| 410 | + |
| 411 | + public SampleInterfaceCls() |
| 412 | + { |
| 413 | + |
| 414 | + } |
| 415 | + |
| 416 | + public SampleInterfaceCls(IActivityData data) |
| 417 | + { |
| 418 | + SetActivityData(data); |
| 419 | + } |
| 420 | + |
| 421 | + public void SetActivityData(IActivityData data) |
| 422 | + { |
| 423 | + ActivityData = data; |
| 424 | + } |
| 425 | + } |
| 426 | + |
| 427 | + public class SampleActivityData : IActivityData |
| 428 | + { |
| 429 | + public SampleActivityParsedData Data { get; set; } |
| 430 | + } |
| 431 | + |
| 432 | + public class SampleActivityParsedData |
| 433 | + { |
| 434 | + public List<string> Steps { get; set; } = new List<string>(); |
| 435 | + } |
377 | 436 |
|
378 | 437 | }
|
379 | 438 | }
|
0 commit comments