Example #1
0
        public void CanProperlyUndoRedoDeletionOfNewConnections()
        {
            classDiagram.CreateShapeAt(EntityType.Interface, new Point(0, 0));
            classDiagram.CreateShapeAt(EntityType.Class, new Point(0, 0));
            classDiagram.CreateShapeAt(EntityType.Interface, new Point(0, 0));
            classDiagram.CreateShapeAt(EntityType.Class, new Point(0, 0));

            var shapes         = classDiagram.Shapes.ToArray(); // shapes is an elementlist, also everything is backwards
            var firstInterFace = (InterfaceShape)shapes[3];
            var firstClass     = (ClassShape)shapes[2];
            Func <Relationship> _connectionFactory = () => classDiagram.AddAssociation(firstInterFace.TypeBase, firstClass.TypeBase);
            var command = new AddConnectionCommand(classDiagram, _connectionFactory);

            command.Execute();
            classDiagram.TrackCommand(command);

            var secondInterFace = (InterfaceShape)shapes[1];
            var secondClass     = (ClassShape)shapes[0];

            _connectionFactory = () => classDiagram.AddAssociation(secondInterFace.TypeBase, secondClass.TypeBase);
            command            = new AddConnectionCommand(classDiagram, _connectionFactory);
            command.Execute();
            classDiagram.TrackCommand(command);

            classDiagram.Undo();
            classDiagram.Undo();
            var oldCount = classDiagram.ConnectionCount;

            classDiagram.Redo();
            classDiagram.Redo();
            var newCount = classDiagram.ConnectionCount;

            oldCount.ShouldBe(0);
            newCount.ShouldBe(2);
        }
Example #2
0
        /// <summary>
        /// Adds the relationships from <paramref name="nrRelationships"/> to the
        /// diagram.
        /// </summary>
        /// <param name="nrRelationships">The relationships to add.</param>
        private void AddRelationships(NRRelationships nrRelationships)
        {
            foreach (NRNesting nrNesting in nrRelationships.Nestings)
            {
                INestable      parentType = types[nrNesting.ParentType] as INestable;
                INestableChild innerType  = types[nrNesting.InnerType];
                if (parentType != null && innerType != null)
                {
                    diagram.AddNesting(parentType, innerType);
                }
            }

            foreach (NRGeneralization nrGeneralization in nrRelationships.Generalizations)
            {
                CompositeType derivedType = types[nrGeneralization.DerivedType] as CompositeType;
                CompositeType baseType    = types[nrGeneralization.BaseType] as CompositeType;
                if (derivedType != null && baseType != null)
                {
                    diagram.AddGeneralization(derivedType, baseType);
                }
            }

            foreach (NRRealization nrRealization in nrRelationships.Realizations)
            {
                CompositeType implementingType = types[nrRealization.ImplementingType] as CompositeType;
                InterfaceType interfaceType    = types[nrRealization.BaseType] as InterfaceType;
                if (implementingType != null && interfaceType != null)
                {
                    diagram.AddRealization(implementingType, interfaceType);
                }
            }

            foreach (NRAssociation nrAssociation in nrRelationships.Associations)
            {
                TypeBase first  = types[nrAssociation.StartType];
                TypeBase second = types[nrAssociation.EndType];
                if (first != null && second != null)
                {
                    AssociationRelationship associationRelationship = diagram.AddAssociation(first, second);
                    associationRelationship.EndMultiplicity   = nrAssociation.EndMultiplicity;
                    associationRelationship.StartMultiplicity = nrAssociation.StartMultiplicity;
                    associationRelationship.EndRole           = nrAssociation.EndRole;
                    associationRelationship.StartRole         = nrAssociation.StartRole;
                }
            }
        }