ExecuteCommand() public method

public ExecuteCommand ( ) : void
return void
Exemplo n.º 1
0
        public void ProvidingListArgumentListsPackageSources()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource("FirstSource", "FirstName", isEnabled: false) });
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object
            };
            sourceCommand.Arguments.Add("list");

            var console = new MockConsole();

            string expectedText =
@"Registered Sources:
  1.  FirstName [Disabled]
      FirstSource
";

            sourceCommand.Console = console;

            // Act
            sourceCommand.ExecuteCommand();

            // Assert
            Assert.Equal(expectedText, console.Output);
        }
Exemplo n.º 2
0
        public void DisableCommandDoNotAffectPackageSourcesThatAreAlreadyDisabled()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var expectedSources = new[] 
                                  { 
                                    new PackageSource("onesource", "one") { IsEnabled = true } ,
                                    new PackageSource("twosource", "two") { IsEnabled = false } ,
                                    new PackageSource("threesource", "three") { IsEnabled = true } ,
                                  };

            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(
                new[] 
                { 
                    new PackageSource("onesource", "one") { IsEnabled = true } ,
                    new PackageSource("twosource", "two") { IsEnabled = false } ,
                    new PackageSource("threesource", "three") { IsEnabled = true } ,
                }
            );
            packageSourceProvider.Setup(s => s.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                                 .Callback((IEnumerable<PackageSource> sources) => Assert.Equal(expectedSources, sources))
                                 .Verifiable();

            var command = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object
            };
            command.Arguments.Add("Disable");
            command.Name = "two";
            command.Console = new Mock<IConsole>().Object;

            // Act
            command.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 3
0
        public void SpecifyingFormatShortSwitchesNugetSourcesListOutputToScriptParsableOutput()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[]
                {
                    new PackageSource("DisabledSourceUri", "FirstName", isEnabled: false),
                    new PackageSource("FirstEnabledSourceUri", "SecondName", isEnabled: true),
                    new PackageSource("SecondEnabledSourceUri", "ThirdName", isEnabled: true),
                    new PackageSource("OfficialDisabledSourceUri", "FourthName", isEnabled: false, isOfficial: true), 
                    new PackageSource("OfficialEnabledSourceUri", "FifthName", isEnabled: true, isOfficial: true), 
                });
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object
            };
            sourceCommand.Arguments.Add("list");
            sourceCommand.Format = SourcesListFormat.Short;

            var console = new MockConsole();

            string expectedText =
@"D DisabledSourceUri
E FirstEnabledSourceUri
E SecondEnabledSourceUri
DO OfficialDisabledSourceUri
EO OfficialEnabledSourceUri
";

            sourceCommand.Console = console;

            // Act
            sourceCommand.ExecuteCommand();

            // Assert
            Assert.Equal(expectedText, console.Output);
        }
Exemplo n.º 4
0
        public void EnableCommandEnableDisabledSourcesCorrectly()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("Two") { IsEnabled = false } });
            packageSourceProvider.Setup(s => s.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                                 .Callback((IEnumerable<PackageSource> sources) => Assert.Equal(new[] { new PackageSource("Two") { IsEnabled = true } }, sources))
                                 .Verifiable();

            var command = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object
            };
            command.Arguments.Add("Enable");
            command.Name = "two";
            command.Console = new Mock<IConsole>().Object;

            // Act
            command.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 5
