Skip to content

Commit ea10979

Browse files
committed
Merge branch 'release/1.1.0'
2 parents f0d1121 + 805ef7d commit ea10979

File tree

8 files changed

+622
-37
lines changed

8 files changed

+622
-37
lines changed

OnTopic.Data.Transfer.Tests/ImportOptionsTest.cs

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void ImportAsReplace_TopicDataWithChild_DeletedOrphanedChildren() {
242242

243243
Assert.AreEqual<int>(1, topic.Children.Count);
244244
Assert.AreEqual(topicData.Children.FirstOrDefault().UniqueKey, topic.Children.FirstOrDefault().GetUniqueKey());
245+
Assert.AreEqual(topicData.Children.FirstOrDefault().ContentType, topic.Children.FirstOrDefault().ContentType);
245246

246247
}
247248

@@ -263,19 +264,86 @@ public void Import_TopicDataWithChild_MapsExistingTopic() {
263264
UniqueKey = topic.GetUniqueKey(),
264265
ContentType = "Page"
265266
};
267+
var childTopicData = new TopicData() {
268+
Key = "Child",
269+
UniqueKey = topic.GetUniqueKey() + ":Child",
270+
ContentType = topic.ContentType
271+
};
266272

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(
268328
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
272339
}
273340
);
274341

275-
topic.Import(topicData);
342+
var mappedNestedTopic = nestedTopics.Children.FirstOrDefault();
276343

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);
279347

280348
}
281349

0 commit comments

Comments
 (0)