public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            // Act
            var packageBuildOutputCommand = new PackageBuildOutputCommand(userInterface.Object, buildOutputPackagingService.Object, publishingService.Object);

            // Assert
            Assert.IsNotNull(packageBuildOutputCommand);
        }
        public void Constructor_CommandAttributesAreInitializedProperly()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            // Act
            var packageBuildOutputCommand = new PackageBuildOutputCommand(userInterface.Object, buildOutputPackagingService.Object, publishingService.Object);

            // Assert
            CommandTestUtilities.ValidateCommandAttributes(packageBuildOutputCommand.Attributes);
        }
        public void Execute_PublishingSucceeds_SuccessMessageIsWrittenTouUserInterface()
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            string packagePath = @"C:\some-package.nupkg";
            buildOutputPackagingService.Setup(b => b.Package(It.IsAny<string>())).Returns(new SuccessResult { ResultArtefact = packagePath });
            publishingService.Setup(p => p.PublishPackage(It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare arguments
            string publishConfigurationName = "Some Publish Configuration";
            string buildOutputFolderPath = "C:\\build-output";
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputFolderPath);
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageBuildOutputCommand.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
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            buildOutputPackagingService.Setup(b => b.Package(It.IsAny<string>())).Returns(new SuccessResult());

            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 packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare arguments
            string publishConfigurationName = "Some Publish Configuration";
            string buildOutputFolderPath = "C:\\build-output";
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputFolderPath);
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageBuildOutputCommand.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
            var userInterface = new Mock<IUserInterface>();
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            buildOutputPackagingService.Setup(b => b.Package(It.IsAny<string>())).Returns(new SuccessResult());
            publishingService.Setup(p => p.PublishPackage(It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var packageBuildOutputCommand = new PackageBuildOutputCommand(userInterface.Object, buildOutputPackagingService.Object, publishingService.Object);

            // prepare arguments
            string publishConfigurationName = "Some Publish Configuration";
            string buildOutputFolderPath = "C:\\build-output";
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputFolderPath);
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNamePublishingConfiguration, publishConfigurationName);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            publishingService.Verify(p => p.PublishPackage(It.IsAny<string>(), publishConfigurationName), Times.Once());
        }
        public void Execute_PackagingSucceeds_ResultIsTrue()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            buildOutputPackagingService.Setup(b => b.Package(It.IsAny<string>())).Returns(new SuccessResult());

            var packageBuildOutputCommand = new PackageBuildOutputCommand(userInterface.Object, buildOutputPackagingService.Object, publishingService.Object);

            // prepare arguments
            string buildOutputFolderPath = "C:\\build-output";
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputFolderPath);

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

            // Assert
            Assert.IsTrue(result);
        }
        public void Execute_BuildOutputPathArgumentIsNotSet_ResultIsFalse()
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

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

            // Assert
            Assert.AreEqual(false, result);
        }
        public void Execute_PackagingSucceeds_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();

            buildOutputPackagingService.Setup(b => b.Package(It.IsAny<string>())).Returns(new SuccessResult());

            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare arguments
            string buildOutputFolderPath = "C:\\build-output";
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputFolderPath);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput));
        }
        public void Execute_BuildOutputPathArgumentIsNotSet_MessageIsWrittenToUserInterface()
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
        public void Execute_BuildOutputPathArgumentIsNotSet_PackageSolutionIsNotExecuted()
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            buildOutputPackagingService.Verify(s => s.Package(It.IsAny<string>()), Times.Never());
        }
        public void Execute_BuildOutputPathArgumentIsInvalid_ResultIsFalse(string buildOutputPath)
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare command arguments
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputPath);

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

            // Assert
            Assert.AreEqual(false, result);
        }
        public void Execute_BuildOutputPathArgumentIsInvalid_PackageSolutionIsNotExecuted(string buildOutputPath)
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare command arguments
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputPath);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            buildOutputPackagingService.Verify(s => s.Package(It.IsAny<string>()), Times.Never());
        }
        public void Execute_BuildOutputPathArgumentIsInvalid_MessageIsWrittenToUserInterface(string buildOutputPath)
        {
            // Arrange
            var buildOutputPackagingService = new Mock<IBuildOutputPackagingService>();
            var publishingService = new Mock<IPublishingService>();
            var packageBuildOutputCommand = new PackageBuildOutputCommand(this.loggingUserInterface.UserInterface, buildOutputPackagingService.Object, publishingService.Object);

            // prepare command arguments
            packageBuildOutputCommand.Arguments.Add(PackageBuildOutputCommand.ArgumentNameBuildOutputFolderPath, buildOutputPath);

            // Act
            packageBuildOutputCommand.Execute();

            // Assert
            Assert.IsNotNullOrEmpty(this.loggingUserInterface.UserInterfaceOutput);
        }
 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 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
                };
        }