Exemplo n.º 1
0
        public void CopyAndPasteInSingleDiagramTest()
        {
            var shapeColor = Color.Red;

            ChangeEntityTypesFillColorTest(
                "CopyAndPasteSingle",
                shapeColor,
                (artifact, commandProcessor) =>
            {
                var entityDesignerDiagram = GetDocData(commandProcessor.EditingContext).GetEntityDesignerDiagram();
                Assert.IsNotNull(entityDesignerDiagram, "Could not get an instance of EntityDesignerDiagram from editingcontext.");

                var author = entityDesignerDiagram.GetShape("author");
                Assert.IsNotNull(author, "Could not get DSL entity type shape instance of 'author'.");

                var titleAuthor = entityDesignerDiagram.GetShape("titleauthor");
                Assert.IsNotNull(titleAuthor, "Could not get DSL entity type shape instance of 'titleauthor'.");

                entityDesignerDiagram.SelectDiagramItems(new[] { author, titleAuthor });

                DesignerUtilities.Copy(Dte);
                DesignerUtilities.Paste(Dte);

                var authorCopy = entityDesignerDiagram.GetShape("author1");
                Assert.IsNotNull(authorCopy, "Entity: 'author1' should have been created.");
                var authorCopyModel =
                    (EntityType)
                    authorCopy.TypedModelElement.EntityDesignerViewModel.ModelXRef.GetExisting(authorCopy.TypedModelElement);
                Assert.IsNotNull(
                    authorCopyModel.GetAntiDependenciesOfType <AssociationEnd>().FirstOrDefault(),
                    "The association between author1 and titleauthor1 should have been created.");
                Assert.AreEqual(shapeColor, authorCopy.FillColor);

                var titleAuthorCopy = entityDesignerDiagram.GetShape("titleauthor1");
                Assert.IsNotNull(titleAuthorCopy, "Entity: 'titleauthor1' should have been created.");
                Assert.AreEqual(shapeColor, titleAuthorCopy.FillColor);
            });
        }
Exemplo n.º 2
0
        public void CopyAndPasteInMultipleDiagramsTest()
        {
            var shapeColor = Color.Brown;

            ChangeEntityTypesFillColorTest(
                "CopyAndPasteMulti",
                shapeColor,
                (artifact, commandProcessorContext) =>
            {
                var docData = GetDocData(commandProcessorContext.EditingContext);
                var entityDesignerDiagram = docData.GetEntityDesignerDiagram();
                Assert.IsNotNull(entityDesignerDiagram, "Could not get an instance of EntityDesignerDiagram from editingcontext.");

                var author = entityDesignerDiagram.GetShape("author");
                Assert.IsNotNull(author, "Could not get DSL entity type shape instance of 'author'.");

                var titleAuthor = entityDesignerDiagram.GetShape("titleauthor");
                Assert.IsNotNull(titleAuthor, "Could not get DSL entity type shape instance of 'titleauthor'.");

                entityDesignerDiagram.SelectDiagramItems(new[] { author, titleAuthor });
                DesignerUtilities.Copy(Dte);

                var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(commandProcessorContext);
                docData.OpenDiagram(diagram.Id.Value);

                DesignerUtilities.Paste(Dte);

                // Get the newly created diagram.
                entityDesignerDiagram = docData.GetEntityDesignerDiagram(diagram.Id.Value);

                author = entityDesignerDiagram.GetShape("author");
                Assert.IsNotNull(author, "Entity: 'author' should exists in diagram:" + diagram.Name);

                titleAuthor = entityDesignerDiagram.GetShape("titleauthor");
                Assert.IsNotNull(titleAuthor, "Entity: 'titleauthor' should exists in diagram:" + diagram.Name);

                var associationConnector =
                    entityDesignerDiagram.NestedChildShapes.OfType <EntityDesignerView.AssociationConnector>().FirstOrDefault();
                Assert.IsNotNull(
                    associationConnector,
                    "There should have been association connector created between entities 'author' and 'titleauthor'.");

                var entityDesignerViewModel = entityDesignerDiagram.ModelElement;
                Assert.IsNotNull(entityDesignerViewModel, "Diagram's ModelElement is not a type of EntityDesignerViewModel");

                var association = (Association)entityDesignerViewModel.ModelXRef.GetExisting(associationConnector.ModelElement);
                Assert.IsNotNull(
                    association,
                    "Could not find association for associationConnector" + associationConnector.AccessibleName
                    + " from Model Xref.");

                var entityTypesInAssociation = association.AssociationEnds().Select(ae => ae.Type.Target).Distinct().ToList();
                Assert.AreEqual(2, entityTypesInAssociation.Count);
                Assert.IsFalse(
                    entityTypesInAssociation.Any(et => et.LocalName.Value != "author" && et.LocalName.Value != "titleauthor"),
                    "The association between author and title-author is not created in diagram: " + diagram.Name);

                Assert.AreEqual(shapeColor, author.FillColor);
                Assert.AreEqual(shapeColor, titleAuthor.FillColor);
            });
        }