@@ -242,6 +242,7 @@ public void ImportAsReplace_TopicDataWithChild_DeletedOrphanedChildren() {
242
242
243
243
Assert . AreEqual < int > ( 1 , topic . Children . Count ) ;
244
244
Assert . AreEqual ( topicData . Children . FirstOrDefault ( ) . UniqueKey , topic . Children . FirstOrDefault ( ) . GetUniqueKey ( ) ) ;
245
+ Assert . AreEqual ( topicData . Children . FirstOrDefault ( ) . ContentType , topic . Children . FirstOrDefault ( ) . ContentType ) ;
245
246
246
247
}
247
248
@@ -263,19 +264,86 @@ public void Import_TopicDataWithChild_MapsExistingTopic() {
263
264
UniqueKey = topic . GetUniqueKey ( ) ,
264
265
ContentType = "Page"
265
266
} ;
267
+ var childTopicData = new TopicData ( ) {
268
+ Key = "Child" ,
269
+ UniqueKey = topic . GetUniqueKey ( ) + ":Child" ,
270
+ ContentType = topic . ContentType
271
+ } ;
266
272
267
- topicData . Children . Add (
273
+ childTopic . Attributes . SetValue ( "Description" , "Old Value" ) ;
274
+
275
+ childTopicData . Attributes . Add (
276
+ new AttributeData ( ) {
277
+ Key = "Description" ,
278
+ Value = "New Value" ,
279
+ LastModified = DateTime . Now . AddDays ( 1 )
280
+ }
281
+ ) ;
282
+
283
+ topicData . Children . Add ( childTopicData ) ;
284
+
285
+ topic . Import (
286
+ topicData ,
287
+ new ImportOptions ( ) {
288
+ Strategy = ImportStrategy . Merge
289
+ }
290
+ ) ;
291
+
292
+ var mappedChild = topic . Children . FirstOrDefault ( ) ;
293
+
294
+ Assert . IsNotNull ( mappedChild ) ;
295
+ Assert . AreEqual ( mappedChild . ContentType , childTopic . ContentType ) ;
296
+ Assert . AreEqual ( "New Value" , mappedChild . Attributes . GetValue ( "Description" ) ) ;
297
+
298
+ }
299
+
300
+ /*==========================================================================================================================
301
+ | TEST: IMPORT AS REPLACE: TOPIC DATA WITH NESTED TOPIC: DELETES ORPHANED CHILDREN
302
+ \-------------------------------------------------------------------------------------------------------------------------*/
303
+ /// <summary>
304
+ /// Creates a <see cref="TopicData"/> with nested topics, and ensures that a new <see cref="Topic"/> is created under the
305
+ /// target <see cref="Topic"/> corresponding to the child <see cref="TopicData"/> object.
306
+ /// </summary>
307
+ [ TestMethod ]
308
+ public void ImportAsReplace_TopicDataWithNestedTopic_DeletedOrphanedChildren ( ) {
309
+
310
+ var topic = TopicFactory . Create ( "Test" , "Container" ) ;
311
+ var nestedTopics = TopicFactory . Create ( "Nested" , "List" , topic ) ;
312
+ var nestedTopic1 = TopicFactory . Create ( "Nested1" , "Page" , 1 , nestedTopics ) ;
313
+ var nestedTopic2 = TopicFactory . Create ( "Nested2" , "Page" , 2 , nestedTopics ) ;
314
+ var topicData = new TopicData ( ) {
315
+ Key = topic . Key ,
316
+ UniqueKey = topic . GetUniqueKey ( ) ,
317
+ ContentType = topic . ContentType
318
+ } ;
319
+ var nestedTopicsData = new TopicData ( ) {
320
+ Key = nestedTopics . Key ,
321
+ UniqueKey = nestedTopics . GetUniqueKey ( ) ,
322
+ ContentType = nestedTopics . ContentType
323
+ } ;
324
+
325
+ topicData . Children . Add ( nestedTopicsData ) ;
326
+
327
+ nestedTopicsData . Children . Add (
268
328
new TopicData ( ) {
269
- Key = "Child" ,
270
- UniqueKey = topic . GetUniqueKey ( ) + ":Child" ,
271
- ContentType = topic . ContentType
329
+ Key = "Nested2" ,
330
+ UniqueKey = nestedTopic2 . GetUniqueKey ( ) ,
331
+ ContentType = nestedTopic2 . ContentType
332
+ }
333
+ ) ;
334
+
335
+ topic . Import (
336
+ topicData ,
337
+ new ImportOptions ( ) {
338
+ Strategy = ImportStrategy . Replace
272
339
}
273
340
) ;
274
341
275
- topic . Import ( topicData ) ;
342
+ var mappedNestedTopic = nestedTopics . Children . FirstOrDefault ( ) ;
276
343
277
- Assert . IsNotNull ( topic . Children . FirstOrDefault ( ) ) ;
278
- Assert . AreEqual ( topicData . Children . FirstOrDefault ( ) . ContentType , childTopic . ContentType ) ;
344
+ Assert . IsNotNull ( mappedNestedTopic ) ;
345
+ Assert . AreEqual < int > ( 1 , nestedTopics . Children . Count ) ;
346
+ Assert . AreEqual ( mappedNestedTopic , nestedTopic2 ) ;
279
347
280
348
}
281
349
0 commit comments