public void Constructor_CommandAttributesAreInitializedProperly()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();

            // Act
            var packageSolutionCommand = new PackageSolutionCommand(userInterface.Object, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // Assert
            CommandTestUtilities.ValidateCommandAttributes(packageSolutionCommand.Attributes);
        }
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();

            // Act
            var packageSolutionCommand = new PackageSolutionCommand(userInterface.Object, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // Assert
            Assert.IsNotNull(packageSolutionCommand);
        }
 public void Setup()
 {
     this.userInterface = new Mock<IUserInterface>().Object;
     this.installationStatus = new InstallationStatusCommand(this.userInterface, new Mock<IInstallationStatusProvider>().Object);
     this.install = new InstallCommand(this.userInterface, new Mock<IPackageInstaller>().Object, new Mock<IDeploymentTypeParser>().Object);
     this.uninstall = new UninstallCommand(this.userInterface, new Mock<IPackageUninstaller>().Object);
     this.cleanup = new CleanupCommand(this.userInterface, new Mock<ICleanupService>().Object);
     this.packageSolution = new PackageSolutionCommand(this.userInterface, new Mock<ISolutionPackagingService>().Object, new Mock<IBuildPropertyParser>().Object, new Mock<IPublishingService>().Object);
     this.packageBuildOutput = new PackageBuildOutputCommand(this.userInterface, new Mock<IBuildOutputPackagingService>().Object, new Mock<IPublishingService>().Object);
     this.configureSources = new RepositorySourceConfigurationCommand(this.userInterface, new Mock<IRepositoryConfigurationCommandActionParser>().Object, new Mock<ISourceRepositoryProvider>().Object);
     this.configurePublishingTargets = new PublishingTargetConfigurationCommand(this.userInterface, new Mock<IPublishingTargetConfigurationCommandActionParser>().Object, new Mock<IPublishConfigurationAccessor>().Object);
     this.selfUpdate = new SelfUpdateCommand(new ApplicationInformation(), new Mock<ISelfUpdateService>().Object, new Mock<_Assembly>().Object);
     this.publishCommand = new PublishCommand(this.userInterface, new Mock<IPublishingService>().Object);
     this.help = new HelpCommand(new Mock<IHelpProvider>().Object);
 }
        public void Execute_SolutionPathArgumentIsNotSet_PackageSolutionIsNotExecuted()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            solutionPackagingService.Verify(s => s.PackageSolution(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<KeyValuePair<string, string>[]>()), Times.Never());
        }
        public void Execute_SolutionPathArgumentIsNotSet_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_PublishingSucceeds_SuccessMessageIsWrittenTouUserInterface()
        {
            // Arrange
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";
            string publishConfigurationName = "Some Publish Config";

            string packagePath = @"C:\some-package.nupkg";
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            solutionPackagingService.Setup(s => s.PackageSolution(solutionPath, buildConfiguration, It.IsAny<KeyValuePair<string, string>[]>())).Returns(
                new SuccessResult { ResultArtefact = packagePath });

            var buildPropertyParser = new Mock<IBuildPropertyParser>();

            var publishingService = new Mock<IPublishingService>();
            publishingService.Setup(p => p.PublishPackage(It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            Assert.IsTrue(
                this.loggingUserInterface.UserInterfaceOutput.Contains(packagePath)
                && this.loggingUserInterface.UserInterfaceOutput.Contains(publishConfigurationName),
                "The user interface should contain the package path \"{0}\" and the publish configuration name \"{1}\" but contains this \"{2}\"",
                packagePath,
                publishConfigurationName,
                this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_PublishingFails_FailureResultIsWrittenTouUserInterface()
        {
            // Arrange
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";
            string publishConfigurationName = "Some Publish Config";

            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            solutionPackagingService.Setup(s => s.PackageSolution(solutionPath, buildConfiguration, It.IsAny<KeyValuePair<string, string>[]>())).Returns(new SuccessResult());

            var buildPropertyParser = new Mock<IBuildPropertyParser>();

            var publishingService = new Mock<IPublishingService>();
            string publishingFailureMessage = "Publishing failed. yada yada. " + Guid.NewGuid().ToString();
            publishingService.Setup(p => p.PublishPackage(It.IsAny<string>(), It.IsAny<string>())).Returns(new FailureResult(publishingFailureMessage));

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            Assert.IsTrue(
                this.loggingUserInterface.UserInterfaceOutput.Contains(publishingFailureMessage),
                "The user interface should contain the failure message \"{0}\" but contains this \"{1}\"",
                publishingFailureMessage,
                this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_PublishConfigurationIsSet_PublishIsExecuted()
        {
            // Arrange
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";
            string publishConfigurationName = "Some Publish Config";

            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            solutionPackagingService.Setup(s => s.PackageSolution(solutionPath, buildConfiguration, It.IsAny<KeyValuePair<string, string>[]>())).Returns(new SuccessResult());

            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            publishingService.Setup(p => p.PublishPackage(It.IsAny<string>(), publishConfigurationName)).Returns(new SuccessResult());

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            publishingService.Verify(p => p.PublishPackage(It.IsAny<string>(), publishConfigurationName), Times.Once());
        }
        public void Execute_PackagingSucceeds_ResultIsTrue()
        {
            // Arrange
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";

            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            solutionPackagingService.Setup(s => s.PackageSolution(solutionPath, buildConfiguration, It.IsAny<KeyValuePair<string, string>[]>())).Returns(new SuccessResult());

            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);

            // Act
            var result = packageSolutionCommand.Execute();

            // Assert
            Assert.IsTrue(result);
        }
        public void Execute_MSBuildPropertiesArgumentIsNotSet_ParseBuildPropertiesArgumentIsNotCalled()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();

            solutionPackagingService.Setup(s => s.PackageSolution(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<KeyValuePair<string, string>[]>())).Returns(
                new SuccessResult());

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";

            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            buildPropertyParser.Verify(b => b.ParseBuildPropertiesArgument(It.IsAny<string>()), Times.Never());
        }
        public void Execute_MSBuildPropertiesArgumentIsInvalid_PackageSolutionIsCalledWithEmptyListOfBuildProperties(string buildPropertiesArgument)
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();

            solutionPackagingService.Setup(s => s.PackageSolution(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<KeyValuePair<string, string>[]>())).Returns(
                new SuccessResult());

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";

            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);

            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameMSBuildProperties, buildPropertiesArgument);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            solutionPackagingService.Verify(
                p => p.PackageSolution(solutionPath, buildConfiguration, It.Is<KeyValuePair<string, string>[]>(d => d.Any() == false)), Times.Once());
        }
        public void Execute_MSBuildPropertiesArgumentContainsTwoValues_PackageSolutionIsCalledWithEmptyListOfTwoBuildProperties()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();

            solutionPackagingService.Setup(s => s.PackageSolution(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<KeyValuePair<string, string>[]>())).Returns(
                new SuccessResult());

            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            string buildConfiguration = "Debug";

            var buildProperties = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("IsAutoBuild", "True"),
                    new KeyValuePair<string, string>("SomeOtherParam", "Value")
                };

            string buildPropertiesArgument = string.Join(
                NuDeployConstants.MultiValueSeperator.ToString(CultureInfo.InvariantCulture),
                buildProperties.Select(pair => string.Format("{0}={1}", pair.Key, pair.Value)));

            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameBuildConfiguration, buildConfiguration);
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameMSBuildProperties, buildPropertiesArgument);

            buildPropertyParser.Setup(b => b.ParseBuildPropertiesArgument(buildPropertiesArgument)).Returns(buildProperties);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            solutionPackagingService.Verify(
                p =>
                p.PackageSolution(solutionPath, buildConfiguration, It.Is<KeyValuePair<string, string>[]>(d => d.Count() == buildProperties.Count)),
                Times.Once());
        }
        public void Execute_BuildConfigurationArgumentIsNotSet_PackageSolutionIsNotExecuted()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            solutionPackagingService.Verify(s => s.PackageSolution(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<KeyValuePair<string, string>[]>()), Times.Never());
        }
        public void Execute_BuildConfigurationArgumentIsNotSet_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var solutionPackagingService = new Mock<ISolutionPackagingService>();
            var buildPropertyParser = new Mock<IBuildPropertyParser>();
            var publishingService = new Mock<IPublishingService>();
            var packageSolutionCommand = new PackageSolutionCommand(this.loggingUserInterface.UserInterface, solutionPackagingService.Object, buildPropertyParser.Object, publishingService.Object);

            // prepare command arguments
            string solutionPath = @"C:\dev\project-xy\solution.sln";
            packageSolutionCommand.Arguments.Add(PackageSolutionCommand.ArgumentNameSolutionPath, solutionPath);

            // Act
            packageSolutionCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public ConsoleCommandProvider(InstallationStatusCommand installationStatus, InstallCommand install, UninstallCommand uninstall, CleanupCommand cleanup, PackageSolutionCommand packageSolution, PackageBuildOutputCommand packageBuildOutput, RepositorySourceConfigurationCommand configureSources, PublishingTargetConfigurationCommand configurePublishingTargets, SelfUpdateCommand selfUpdate, PublishCommand publishCommand, IHelpCommand helpCommand)
        {
            if (installationStatus == null)
            {
                throw new ArgumentNullException("installationStatus");
            }

            if (install == null)
            {
                throw new ArgumentNullException("install");
            }

            if (uninstall == null)
            {
                throw new ArgumentNullException("uninstall");
            }

            if (cleanup == null)
            {
                throw new ArgumentNullException("cleanup");
            }

            if (packageSolution == null)
            {
                throw new ArgumentNullException("packageSolution");
            }

            if (packageBuildOutput == null)
            {
                throw new ArgumentNullException("packageBuildOutput");
            }

            if (configureSources == null)
            {
                throw new ArgumentNullException("configureSources");
            }

            if (configurePublishingTargets == null)
            {
                throw new ArgumentNullException("configurePublishingTargets");
            }

            if (selfUpdate == null)
            {
                throw new ArgumentNullException("selfUpdate");
            }

            if (publishCommand == null)
            {
                throw new ArgumentNullException("publishCommand");
            }

            if (helpCommand == null)
            {
                throw new ArgumentNullException("helpCommand");
            }

            this.commands = new List<ICommand>
                {
                    installationStatus,
                    install,
                    uninstall,
                    cleanup,
                    packageSolution,
                    packageBuildOutput,
                    configureSources,
                    configurePublishingTargets,
                    selfUpdate,
                    publishCommand,
                    helpCommand
                };
        }