Skip to content

Commit

Permalink
Merge pull request #2876 from Tom-V/features/2815-filter-feature
Browse files Browse the repository at this point in the history
(#2815) Add new choco feature get subcommand
  • Loading branch information
corbob authored Apr 14, 2023
2 parents 720c0e3 + 4d224d5 commit ee01a00
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,113 +33,113 @@ public class ChocolateyConfigCommandSpecs
[ConcernFor("config")]
public abstract class ChocolateyConfigCommandSpecsBase : TinySpec
{
protected ChocolateyConfigCommand command;
protected Mock<IChocolateyConfigSettingsService> configSettingsService = new Mock<IChocolateyConfigSettingsService>();
protected ChocolateyConfiguration configuration = new ChocolateyConfiguration();
protected ChocolateyConfigCommand Command;
protected Mock<IChocolateyConfigSettingsService> ConfigSettingsService = new Mock<IChocolateyConfigSettingsService>();
protected ChocolateyConfiguration Configuration = new ChocolateyConfiguration();

public override void Context()
{
command = new ChocolateyConfigCommand(configSettingsService.Object);
Command = new ChocolateyConfigCommand(ConfigSettingsService.Object);
}
}

public class When_implementing_command_for : ChocolateyConfigCommandSpecsBase
{
private List<string> results;
private List<string> _results;

public override void Because()
{
results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast<CommandForAttribute>().Select(a => a.CommandName).ToList();
_results = Command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast<CommandForAttribute>().Select(a => a.CommandName).ToList();
}

[Fact]
public void Should_implement_config()
{
results.ShouldContain("config");
_results.ShouldContain("config");
}
}

public class When_configurating_the_argument_parser : ChocolateyConfigCommandSpecsBase
{
private OptionSet optionSet;
private OptionSet _optionSet;

public override void Context()
{
base.Context();
optionSet = new OptionSet();
_optionSet = new OptionSet();
}

public override void Because()
{
command.ConfigureArgumentParser(optionSet, configuration);
Command.ConfigureArgumentParser(_optionSet, Configuration);
}

[Fact]
public void Should_add_name_to_the_option_set()
{
optionSet.Contains("name").ShouldBeTrue();
_optionSet.Contains("name").ShouldBeTrue();
}

[Fact]
public void Should_add_value_to_the_option_set()
{
optionSet.Contains("value").ShouldBeTrue();
_optionSet.Contains("value").ShouldBeTrue();
}
}

public class When_noop_is_called : ChocolateyConfigCommandSpecsBase
{
public override void Because()
{
command.DryRun(configuration);
Command.DryRun(Configuration);
}

[Fact]
public void Should_call_service_noop()
{
configSettingsService.Verify(c => c.DryRun(configuration), Times.Once);
ConfigSettingsService.Verify(c => c.DryRun(Configuration), Times.Once);
}
}

public class When_run_is_called : ChocolateyConfigCommandSpecsBase
{
private Action because;
private Action _because;

public override void Because()
{
because = () => command.Run(configuration);
_because = () => Command.Run(Configuration);
}

[Fact]
public void Should_call_service_source_list_when_command_is_list()
public void Should_call_service_config_list_when_command_is_list()
{
configuration.ConfigCommand.Command = ConfigCommandType.List;
because();
configSettingsService.Verify(c => c.ListConfig(configuration), Times.Once);
Configuration.ConfigCommand.Command = ConfigCommandType.List;
_because();
ConfigSettingsService.Verify(c => c.ListConfig(Configuration), Times.Once);
}

[Fact]
public void Should_call_service_source_disable_when_command_is_disable()
public void Should_call_service_config_get_when_command_is_get()
{
configuration.ConfigCommand.Command = ConfigCommandType.Get;
because();
configSettingsService.Verify(c => c.GetConfig(configuration), Times.Once);
Configuration.ConfigCommand.Command = ConfigCommandType.Get;
_because();
ConfigSettingsService.Verify(c => c.GetConfig(Configuration), Times.Once);
}

[Fact]
public void Should_call_service_source_enable_when_command_is_enable()
public void Should_call_service_config_set_when_command_is_set()
{
configuration.ConfigCommand.Command = ConfigCommandType.Set;
because();
configSettingsService.Verify(c => c.SetConfig(configuration), Times.Once);
Configuration.ConfigCommand.Command = ConfigCommandType.Set;
_because();
ConfigSettingsService.Verify(c => c.SetConfig(Configuration), Times.Once);
}

[Fact]
public void Should_call_service_source_unset_when_command_is_unset()
public void Should_call_service_config_unset_when_command_is_unset()
{
configuration.ConfigCommand.Command = ConfigCommandType.Unset;
because();
configSettingsService.Verify(c => c.UnsetConfig(configuration), Times.Once);
Configuration.ConfigCommand.Command = ConfigCommandType.Unset;
_because();
ConfigSettingsService.Verify(c => c.UnsetConfig(Configuration), Times.Once);
}
}
}
Expand Down
Loading

0 comments on commit ee01a00

Please sign in to comment.