NuDeploy.CommandLine.Commands.Console.InstallationStatusCommand.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : bool
return bool
        public bool Execute()
        {
            // package id
            string packageId = this.Arguments.ContainsKey(ArgumentNameNugetPackageId) ? this.Arguments[ArgumentNameNugetPackageId] : string.Empty;

            // retrieve packages
            IList<NuDeployPackageInfo> packages = string.IsNullOrWhiteSpace(packageId)
                                                      ? this.installationStatusProvider.GetPackageInfo().ToList()
                                                      : this.installationStatusProvider.GetPackageInfo(packageId).ToList();

            // abort if no packages are returned
            if (packages.Count == 0)
            {
                this.userInterface.WriteLine(
                    string.IsNullOrWhiteSpace(packageId)
                        ? Resources.InstallationStatusCommand.NoPackagesInstalledMessage
                        : string.Format(Resources.InstallationStatusCommand.NoInstancesOfPackageInstalledMessageTemplate, packageId));

                return true;
            }

            // display package installation status
            var dataToDisplay = new Dictionary<string, string>
                {
                    { Resources.InstallationStatusCommand.InstallationStatusTableHeadlineColumn1, Resources.InstallationStatusCommand.InstallationStatusTableHeadlineColumn2 },
                    { new string('-', Resources.InstallationStatusCommand.InstallationStatusTableHeadlineColumn1.Length + 3), new string('-', Resources.InstallationStatusCommand.InstallationStatusTableHeadlineColumn2.Length + 3) },
                    { string.Empty, string.Empty },
                };

            foreach (NuDeployPackageInfo package in packages)
            {
                string key = string.Format(Resources.InstallationStatusCommand.InstallationStatusTableKeyColumnTemplate, package.Id, package.Version);
                string value = package.IsInstalled
                                   ? Resources.InstallationStatusCommand.PackageIsInstalled
                                   : Resources.InstallationStatusCommand.PackageIsNotInstalled;

                dataToDisplay.Add(key, value);
            }

            this.userInterface.ShowKeyValueStore(dataToDisplay, 4);
            return true;
        }

Usage Example

        public void Execute_InstallationStatusProviderReturnsPackages_OneMessageForEachPackageIsWrittenToUserInterface()
        {
            // Arrange
            var installationStatusProvider = new Mock<IInstallationStatusProvider>();

            var packages = new List<NuDeployPackageInfo>
                {
                    new NuDeployPackageInfo { Id = "Package.A", Version = new SemanticVersion(1, 0, 0, 1), IsInstalled = true },
                    new NuDeployPackageInfo { Id = "Package.B", Version = new SemanticVersion(1, 0, 0, 2), IsInstalled = false },
                };
            installationStatusProvider.Setup(i => i.GetPackageInfo()).Returns(packages);

            var installationStatusCommand = new InstallationStatusCommand(this.loggingUserInterface.UserInterface, installationStatusProvider.Object);

            // Act
            installationStatusCommand.Execute();

            // Assert
            foreach (var packageInfo in packages)
            {
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(packageInfo.Id));
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(packageInfo.Version.ToString()));
            }
        }
All Usage Examples Of NuDeploy.CommandLine.Commands.Console.InstallationStatusCommand::Execute
InstallationStatusCommand