public void Run_ShouldSetParametersOnInstallPackageCommand()
        {
            // Arrange
            var roleFile = Path.Combine( @"config\roles" , RoleCommandFile);
            _nployConfigurationMock.Setup(x => x.FileExists(roleFile)).Returns(true);
            var roleConfig = new RoleConfig();
            roleConfig.Packages.Add(new PackageConfig { Id = "Test.Package" });
            _nployConfigurationMock.Setup(x => x.GetRoleConfig(roleFile)).Returns(roleConfig);

            _commandFactory.Setup(x => x.GetCommand<InstallPackageCommand>()).Returns(_installPackageCommandMock.Object);

            // Act
            _command.PackageSources = "source";
            _command.Environment= "test";
            _command.NuGetPath = "nugetpath";
            _command.ConfigurationDirectory = "config";
            _command.InstallDirectory = @"c:\install";
            _command.Properties = "properties";
            _command.IncludePrerelease = true;
            var result = _command.Run(new[] { RoleCommandFile });

            // Assert
            Assert.That(result, Is.EqualTo(0));
            _installPackageCommandMock.VerifySet(c => c.PackageSources="source", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.Environment = "test", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.WorkingDirectory = @"c:\install", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.NuGetPath = "nugetpath", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.ConfigurationDirectory = "config", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.Properties = "properties", Times.Once());
            _installPackageCommandMock.VerifySet(c => c.IncludePrerelease = true, Times.Once());
        }
        public void Run_ShouldInstallPackage()
        {
            // Arrange
            var roleFile = Path.Combine(_currentDirectory, @"roles\" + RoleCommandFile);
            _nployConfigurationMock.Setup(x => x.FileExists(roleFile)).Returns(true);
            var roleConfig = new RoleConfig();
            roleConfig.Packages.Add(new PackageConfig{Id="Test.Package"});
            _nployConfigurationMock.Setup(x => x.GetRoleConfig(roleFile)).Returns(roleConfig);

            _commandFactory.Setup(x => x.GetCommand<InstallPackageCommand>()).Returns(_installPackageCommandMock.Object);

            // Act
            var result = _command.Run(new[] { RoleCommandFile });

            // Assert
            Assert.That(result, Is.EqualTo(0));
            _installPackageCommandMock.Verify(c => c.Run(new[] { "Test.Package" }), Times.Once());
        }
Exemple #3
0
        public RoleConfig GetRoleConfig(string roleFile)
        {
            var roleConfig = new RoleConfig();

            var doc = XDocument.Load(roleFile);

            var rootElement = doc.Root;
            roleConfig.SubFolder = rootElement.Attribute("subFolder") != null ? rootElement.Attribute("subFolder").Value : "";

            var docPackages = doc.Descendants("package");
            foreach (var docPackage in docPackages)
            {
                roleConfig.Packages.Add(new PackageConfig
                {
                    Id = docPackage.Attribute("id").Value,
                    Version =
                        docPackage.Attribute("version") != null ? docPackage.Attribute("version").Value : null
                });
            }
            return roleConfig;
        }