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"); } }
public void AddElement(Type dialogType) { 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); bool callback = false; segment.PropertyChanged += (sender, args) => callback = true; int before = segment.SegmentParts.Count; IDialogElement element = DialogTypeStore.Instance.CreateEntity(dialogType); segment.AddDialogElement(element); Assert.AreEqual(before + 1, segment.SegmentParts.Count); Assert.IsTrue(callback, "Failed to send callback for added type"); } else { Assert.Fail("Failed to create character"); } }
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"); } }