public void ConstructorThrowsIfSettingsIsNull()
 {
     // Act and Assert
     var configCommand = new ConfigCommand();
     ExceptionAssert.Throws<InvalidOperationException>(
         () => configCommand.ExecuteCommand(),
         "Property Settings is null.");
 }
Beispiel #2
0
        public void ExecutePrintsNothingIfNoArgumentsAndNoSetPropertiesAreSpecified()
        {
            // Arrange
            var settings = Mock.Of<ISettings>();
            var console = new MockConsole();
            var command = new ConfigCommand(settings)
                                {
                                    Console = console
                                };

            // Act
            command.ExecuteCommand();

            // Assert
            Assert.Empty(console.Output);
        }
Beispiel #3
0
        public void ExecutePrintsValueOfKeyIfArgumentIsSpecified()
        {
            // Arrange
            var settings = new Mock<ISettings>(MockBehavior.Strict);
            settings.Setup(s => s.GetValue("config", "test")).Returns("value").Verifiable();

            var console = new MockConsole();
            var command = new ConfigCommand(settings.Object)
            {
                Console = console,
            };
            command.Arguments.Add("test");

            // Act
            command.ExecuteCommand();

            // Assert
            Assert.Equal("value", console.Output.Trim());
            settings.Verify();
        }
Beispiel #4
0
        public void SpecifiedPropertiesAreSetInConfig()
        {
            // Arrange
            var settings = new Mock<ISettings>(MockBehavior.Strict);
            settings.Setup(s => s.SetValue("config", "test", "value2")).Verifiable();
            settings.Setup(s => s.SetValue("config", "test2", "value1")).Verifiable();

            var console = new MockConsole();
            var command = new ConfigCommand(settings.Object)
            {
                Console = console,
            };
            command.Set.Add("test", "value2");
            command.Set.Add("test2", "value1");

            // Act
            command.ExecuteCommand();

            // Assert
            settings.Verify();
        }
        public void SpecifiedPropertiesAreDeletedIfNoValueIsProvidedToSetProperties()
        {
            // Arrange
            var settings = new Mock<ISettings>(MockBehavior.Strict);
            settings.Setup(s => s.DeleteValue("config", "test")).Returns(true).Verifiable();

            var console = new MockConsole();
            var command = new ConfigCommand()
            {
                Settings = settings.Object,
                Console = console,
            };
            command.Set.Add("test", "");

            // Act
            command.ExecuteCommand();

            // Assert
            settings.Verify();
        }
        public void ExecuteThrowsIfSettingsIsNullSettings()
        {
            // Arrange
            var command = new ConfigCommand()
            {
                Settings = NullSettings.Instance
            };
            command.Set.Add("foo", "bar");

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(
                () => command.ExecuteCommand(),
                "\"SetValue\" cannot be called on a NullSettings. This may be caused on account of insufficient permissions to read or write to \"%AppData%\\NuGet\\NuGet.config\".");
        }