Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public void AddCommandThrowsIfNameIsNullOrEmpty(string name)
 {
     // Arrange
     var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
     var sourceCommand = new SourcesCommand(packageSourceProvider.Object) {
         Name = name
     };
     sourceCommand.Arguments.Add("ADD");
     
     // Act and Assert
     ExceptionAssert.Throws<CommandLineException>(sourceCommand.Execute, "The name specified cannot be empty. Please provide a valid name.");
 }
Esempio n. 4
0
        public void ProvidingNoArgumentListsPackages()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource("FirstSource", "FirstName") });
            var sourceCommand = new SourcesCommand(packageSourceProvider.Object);
            string expectedText =
@"Registered Sources:
  1.  FirstName [Enabled]
      FirstSource
";
            var stringBuilder = new StringBuilder();
            var console = new MockConsole();

            var sourcesCommand = new SourcesCommand(packageSourceProvider.Object);
            sourceCommand.Console = console;

            // Act
            sourceCommand.Execute();

            // Assert
            Assert.Equal(expectedText, console.Output);
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public void UpdateThrowsIfOnlyOneOfUsernameOrPasswordIsSpecified(string userName, string password)
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("http://testsource") });
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "http://TestSource",
                UserName = userName,
                Password = password
            };
            sourceCommand.Arguments.Add("UPDATE");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "Both UserName and Password must be specified.");
        }
Esempio n. 7
0
        public void UpdateCommandThrowsIfSourceAlreadyExists()
        {
            // Arrange
            var sources = new[] { new PackageSource("Abcd"), new PackageSource("http://test-source", "source") };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "Abcd",
                Source = "http://test-source"
            };
            sourceCommand.Arguments.Add("update");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand,
                "The source specified has already been added to the list of available package sources. Please provide a unique source.");
        }
Esempio n. 8
0
        public void UpdateCommandThrowsIfSourceIsInvalid()
        {
            // Arrange
            var sources = new[] { new PackageSource("Abcd"), new PackageSource("pqrs") };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "Abcd",
                Source = "http:\\bad-url"
            };
            sourceCommand.Arguments.Add("update");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "The source specified is invalid. Please provide a valid source.");
        }
Esempio n. 9
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);
        }
Esempio n. 10
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();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        public void AddCommandThrowsIfOnlyOneOfUsernameOrPasswordIsSpecified(string userName, string password)
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "TestName",
                Source = "http://TestSource",
                UserName = userName,
                Password = password
            };
            sourceCommand.Arguments.Add("ADD");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "Both UserName and Password must be specified.");
        }
Esempio n. 13
0
        public void AddCommandThrowsIfNameAlreadyExists()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(s => s.LoadPackageSources())
                                 .Returns(new[] { new PackageSource("http://TestSource", "TestName") });
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "TestName",
                Source = "http://nuget.org"
            };
            sourceCommand.Arguments.Add("ADD");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "The name specified has already been added to the list of available package sources. Please provide a unique name.");
        }
Esempio n. 14
0
        public void AddCommandThrowsIfSourceIsInvalid(string source)
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "Test",
                Source = source
            };
            sourceCommand.Arguments.Add("ADD");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "The source specified is invalid. Please provide a valid source.");
        }
Esempio n. 15
0
        public void AddCommandThrowsIfNameIsAll()
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "All"
            };
            sourceCommand.Arguments.Add("ADD");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "Package source name 'All' is a reserved name.");
        }
Esempio n. 16
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();
        }
Esempio n. 17
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();
        }
Esempio n. 18
0
        public void UpdateCommandThrowsIfSourceIsNullOrEmpty(string source)
        {
            // Arrange
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = source,
                Source = "Source"
            };
            sourceCommand.Arguments.Add("update");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "The name specified cannot be empty. Please provide a valid name.");
        }
Esempio n. 19
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();
        }
Esempio n. 20
0
        public void UpdateCommandThrowsIfNameDoesNotExist()
        {
            // Arrange
            var sources = new[] { new PackageSource("Abcd") };
            var packageSourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            packageSourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
            var sourceCommand = new SourcesCommand()
            {
                SourceProvider = packageSourceProvider.Object,
                Name = "efgh",
            };
            sourceCommand.Arguments.Add("update");

            // Act and Assert
            ExceptionAssert.Throws<CommandLineException>(sourceCommand.ExecuteCommand, "Unable to find any package source(s) matching name: efgh.");
        }