-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a config section to the configuration file. Move the existing items into that section that are not apikeys, sources, or features. Search for existing settings and port the value to the new location. Allow querying and setting these configuration values.
- Loading branch information
1 parent
5f77d6c
commit 362507c
Showing
15 changed files
with
524 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.tests.infrastructure.app.commands | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Moq; | ||
using Should; | ||
using chocolatey.infrastructure.app.attributes; | ||
using chocolatey.infrastructure.app.commands; | ||
using chocolatey.infrastructure.app.configuration; | ||
using chocolatey.infrastructure.app.domain; | ||
using chocolatey.infrastructure.app.services; | ||
using chocolatey.infrastructure.commandline; | ||
|
||
public class ChocolateyConfigCommandSpecs | ||
{ | ||
public abstract class ChocolateyConfigCommandSpecsBase : TinySpec | ||
{ | ||
protected ChocolateyConfigCommand command; | ||
protected Mock<IChocolateyConfigSettingsService> configSettingsService = new Mock<IChocolateyConfigSettingsService>(); | ||
protected ChocolateyConfiguration configuration = new ChocolateyConfiguration(); | ||
|
||
public override void Context() | ||
{ | ||
command = new ChocolateyConfigCommand(configSettingsService.Object); | ||
} | ||
} | ||
|
||
public class when_implementing_command_for : ChocolateyConfigCommandSpecsBase | ||
{ | ||
private List<string> results; | ||
|
||
public override void Because() | ||
{ | ||
results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast<CommandForAttribute>().Select(a => a.CommandName).ToList(); | ||
} | ||
|
||
[Fact] | ||
public void should_implement_config() | ||
{ | ||
results.ShouldContain(CommandNameType.config.to_string()); | ||
} | ||
} | ||
|
||
public class when_configurating_the_argument_parser : ChocolateyConfigCommandSpecsBase | ||
{ | ||
private OptionSet optionSet; | ||
|
||
public override void Context() | ||
{ | ||
base.Context(); | ||
optionSet = new OptionSet(); | ||
} | ||
|
||
public override void Because() | ||
{ | ||
command.configure_argument_parser(optionSet, configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_add_name_to_the_option_set() | ||
{ | ||
optionSet.Contains("name").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_value_to_the_option_set() | ||
{ | ||
optionSet.Contains("value").ShouldBeTrue(); | ||
} | ||
} | ||
|
||
public class when_noop_is_called : ChocolateyConfigCommandSpecsBase | ||
{ | ||
public override void Because() | ||
{ | ||
command.noop(configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_noop() | ||
{ | ||
configSettingsService.Verify(c => c.noop(configuration), Times.Once); | ||
} | ||
} | ||
|
||
public class when_run_is_called : ChocolateyConfigCommandSpecsBase | ||
{ | ||
private Action because; | ||
|
||
public override void Because() | ||
{ | ||
because = () => command.run(configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_source_list_when_command_is_list() | ||
{ | ||
configuration.ConfigCommand.Command = ConfigCommandType.list; | ||
because(); | ||
configSettingsService.Verify(c => c.config_list(configuration), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_source_disable_when_command_is_disable() | ||
{ | ||
configuration.ConfigCommand.Command = ConfigCommandType.get; | ||
because(); | ||
configSettingsService.Verify(c => c.config_get(configuration), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_source_enable_when_command_is_enable() | ||
{ | ||
configuration.ConfigCommand.Command = ConfigCommandType.set; | ||
because(); | ||
configSettingsService.Verify(c => c.config_set(configuration), Times.Once); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.