public void ClearElements() { NpcChatProject project = new NpcChatProject(); if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill")) { DialogTree tree = project.ProjectDialogs.CreateNewDialogTree(); DialogTreeBranch branch = tree.CreateNewBranch(); DialogSegment segment = branch.CreateNewDialog(id); Assert.NotNull(segment); DialogText one = DialogTypeStore.Instance.CreateEntity <DialogText>(); one.Text = "one"; segment.AddDialogElement(one); Assert.IsTrue(segment.SegmentParts.Count > 0); bool callback = false; segment.PropertyChanged += (sender, args) => callback = true; segment.ClearElements(); Assert.AreEqual(0, segment.SegmentParts.Count); Assert.IsTrue(callback, "Failed to send callback for added type"); } else { Assert.Fail("Failed to create character"); } }
private CharacterDialogVM ElementTextEditTestCreation() { NpcChatProject project = new NpcChatProject(); DialogTree tree = project.ProjectDialogs.CreateNewDialogTree(); DialogTreeBranch branch = tree.CreateNewBranch(); Assert.AreEqual(0, branch.Dialog.Count, "This is a new branch and shouldn't have any dialog inside it!"); int charId; Assert.IsTrue(project.ProjectCharacters.RegisterNewCharacter(out charId, "Gerald")); DialogSegment dialogSegment = branch.CreateNewDialog(charId); Assert.AreEqual(1, branch.Dialog.Count, "Failed to create sample dialog segment"); dialogSegment.ClearElements(); Assert.AreEqual(0, dialogSegment.SegmentParts.Count); Assert.AreEqual("", dialogSegment.Text); CharacterDialogVM testVM = new CharacterDialogVM(project, dialogSegment) { EditMode = EditMode.Elements, InspectionActive = false }; // make sure creation was valid Assert.NotNull(testVM); Assert.AreSame(dialogSegment, testVM.DialogSegment); Assert.AreEqual(0, testVM.DialogSegment.SegmentParts.Count); return(testVM); }
public void RemoveElement() { NpcChatProject project = new NpcChatProject(); if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill")) { DialogTree tree = project.ProjectDialogs.CreateNewDialogTree(); DialogTreeBranch branch = tree.CreateNewBranch(); DialogSegment segment = branch.CreateNewDialog(id); Assert.NotNull(segment); segment.ClearElements(); //ensure there are elements in the segment DialogText one = DialogTypeStore.Instance.CreateEntity <DialogText>(); one.Text = "one"; segment.AddDialogElement(one); DialogText two = DialogTypeStore.Instance.CreateEntity <DialogText>(); one.Text = "two"; segment.AddDialogElement(two); Assert.IsTrue(segment.SegmentParts.Count > 0); bool callback = false; segment.PropertyChanged += (sender, args) => callback = true; int before = segment.SegmentParts.Count; segment.RemoveDialogElement(one); Assert.AreEqual(before - 1, segment.SegmentParts.Count); Assert.IsTrue(callback, "Failed to send callback for added type"); //ensure correct element is actually removed Assert.IsFalse(segment.SegmentParts.Contains(one)); Assert.IsTrue(segment.SegmentParts.Contains(two)); } else { Assert.Fail("Failed to create character"); } }