public void AddShapeTest()
        {
            DocumentDataModel target = new DocumentDataModel();

            target.New(new Size(700, 1200), new Thickness(32, 32, 32, 32));
            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);

            //Test if the reference returned is correct.
            XElement shape      = new XElement("testTag", new XAttribute("Id", "myshape"));
            XElement addedShape = target.AddShape(shape);

            AssertAreEqualStrings(shape, addedShape);

            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);

            //Test if the id is replaced if it is taken.
            target.AddShape(shape);
            addedShape.Remove();
            Assert.AreSame(null, target.GetShapeById("myshape"));
            AssertAreEqualStrings(shape, target.GetShapeById("auto_0"));

            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);
        }
        public void GetUniqueIdTest()
        {
            DocumentDataModel model = new DocumentDataModel();

            model.New(new Size(700, 1200), new Thickness(32, 32, 32, 32));
            DocumentDataModelInvariant(model);
            Assert.AreEqual(DataModel.ModelState.Ready, model.State);

            // The first unique id should be auto_0:
            string firstUniqueId = model.GetUniqueId();

            Assert.AreEqual("auto_0", firstUniqueId);
            Assert.AreSame(null, model.GetShapeById(firstUniqueId));

            // Adding an id which almost looks like an auto-id does not change GetUniqueId.
            XElement shape = model.AddShape(new XElement("Test", new XAttribute("Id", "auto_not")));

            Assert.AreEqual(firstUniqueId, model.GetUniqueId());

            shape = model.AddShape(new XElement("Test", new XAttribute("Id", firstUniqueId)));
            Assert.AreSame(shape, model.GetShapeById(firstUniqueId));

            // The second unique id should be auto_1:
            string secondUniqueId = model.GetUniqueId();

            Assert.AreEqual("auto_1", secondUniqueId);
            Assert.AreSame(null, model.GetShapeById(secondUniqueId));

            // Removing a shape should not cause the unique id to decrement.
            shape.Remove();
            Assert.AreEqual(secondUniqueId, model.GetUniqueId());

            DocumentDataModelInvariant(model);
            Assert.AreEqual(DataModel.ModelState.Ready, model.State);
        }
        public void GetShapeByIdTest()
        {
            DocumentDataModel target = new DocumentDataModel();

            target.New(new Size(700, 1200), new Thickness(32, 32, 32, 32));
            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);

            XElement actual = target.GetShapeById("Id that isn't present");

            Assert.AreSame(null, actual);
            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);

            string   knownId = "1";
            XElement shape   = new XElement("testXElement", new XAttribute("Id", knownId));

            target.AddShape(shape);
            actual = target.GetShapeById(knownId);
            Assert.AreEqual(shape, actual);
            DocumentDataModelInvariant(target);
            Assert.AreEqual(DataModel.ModelState.Ready, target.State);
        }