@@ -41,7 +41,7 @@ public void AdaptRecordStructToRecordStruct()
4141 var _structResult = _sourceStruct . Adapt ( _destinationStruct ) ;
4242
4343 _structResult . X . ShouldBe ( 1000 ) ;
44- object . ReferenceEquals ( _destinationStruct , _structResult ) . ShouldBeFalse ( ) ;
44+ _destinationStruct . X . Equals ( _structResult . X ) . ShouldBeFalse ( ) ;
4545 }
4646
4747 [ TestMethod ]
@@ -194,26 +194,6 @@ public void UpdateNullable()
194194
195195 }
196196
197- /// <summary>
198- /// https://github.com/MapsterMapper/Mapster/issues/524
199- /// </summary>
200- [ TestMethod ]
201- public void TSousreIsObjectUpdateUseDynamicCast ( )
202- {
203- var source = new TestClassPublicCtr { X = 123 } ;
204- var _result = SomemapWithDynamic ( source ) ;
205-
206- _result . X . ShouldBe ( 123 ) ;
207- }
208-
209- TestClassPublicCtr SomemapWithDynamic ( object source )
210- {
211- var dest = new TestClassPublicCtr { X = 321 } ;
212- var dest1 = source . Adapt ( dest , source . GetType ( ) , dest . GetType ( ) ) ;
213-
214- return dest ;
215- }
216-
217197 /// <summary>
218198 /// https://github.com/MapsterMapper/Mapster/issues/569
219199 /// </summary>
@@ -247,6 +227,56 @@ public void DetectFakeRecord()
247227 _destination . X . ShouldBe ( 200 ) ;
248228 object . ReferenceEquals ( _destination , _result ) . ShouldBeTrue ( ) ;
249229 }
230+
231+ [ TestMethod ]
232+ public void OnlyInlineRecordWorked ( )
233+ {
234+ var _sourcePoco = new InlinePoco501 ( ) { MyInt = 1 , MyString = "Hello" } ;
235+ var _sourceOnlyInitRecord = new OnlyInitRecord501 { MyInt = 2 , MyString = "Hello World" } ;
236+
237+ var _resultOnlyinitRecord = _sourcePoco . Adapt < OnlyInitRecord501 > ( ) ;
238+ var _updateResult = _sourceOnlyInitRecord . Adapt ( _resultOnlyinitRecord ) ;
239+
240+ _resultOnlyinitRecord . MyInt . ShouldBe ( 1 ) ;
241+ _resultOnlyinitRecord . MyString . ShouldBe ( "Hello" ) ;
242+ _updateResult . MyInt . ShouldBe ( 2 ) ;
243+ _updateResult . MyString . ShouldBe ( "Hello World" ) ;
244+ }
245+
246+ [ TestMethod ]
247+ public void MultyCtorRecordWorked ( )
248+ {
249+ var _sourcePoco = new InlinePoco501 ( ) { MyInt = 1 , MyString = "Hello" } ;
250+ var _sourceMultyCtorRecord = new MultiCtorRecord ( 2 , "Hello World" ) ;
251+
252+ var _resultMultyCtorRecord = _sourcePoco . Adapt < MultiCtorRecord > ( ) ;
253+ var _updateResult = _sourceMultyCtorRecord . Adapt ( _resultMultyCtorRecord ) ;
254+
255+ _resultMultyCtorRecord . MyInt . ShouldBe ( 1 ) ;
256+ _resultMultyCtorRecord . MyString . ShouldBe ( "Hello" ) ;
257+ _updateResult . MyInt . ShouldBe ( 2 ) ;
258+ _updateResult . MyString . ShouldBe ( "Hello World" ) ;
259+ }
260+
261+ [ TestMethod ]
262+ public void MultiCtorAndInlineRecordWorked ( )
263+ {
264+ var _sourcePoco = new MultiCtorAndInlinePoco ( ) { MyInt = 1 , MyString = "Hello" , MyEmail = "[email protected] " , InitData = "Test" } ; 265+ var _sourceMultiCtorAndInline = new MultiCtorAndInlineRecord ( 2 , "Hello World" ) { InitData = "Worked" , MyEmail = "[email protected] " } ; 266+
267+ var _resultMultiCtorAndInline = _sourcePoco . Adapt < MultiCtorAndInlineRecord > ( ) ;
268+ var _updateResult = _sourceMultiCtorAndInline . Adapt ( _resultMultiCtorAndInline ) ;
269+
270+ _resultMultiCtorAndInline . MyInt . ShouldBe ( 1 ) ;
271+ _resultMultiCtorAndInline . MyString . ShouldBe ( "Hello" ) ;
272+ _resultMultiCtorAndInline . MyEmail . ShouldBe ( "[email protected] " ) ; 273+ _resultMultiCtorAndInline . InitData . ShouldBe ( "Test" ) ;
274+ _updateResult . MyInt . ShouldBe ( 2 ) ;
275+ _updateResult . MyString . ShouldBe ( "Hello World" ) ;
276+ _updateResult . MyEmail . ShouldBe ( "[email protected] " ) ; 277+ _updateResult . InitData . ShouldBe ( "Worked" ) ;
278+ }
279+
250280
251281 #region NowNotWorking
252282
@@ -268,35 +298,67 @@ public void CollectionUpdate()
268298 destination . Count . ShouldBe ( _result . Count ) ;
269299 }
270300
271- /// <summary>
272- /// https://github.com/MapsterMapper/Mapster/issues/524
273- /// Not work. Already has a special overload:
274- /// .Adapt(this object source, object destination, Type sourceType, Type destinationType)
275- /// </summary>
276- [ Ignore ]
277- [ TestMethod ]
278- public void TSousreIsObjectUpdate ( )
279- {
280- var source = new TestClassPublicCtr { X = 123 } ;
281- var _result = Somemap ( source ) ;
301+ #endregion NowNotWorking
302+
303+ }
304+
282305
283- _result . X . ShouldBe ( 123 ) ;
306+ #region TestClasses
307+
308+ class MultiCtorAndInlinePoco
309+ {
310+ public int MyInt { get ; set ; }
311+ public string MyString { get ; set ; }
312+ public string MyEmail { get ; set ; }
313+ public string InitData { get ; set ; }
314+ }
315+
316+ record MultiCtorAndInlineRecord
317+ {
318+ public MultiCtorAndInlineRecord ( int myInt )
319+ {
320+ MyInt = myInt ;
284321 }
285322
286- TestClassPublicCtr Somemap ( object source )
323+ public MultiCtorAndInlineRecord ( int myInt , string myString ) : this ( myInt )
287324 {
288- var dest = new TestClassPublicCtr { X = 321 } ;
289- var dest1 = source . Adapt ( dest ) ; // typeof(TSource) always return Type as Object. Need use dynamic or Cast to Runtime Type before Adapt
325+ MyString = myString ;
326+ }
327+
328+
329+ public int MyInt { get ; private set ; }
330+ public string MyString { get ; private set ; }
331+ public string MyEmail { get ; set ; }
332+ public string InitData { get ; init ; }
333+ }
290334
291- return dest ;
335+ record MultiCtorRecord
336+ {
337+ public MultiCtorRecord ( int myInt )
338+ {
339+ MyInt = myInt ;
292340 }
293341
294- #endregion NowNotWorking
342+ public MultiCtorRecord ( int myInt , string myString ) : this ( myInt )
343+ {
344+ MyString = myString ;
345+ }
295346
347+ public int MyInt { get ; private set ; }
348+ public string MyString { get ; private set ; }
296349 }
297350
351+ class InlinePoco501
352+ {
353+ public int MyInt { get ; set ; }
354+ public string MyString { get ; set ; }
355+ }
298356
299- #region TestClasses
357+ record OnlyInitRecord501
358+ {
359+ public int MyInt { get ; init ; }
360+ public string MyString { get ; init ; }
361+ }
300362
301363 class PocoWithGuid
302364 {
0 commit comments