Beispiel #1
0
        public void GivenAnElementIsInTheModelWhenSearchIsCalledWithTextPartOfItsNameThenElementIsFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);

            Assert.IsNotNull(a);

            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            Assert.IsNotNull(b);

            IDsmElement foundElement = model.SearchElements(".b").ToList().FirstOrDefault();

            Assert.IsNotNull(foundElement);
            Assert.AreEqual(2, foundElement.Id);
            Assert.AreEqual("b", foundElement.Name);
            Assert.AreEqual("a.b", foundElement.Fullname);
            Assert.AreEqual("type", foundElement.Type);
            Assert.AreEqual(11, foundElement.Order);
            Assert.AreEqual(true, foundElement.IsExpanded);
            Assert.AreEqual(a, foundElement.Parent);
        }
Beispiel #2
0
        public void GivenAnElementIsInTheModelWhenFindByIdIsCalledWithItsNameThenElementIsFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);

            Assert.IsNotNull(a);

            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            Assert.IsNotNull(b);

            IDsmElement foundElement = model.FindElementByFullname("a.b");

            Assert.IsNotNull(foundElement);
            Assert.AreEqual(2, foundElement.Id);
            Assert.AreEqual("b", foundElement.Name);
            Assert.AreEqual("a.b", foundElement.Fullname);
            Assert.AreEqual("type", foundElement.Type);
            Assert.AreEqual(11, foundElement.Order);
            Assert.AreEqual(true, foundElement.IsExpanded);
            Assert.AreEqual(a, foundElement.Parent);
        }
Beispiel #3
0
        public void GivenMultipleElementAreInTheModelWhenAssignElementOrderIsCalledThenElementsHaveOrderSet()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "", 0, false, null, false);

            Assert.AreEqual(1, a.Id);
            IDsmElement a1 = model.ImportElement(2, "a1", "eta", 0, false, a.Id, false);

            Assert.AreEqual(2, a1.Id);

            IDsmElement b = model.ImportElement(3, "b", "", 0, false, null, false);

            Assert.AreEqual(3, b.Id);
            IDsmElement b1 = model.ImportElement(4, "b1", "etb", 0, false, b.Id, false);

            Assert.AreEqual(4, b1.Id);
            IDsmElement b2 = model.ImportElement(5, "b2", "etb", 0, false, b.Id, false);

            Assert.AreEqual(5, b2.Id);

            IDsmElement c = model.ImportElement(6, "c", "", 0, false, null, false);

            Assert.AreEqual(6, c.Id);
            IDsmElement c1 = model.ImportElement(7, "c1", "etc", 0, false, c.Id, false);

            Assert.AreEqual(7, c1.Id);
            IDsmElement c2 = model.ImportElement(8, "c2", "etc", 0, false, c.Id, false);

            Assert.AreEqual(8, c2.Id);
            IDsmElement c3 = model.ImportElement(9, "c3", "etc", 0, false, c.Id, false);

            Assert.AreEqual(9, c3.Id);

            Assert.AreEqual(0, a.Order);
            Assert.AreEqual(0, a1.Order);
            Assert.AreEqual(0, b.Order);
            Assert.AreEqual(0, b1.Order);
            Assert.AreEqual(0, b2.Order);
            Assert.AreEqual(0, c.Order);
            Assert.AreEqual(0, c1.Order);
            Assert.AreEqual(0, c2.Order);
            Assert.AreEqual(0, c3.Order);

            model.AssignElementOrder();

            Assert.AreEqual(1, a.Order);
            Assert.AreEqual(2, a1.Order);
            Assert.AreEqual(3, b.Order);
            Assert.AreEqual(4, b1.Order);
            Assert.AreEqual(5, b2.Order);
            Assert.AreEqual(6, c.Order);
            Assert.AreEqual(7, c1.Order);
            Assert.AreEqual(8, c2.Order);
            Assert.AreEqual(9, c3.Order);
        }
Beispiel #4
0
 private void CreateElementHierarchy()
 {
     _a  = _elementsDataModel.ImportElement(11, "a", "", 1, false, null, false);
     _a1 = _elementsDataModel.ImportElement(12, "a1", "eta", 2, false, _a.Id, false);
     _a2 = _elementsDataModel.ImportElement(13, "a2", "eta", 3, false, _a.Id, false);
     _b  = _elementsDataModel.ImportElement(14, "b", "", 4, false, null, false);
     _b1 = _elementsDataModel.ImportElement(15, "b1", "etb", 5, false, _b.Id, false);
     _b2 = _elementsDataModel.ImportElement(16, "b2", "etb", 6, false, _b.Id, false);
     _c  = _elementsDataModel.ImportElement(17, "c", "", 7, false, null, false);
     _c1 = _elementsDataModel.ImportElement(18, "c1", "etc", 8, false, _c.Id, false);
     _c2 = _elementsDataModel.ImportElement(19, "c2", "etc", 9, false, _c.Id, false);
 }
