From 9424583d93707e1776ad1186c2f5e81a8ccc2bdd Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Tue, 3 Mar 2015 02:18:37 -0500 Subject: [PATCH] (GH-132) Change ChocolateySourceCommand to an IListCommand In order to make commands support listing, add a new command interface the IListCommand interface is an ICommand with an extra method "list" --- .../commands/ChocolateySourceCommandSpecs.cs | 20 ++++++++++++++- src/chocolatey/chocolatey.csproj | 1 + .../commands/ChocolateySourceCommand.cs | 9 +++++-- .../infrastructure/commands/IListCommand.cs | 25 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/chocolatey/infrastructure/commands/IListCommand.cs diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs index aecaf9d987..55e6654e34 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs @@ -355,7 +355,7 @@ public void should_call_service_source_add_when_command_is_add() because(); configSettingsService.Verify(c => c.source_add(configuration), Times.Once); } - + [Fact] public void should_call_service_source_remove_when_command_is_remove() { @@ -380,5 +380,23 @@ public void should_call_service_source_enable_when_command_is_enable() configSettingsService.Verify(c => c.source_enable(configuration), Times.Once); } } + + public class when_list_is_called : ChocolateySourceCommandSpecsBase + { + private Action because; + + public override void Because() + { + because = () => command.list(configuration); + } + + [Fact] + public void should_call_service_source_list_when_command_is_list() + { + configuration.SourceCommand.Command = SourceCommandType.list; + because(); + configSettingsService.Verify(c => c.source_list(configuration), Times.Once); + } + } } } \ No newline at end of file diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index 379c389c23..854bd24c55 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -161,6 +161,7 @@ + diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs index eafdcac8f4..317ee453c8 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs @@ -28,7 +28,7 @@ namespace chocolatey.infrastructure.app.commands [CommandFor(CommandNameType.sources)] [CommandFor(CommandNameType.source)] - public sealed class ChocolateySourceCommand : ICommand + public sealed class ChocolateySourceCommand : IListCommand { private readonly IChocolateyConfigSettingsService _configSettingsService; @@ -139,5 +139,10 @@ public void run(ChocolateyConfiguration configuration) break; } } + + public IEnumerable list(ChocolateyConfiguration configuration) + { + return _configSettingsService.source_list(configuration); + } } -} \ No newline at end of file +} diff --git a/src/chocolatey/infrastructure/commands/IListCommand.cs b/src/chocolatey/infrastructure/commands/IListCommand.cs new file mode 100644 index 0000000000..d24a89ccb2 --- /dev/null +++ b/src/chocolatey/infrastructure/commands/IListCommand.cs @@ -0,0 +1,25 @@ +// Copyright © 2015 - 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.infrastructure.commands +{ + using System.Collections.Generic; + using app.configuration; + + public interface IListCommand : ICommand + { + IEnumerable list(ChocolateyConfiguration config); + } +}