Execute() public method

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

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();
            sourceRepositoryProvider.Setup(s => s.ResetRepositoryConfiguration()).Returns(new SuccessResult());

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // Act
            repositorySourceConfigurationCommand.Execute();

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

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

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

            // Act
            repositorySourceConfigurationCommand.Execute();

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

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var configurations = new List<SourceRepositoryConfiguration>();
            sourceRepositoryProvider.Setup(s => s.GetRepositoryConfigurations()).Returns(configurations);

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // Act
            repositorySourceConfigurationCommand.Execute();

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

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            sourceRepositoryProvider.Setup(s => s.ResetRepositoryConfiguration()).Returns(new SuccessResult());

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            sourceRepositoryProvider.Verify(s => s.ResetRepositoryConfiguration(), Times.Once());
        }
        public void Execute_ActionArgumentIs_Delete_NoArgumentsSupplied_DeleteRepositoryConfigurationIsNotCalled()
        {
            // Arrange
            var commandAction = RepositoryConfigurationCommandAction.Delete;

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

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

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            sourceRepositoryProvider.Verify(s => s.DeleteRepositoryConfiguration(It.IsAny<string>()), Times.Never());
        }
        public void Execute_ActionArgumentIs_List_AllConfiguredRepositoriesAreListed()
        {
            // Arrange
            var commandAction = RepositoryConfigurationCommandAction.List;

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

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

            sourceRepositoryProvider.Setup(s => s.GetRepositoryConfigurations()).Returns(configurations);

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            foreach (var repositoryConfiguration in configurations)
            {
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(repositoryConfiguration.Name));
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(repositoryConfiguration.Url.ToString()));
            }
        }
        public void Execute_ActionArgumentIs_Delete_DeleteRepositoryConfigurationSucceeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            string repositoryName = "Test Repository";
            var commandAction = RepositoryConfigurationCommandAction.Delete;

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();
            sourceRepositoryProvider.Setup(s => s.DeleteRepositoryConfiguration(repositoryName)).Returns(new SuccessResult());

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // prepare command arguments
            repositorySourceConfigurationCommand.Arguments.Add(RepositorySourceConfigurationCommand.ArgumentNameRepositoryName, repositoryName);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_ActionArgumentIs_Add_SaveRepositoryConfigurationSucceeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var commandAction = RepositoryConfigurationCommandAction.Add;
            string repositoryName = "Test Repository";
            string repositoryUrl = "http://nuget.org/api/v2";

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();
            sourceRepositoryProvider.Setup(s => s.SaveRepositoryConfiguration(repositoryName, repositoryUrl)).Returns(new SuccessResult());

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // prepare command arguments
            repositorySourceConfigurationCommand.Arguments.Add(RepositorySourceConfigurationCommand.ArgumentNameRepositoryName, repositoryName);
            repositorySourceConfigurationCommand.Arguments.Add(RepositorySourceConfigurationCommand.ArgumentNameRepositoryUrl, repositoryUrl);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains("success") || this.loggingUserInterface.UserInterfaceOutput.Contains("suceeded"));
        }
        public void Execute_ActionArgumentIs_Add_RepositoryUrlArgumentMissing_SaveRepositoryConfigurationIsNotExecuted()
        {
            // Arrange
            var commandAction = RepositoryConfigurationCommandAction.Add;

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

            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // prepare command arguments
            string repositoryName = "Test Repository";
            repositorySourceConfigurationCommand.Arguments.Add(RepositorySourceConfigurationCommand.ArgumentNameRepositoryName, repositoryName);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            sourceRepositoryProvider.Verify(s => s.SaveRepositoryConfiguration(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
        public void Execute_ActionArgumentIsSet_ArgumentIsPassedToCommandActionParser(string actionParameter)
        {
            // Arrange
            var repositoryConfigurationCommandActionParser = new Mock<IRepositoryConfigurationCommandActionParser>();
            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

            // prepare command arguments
            repositorySourceConfigurationCommand.Arguments.Add(RepositorySourceConfigurationCommand.ArgumentNameAction, actionParameter);

            // Act
            repositorySourceConfigurationCommand.Execute();

            // Assert
            repositoryConfigurationCommandActionParser.Verify(p => p.ParseAction(actionParameter), Times.Once());
        }
        public void Execute_ActionArgumentIsNotSet_EmptyStringIsPassedToCommandActionParser()
        {
            // Arrange
            var repositoryConfigurationCommandActionParser = new Mock<IRepositoryConfigurationCommandActionParser>();
            var sourceRepositoryProvider = new Mock<ISourceRepositoryProvider>();

            var repositorySourceConfigurationCommand = new RepositorySourceConfigurationCommand(
                this.loggingUserInterface.UserInterface, repositoryConfigurationCommandActionParser.Object, sourceRepositoryProvider.Object);

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

            // Act
            repositorySourceConfigurationCommand.Execute();

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