public void CreateUndoCommandSucceedsForInsertion()
        {
            var command = ConfigurationCommandFactory.CreateUndoCommandForInsertion(
                new ElementInsertionCommand(
                    "/configuration",
                    new ElementSpecification("appSettings", string.Empty, Enumerable.Empty <AttributeSpecification>(), "appSettings")));

            command.Should().BeEquivalentTo(new ElementDeletionCommand("/configuration/appSettings"));
        }
Beispiel #2
0
        internal override ConfigurationCommand Execute(XmlElement configurationElement)
        {
            var undoCommand = ConfigurationCommandFactory.CreateUndoCommandForUpdate(this, configurationElement);

            foreach (var attributeSpecification in AttributeSpecifications)
            {
                attributeSpecification.Execute(configurationElement);
            }
            return(undoCommand);
        }
        public void CreateFailedWhenActionIsMissing()
        {
            Action act = () => {
                ConfigurationCommandFactory.Create(
                    Files.Load("create-node-change.config")
                    .AsXPathNavigator()
                    .SelectSingleNode("/configuration"));
            };

            act.Should().ThrowExactly <InvalidOperationException>();
        }
Beispiel #4
0
        internal override ConfigurationCommand Execute(XmlElement configurationElement)
        {
            if (ElementSpecification.Exists(configurationElement))
            {
                throw new InvalidOperationException(
                          $"The configuration element already exists at '{string.Join("/", ConfigurationElementSelector, ElementSpecification.Selector)}'.");
            }
            var undoCommand = ConfigurationCommandFactory.CreateUndoCommandForInsertion(this);

            configurationElement.AppendChild(ElementSpecification.Execute(configurationElement.OwnerDocument));
            return(undoCommand);
        }
 public void CreateSucceedsForNodeUpdateChangeWithAttributeUpdate()
 {
     ConfigurationCommandFactory
     .Create(
         Files.Load("update-node-change-with-attribute-update.config")
         .AsXPathNavigator()
         .SelectSingleNode("/configuration/system.net"))
     .Should().NotBeNull()
     .And.BeOfType <ElementUpdateCommand>()
     .Subject.AttributeSpecifications.Should()
     .ContainSingle(update => update.Name == "test" && update.Value == "true");
 }
 public void CreateSucceedsForElementDeletionChange()
 {
     ConfigurationCommandFactory.Create(
         Files
         .Load("delete-element-command.config")
         .AsXPathNavigator()
         .SelectSingleNode("/configuration/appSettings/add[@key='second_setting']"))
     .Should().NotBeNull()
     .And.BeOfType <ElementDeletionCommand>()
     .Which.ConfigurationElementSelector
     .Should().Be("/*[local-name()='configuration']/*[local-name()='appSettings']/*[local-name()='add' and (@key = 'second_setting')]");
 }
        internal override ConfigurationCommand Execute(XmlElement configurationElement)
        {
            if (configurationElement.HasChildNodes)
            {
                throw new InvalidOperationException($"The configuration element '{configurationElement.Name}' has child nodes (Content: '{configurationElement.InnerXml}').");
            }

            var undoCommand = ConfigurationCommandFactory.CreateUndoCommandForDeletion(configurationElement);
            var parent      = configurationElement.ParentNode
                              ?? throw new InvalidOperationException($"The configuration element '{configurationElement.Name}' does not have a parent.");

            parent.RemoveChild(configurationElement);
            return(undoCommand);
        }
        public void CreateSucceedsForNodeInsertionChange()
        {
            var elementInsertionDefinition = ConfigurationCommandFactory.Create(
                Files
                .Load("create-node-change.config")
                .AsXPathNavigator()
                .SelectSingleNode("/configuration/system.net"))
                                             .Should().NotBeNull()
                                             .And.BeOfType <ElementInsertionCommand>().Subject.ElementSpecification;

            elementInsertionDefinition.Name.Should().Be("system.net");
            elementInsertionDefinition.NamespaceUri.Should().BeNullOrEmpty();
            elementInsertionDefinition.Selector.Should().Be("*[local-name()='system.net']");
        }
        public void CreateSucceedsForNodeInsertionChangeWithDiscriminant()
        {
            var elementInsertionDefinition = ConfigurationCommandFactory
                                             .Create(
                Files.Load("create-node-change-with-discriminant.config")
                .AsXPathNavigator()
                .SelectSingleNode("/configuration/system.net/connectionManagement/add"))
                                             .Should().NotBeNull()
                                             .And.BeOfType <ElementInsertionCommand>().Subject
                                             .ElementSpecification;

            elementInsertionDefinition.Name.Should().Be("add");
            elementInsertionDefinition.NamespaceUri.Should().BeNullOrEmpty();
            elementInsertionDefinition.Selector.Should().Be("*[local-name()='add' and (@address = '*')]");
        }
        public void CreateUndoCommandSucceedsForUpdate()
        {
            var elementToUpdate = Files.Load("web-original.config").AsXmlDocument().SelectSingleNode("/configuration/appSettings/add[@key='first_setting']") as XmlElement;
            var command         = ConfigurationCommandFactory.CreateUndoCommandForUpdate(
                new ElementUpdateCommand(
                    "/configuration/appSettings/add[@key='first_setting']",
                    new[] {
                new AttributeSpecification {
                    Name = "value", Value = "test", NamespaceUri = string.Empty
                }
            }),
                elementToUpdate);

            command.Should().BeEquivalentTo(
                new ElementUpdateCommand(
                    "/configuration/appSettings/add[@key='first_setting']",
                    new[] {
                new AttributeSpecification {
                    Name = "value", Value = "", NamespaceUri = string.Empty
                }
            }));
        }
        public void CreateUndoCommandSucceedsForDeletion()
        {
            var elementToUpdate = Files.Load("web-original.config").AsXmlDocument().SelectSingleNode("/configuration/appSettings/add[@key='first_setting']") as XmlElement;
            var command         = ConfigurationCommandFactory.CreateUndoCommandForDeletion(elementToUpdate);

            command.Should().BeEquivalentTo(
                new ElementInsertionCommand(
                    "/configuration/appSettings",
                    new ElementSpecification(
                        "add",
                        string.Empty,
                        new[] {
                new AttributeSpecification {
                    Name = "key", Value = "first_setting", NamespaceUri = string.Empty
                },
                new AttributeSpecification {
                    Name = "value", Value = "", NamespaceUri = string.Empty
                }
            },
                        "add")),
                options => options.IncludingAllDeclaredProperties());
        }