Beispiel #5
0
        public void GivenNoElementHasBeenAddedToTheModelWhenImportElementIsCalledThenItsHasTwoElements()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            model.ImportElement(1, "name", "type", 0, false, null, false);
            Assert.AreEqual(2, model.GetElementCount());
        }
Beispiel #6
0
        public void GivenAnElementIsInTheModelWhenFindByIdIsCalledWithAnotherNameThenElementIsNotFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);

            Assert.IsNotNull(a);

            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            Assert.IsNotNull(b);

            IDsmElement foundElement = model.FindElementByFullname("a.c");

            Assert.IsNull(foundElement);
        }
Beispiel #7
0
        public void WhenChangeElementIsCalledToChangeNameThenItCanBeFoundUnderThatName()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);
            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            IDsmElement foundElementBefore = model.FindElementByFullname("a.c");

            Assert.IsNull(foundElementBefore);

            model.ChangeElementName(b, "c");

            IDsmElement foundElementAfter = model.FindElementByFullname("a.c");

            Assert.IsNotNull(foundElementAfter);
        }
Beispiel #8
0
        public void WhenChangeElementIsCalledToChangeTypeThenTypeIsChanged()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);
            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            IDsmElement foundElementBefore = model.FindElementByFullname("a.b");

            Assert.IsNotNull(foundElementBefore);
            Assert.AreEqual("type", foundElementBefore.Type);

            model.ChangeElementType(b, "type1");

            IDsmElement foundElementAfter = model.FindElementByFullname("a.b");

            Assert.IsNotNull(foundElementAfter);
            Assert.AreEqual("type1", foundElementAfter.Type);
        }
Beispiel #9
0
        public void GivenAnElementIsInTheModelWhenFindByIdIsCalledWithAnotherIdThenElementIsNotFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            model.ImportElement(1, "name", "type", 10, true, null, false);

            IDsmElement foundElement = model.FindElementById(2);

            Assert.IsNull(foundElement);
        }
Beispiel #10
0
        public void GivenOneElementHasBeenAddedToTheModelWhenClearIsCalledThenOnlyRootElementIsinModelAgain()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            model.ImportElement(1, "name", "type", 0, false, null, false);
            Assert.AreEqual(2, model.GetElementCount());

            model.Clear();

            Assert.AreEqual(1, model.GetElementCount());
        }
Beispiel #11
0
        public void WhenChangeElementParentIsCalledThenItCanBeFoundAtTheNewLocation()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            IDsmElement a = model.ImportElement(1, "a", "type", 10, true, null, false);
            IDsmElement b = model.ImportElement(2, "b", "type", 11, true, a.Id, false);

            IDsmElement c = model.ImportElement(3, "c", "type", 12, true, null, false);

            IDsmElement foundElementBefore = model.FindElementByFullname("a.b");

            Assert.IsNotNull(foundElementBefore);
            Assert.AreEqual(a, foundElementBefore.Parent);

            model.ChangeElementParent(b, c);

            IDsmElement foundElementAfter = model.FindElementByFullname("c.b");

            Assert.IsNotNull(foundElementAfter);
            Assert.AreEqual(c, foundElementAfter.Parent);
        }
Beispiel #12
0
        public void GivenAnElementIsInTheModelWhenFindByIdIsCalledItsIdThenElementIsFound()
        {
            DsmElementModel model = new DsmElementModel();

            Assert.AreEqual(1, model.GetElementCount());

            model.ImportElement(1, "name", "type", 10, true, null, false);

            IDsmElement foundElement = model.FindElementById(1);

            Assert.IsNotNull(foundElement);
            Assert.AreEqual(1, foundElement.Id);
            Assert.AreEqual("name", foundElement.Name);
            Assert.AreEqual("type", foundElement.Type);
            Assert.AreEqual(10, foundElement.Order);
            Assert.AreEqual(true, foundElement.IsExpanded);
            Assert.IsNotNull(foundElement.Parent); // root element
            Assert.IsNull(foundElement.Parent.Parent);
        }