0
        public void UpdateCommandStoresPasswordInClearTextWhenStorePasswordInClearTextIsTrue()
        {
            // Arrange
            string userName = "******";
            string password = "******";
            var sources = new[] { new PackageSource("First") { IsPasswordClearText = true }, new PackageSource("Abcd") { IsPasswordClearText = true }, new PackageSource("http://test-source", "source") { IsPasswordClearText = true } };
            var expectedSources = new[] { new PackageSource("First") { IsPasswordClearText = true }, new PackageSource("http://abcd-source", "Abcd") { IsPasswordClearText = true }, 
                                          new PackageSource("http://test-source", "source")  { IsPasswordClearText = true }};
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            packageSourceProvider.Setup(c => c.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                                 .Callback((IEnumerable<PackageSource> actualSources) =>
                                 {
                                     Assert.Equal(expectedSources, actualSources);
                                     var s = actualSources.ElementAt(1);
                                     Assert.Equal(userName, s.UserName);
                                     Assert.Equal(password, s.Password);
                                     Assert.True(s.IsPasswordClearText);
                                 })
                                 .Verifiable();

            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "Abcd",
                Source = "http://abcd-source",
                UserName = userName,
                Password = password,
                StorePasswordInClearText = true
            };
            sourceCommand.Arguments.Add("update");
            sourceCommand.Console = new MockConsole();

            // Act 
            sourceCommand.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 6
0
        public void UpdateCommandPreservesOrder()
        {
            // Arrange
            var sources = new[] { new PackageSource("First"), new PackageSource("Abcd"), new PackageSource("http://test-source", "source") };
            var expectedSources = new[] { new PackageSource("First"), new PackageSource("http://abcd-source", "Abcd"), 
                                          new PackageSource("http://test-source", "source") };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            packageSourceProvider.Setup(c => c.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                                 .Callback((IEnumerable<PackageSource> actualSources) => Assert.Equal(expectedSources, actualSources))
                                 .Verifiable();

            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "Abcd",
                Source = "http://abcd-source"
            };
            sourceCommand.Arguments.Add("update");
            sourceCommand.Console = new MockConsole();

            // Act 
            sourceCommand.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 7
0
        public void RemoveCommandRemovesMatchingSources()
        {
            // Arrange
            var sources = new[] { new PackageSource("Abcd"), new PackageSource("EFgh"), new PackageSource("pqrs") };
            var expectedSource = new[] { new PackageSource("Abcd"), new PackageSource("pqrs") };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            packageSourceProvider.Setup(c => c.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                                 .Callback((IEnumerable<PackageSource> src) => Assert.Equal(expectedSource, src))
                                 .Verifiable();
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "efgh",
            };
            sourceCommand.Arguments.Add("remove");
            sourceCommand.Console = new MockConsole();

            // Act 
            sourceCommand.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 8
0
        public void AddCommandAddsSourceToSourceProviderWithPasswordInClearTextWhenStorePasswordInClearTextIsTrue()
        {
            // Arrange
            var expectedSources = new[] { new PackageSource("http://TestSource", "TestName"), new PackageSource("http://new-source", "new-source-name") { IsPasswordClearText = true } };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(s => s.LoadPackageSources())
                                 .Returns(new[] { new PackageSource("http://TestSource", "TestName") });
            packageSourceProvider.Setup(s => s.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>()))
                .Callback((IEnumerable<PackageSource> source) => Assert.Equal(expectedSources, source)).Verifiable();
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "new-source-name",
                Source = "http://new-source",
                StorePasswordInClearText = true
            };
            sourceCommand.Arguments.Add("add");
            sourceCommand.Console = new MockConsole();

            // Act 
            sourceCommand.ExecuteCommand();

            // Assert
            packageSourceProvider.Verify();
        }
Exemplo n.º 9
0
        public void EnableCommandEnableDisabledSourcesCorrectly()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            settings.SetValues(PackageSourceProvider.PackageSourcesSectionName,
               new[] {
                    new KeyValuePair<string, string>("one", "onesource"),       // enabled
                    new KeyValuePair<string, string>("two", "twosource"),       // disabled
                    new KeyValuePair<string, string>("three", "threesource")    // enabled
                });
            settings.SetValues(PackageSourceProvider.DisabledPackageSourcesSectionName,
                new[] {
                    new KeyValuePair<string, string>("two", "true")
                });

            var packageSourceProvider = new PackageSourceProvider(settings);
            var command = new SourcesCommand(packageSourceProvider);
            command.Arguments.Add("Enable");
            command.Name = "two";
            command.Console = new Mock<IConsole>().Object;

            // Act
            command.ExecuteCommand();

            // Assert
            var packageSources = packageSourceProvider.LoadPackageSources().ToList();
            Assert.Equal(3, packageSources.Count);
            Assert.True(packageSources[0].IsEnabled);
            Assert.True(packageSources[1].IsEnabled);
            Assert.True(packageSources[2].IsEnabled);
        }