Skip to content

Commit

Permalink
(chocolateyGH-132) Change ChocolateySourceCommand to an IListCommand
Browse files Browse the repository at this point in the history
In order to make commands support listing, add a new command interface
 the IListCommand interface is an ICommand with an extra method "list"
  • Loading branch information
Jaykul committed Mar 4, 2015
1 parent a7ccc86 commit f479a83
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Expand Up @@ -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()
{
Expand All @@ -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);
}
}
}
}
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Expand Up @@ -161,6 +161,7 @@
<Compile Include="infrastructure\commandline\ExitScenarioHandler.cs" />
<Compile Include="infrastructure\commandline\InteractivePrompt.cs" />
<Compile Include="infrastructure\commands\ICommandExecutor.cs" />
<Compile Include="infrastructure\commands\IListCommand.cs" />
<Compile Include="infrastructure\commands\PowershellExecutor.cs" />
<Compile Include="infrastructure\guards\Ensure.cs" />
<Compile Include="infrastructure\information\ProcessInformation.cs" />
Expand Down
Expand Up @@ -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<ChocolateySource>
{
private readonly IChocolateyConfigSettingsService _configSettingsService;

Expand Down Expand Up @@ -139,5 +139,10 @@ public void run(ChocolateyConfiguration configuration)
break;
}
}

public IEnumerable<ChocolateySource> list(ChocolateyConfiguration configuration)
{
return _configSettingsService.source_list(configuration);
}
}
}
}
25 changes: 25 additions & 0 deletions 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<out T> : ICommand
{
IEnumerable<T> list(ChocolateyConfiguration config);
}
}

0 comments on commit f479a83

Please sign in to comment.