Execute() public method

public Execute ( ) : bool
return bool
        public void Execute_ActionArgumentIs_Reset_Succeeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Reset;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();
            publishConfigurationAccessor.Setup(s => s.ResetPublishConfiguration()).Returns(new SuccessResult());

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains("success") || this.loggingUserInterface.UserInterfaceOutput.Contains("succeed"));
        }
        public void Execute_ActionArgumentIs_Unrecognized_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Unrecognized;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments = new Dictionary<string, string>();

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_ActionArgumentIs_List_NoPublishingTargetsConfigured_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.List;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var configurations = new List<PublishConfiguration>();
            publishConfigurationAccessor.Setup(s => s.GetPublishConfigurations()).Returns(configurations);

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_ActionArgumentIs_Reset_ResetIsCalled()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Reset;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();
            publishConfigurationAccessor.Setup(p => p.ResetPublishConfiguration()).Returns(new SuccessResult());

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            publishConfigurationAccessor.Verify(s => s.ResetPublishConfiguration(), Times.Once());
        }
        public void Execute_ActionArgumentIs_Delete_NoArgumentsSupplied_DeletePublishConfigurationIsNotCalled()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Delete;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments = new Dictionary<string, string>();

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            publishConfigurationAccessor.Verify(s => s.DeletePublishConfiguration(It.IsAny<string>()), Times.Never());
        }
        public void Execute_ActionArgumentIs_List_AllConfiguredPublishingTargetsAreListed()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.List;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var configurations = new List<PublishConfiguration>
                {
                    new PublishConfiguration { Name = "Test Repo 1", PublishLocation = "http://test.repo1.com/api/v2" },
                    new PublishConfiguration { Name = "Test Repo 2", PublishLocation = "http://test.repo2.com/api/v2" },
                    new PublishConfiguration { Name = "Test Repo 3", PublishLocation = "http://test.repo3.com/api/v2" }
                };

            publishConfigurationAccessor.Setup(s => s.GetPublishConfigurations()).Returns(configurations);

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            foreach (var repositoryConfiguration in configurations)
            {
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(repositoryConfiguration.Name));
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(repositoryConfiguration.PublishLocation));
            }
        }
        public void Execute_ActionArgumentIs_Delete_DeletePublishConfigurationSucceeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            string publishConfigurationName = "Nuget Gallery";
            var commandAction = PublishingTargetConfigurationCommandAction.Delete;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();
            publishConfigurationAccessor.Setup(s => s.DeletePublishConfiguration(publishConfigurationName)).Returns(new SuccessResult());

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments.Add(PublishingTargetConfigurationCommand.ArgumentNamePublishConfigurationName, publishConfigurationName);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_ActionArgumentIs_Add_RepositoryNameArgumentMissing_AddOrUpdatePublishConfigurationIsNotExecuted()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Add;

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            string url = "http://nuget.org./api/v2";
            publishingTargetConfigurationCommand.Arguments.Add(PublishingTargetConfigurationCommand.ArgumentNamePublishLocation, url);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            publishConfigurationAccessor.Verify(s => s.AddOrUpdatePublishConfiguration(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
        public void Execute_ActionArgumentIs_Add_AddOrUpdatePublishConfigurationSucceeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var commandAction = PublishingTargetConfigurationCommandAction.Add;
            string publishConfigurationName = "Nuget Gallery";
            string publishLocation = "http://nuget.org/api/v2";

            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            publishingTargetConfigurationCommandParser.Setup(r => r.ParseAction(It.IsAny<string>())).Returns(commandAction);

            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();
            publishConfigurationAccessor.Setup(s => s.AddOrUpdatePublishConfiguration(publishConfigurationName, publishLocation, It.IsAny<string>())).Returns(new SuccessResult());

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments.Add(PublishingTargetConfigurationCommand.ArgumentNamePublishConfigurationName, publishConfigurationName);
            publishingTargetConfigurationCommand.Arguments.Add(PublishingTargetConfigurationCommand.ArgumentNamePublishLocation, publishLocation);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains("success") || this.loggingUserInterface.UserInterfaceOutput.Contains("suceeded"));
        }
        public void Execute_ActionArgumentIsSet_ArgumentIsPassedToCommandActionParser(string actionParameter)
        {
            // Arrange
            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments.Add(PublishingTargetConfigurationCommand.ArgumentNameAction, actionParameter);

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            publishingTargetConfigurationCommandParser.Verify(p => p.ParseAction(actionParameter), Times.Once());
        }
        public void Execute_ActionArgumentIsNotSet_EmptyStringIsPassedToCommandActionParser()
        {
            // Arrange
            var publishingTargetConfigurationCommandParser = new Mock<IPublishingTargetConfigurationCommandActionParser>();
            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            var publishingTargetConfigurationCommand = new PublishingTargetConfigurationCommand(
                this.loggingUserInterface.UserInterface, publishingTargetConfigurationCommandParser.Object, publishConfigurationAccessor.Object);

            // prepare command arguments
            publishingTargetConfigurationCommand.Arguments = new Dictionary<string, string>();

            // Act
            publishingTargetConfigurationCommand.Execute();

            // Assert
            publishingTargetConfigurationCommandParser.Verify(p => p.ParseAction(string.Empty), Times.Once());
        }