-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using Autofac; | ||
using Clio.Command; | ||
using Clio.Package; | ||
using Clio.Project; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Clio.Tests.Command; | ||
|
||
[TestFixture] | ||
public class PushPkgCommandTestCase : BaseCommandTests<PushPkgOptions> | ||
{ | ||
|
||
private readonly ICompileConfigurationCommand _compileConfigurationCommand = Substitute.For<ICompileConfigurationCommand>(); | ||
private readonly IPackageInstaller _packageInstaller = Substitute.For<IPackageInstaller>(); | ||
private readonly IMarketplace _marketplace = Substitute.For<IMarketplace>(); | ||
|
||
protected override void AdditionalRegistrations(ContainerBuilder containerBuilder) { | ||
base.AdditionalRegistrations(containerBuilder); | ||
containerBuilder.RegisterInstance(_compileConfigurationCommand); | ||
containerBuilder.RegisterInstance(_packageInstaller); | ||
containerBuilder.RegisterInstance(_marketplace); | ||
} | ||
|
||
[Test, Category("Unit")] | ||
public void Execute_RunsForceCompilation() { | ||
_compileConfigurationCommand.ClearReceivedCalls(); | ||
PushPackageCommand command = Container.Resolve<PushPackageCommand>(); | ||
PushPkgOptions options = new() { | ||
ForceCompilation = true | ||
}; | ||
_packageInstaller.Install(Arg.Any<string>(), Arg.Any<EnvironmentSettings>(), | ||
Arg.Any<PackageInstallOptions>(), Arg.Any<string>()) | ||
.Returns(true); | ||
_compileConfigurationCommand.Execute(Arg.Any<CompileConfigurationOptions>()) | ||
.Returns(0); | ||
int result = command.Execute(options); | ||
result.Should().Be(0); | ||
_compileConfigurationCommand.Received(1).Execute(Arg.Any<CompileConfigurationOptions>()); | ||
} | ||
|
||
[Test, Category("Unit")] | ||
public void Execute_DoesNotRunningCompilation_WhenInstallFails() { | ||
PushPackageCommand command = Container.Resolve<PushPackageCommand>(); | ||
PushPkgOptions options = new() { | ||
ForceCompilation = true | ||
}; | ||
_packageInstaller.Install(Arg.Any<string>(), Arg.Any<EnvironmentSettings>(), | ||
Arg.Any<PackageInstallOptions>(), Arg.Any<string>()) | ||
.Returns(false); | ||
int result = command.Execute(options); | ||
result.Should().Be(1); | ||
_compileConfigurationCommand.DidNotReceive().Execute(Arg.Any<CompileConfigurationOptions>()); | ||
} | ||
|
||
[Test, Category("Unit")] | ||
public void Execute_DoesNotRunningCompilation_WhenCompilationOptionsFalse() { | ||
PushPackageCommand command = Container.Resolve<PushPackageCommand>(); | ||
PushPkgOptions options = new() { | ||
ForceCompilation = false | ||
}; | ||
_packageInstaller.Install(Arg.Any<string>(), Arg.Any<EnvironmentSettings>(), | ||
Arg.Any<PackageInstallOptions>(), Arg.Any<string>()) | ||
.Returns(true); | ||
int result = command.Execute(options); | ||
result.Should().Be(0); | ||
_compileConfigurationCommand.DidNotReceive().Execute(Arg.Any<CompileConfigurationOptions>()); | ||
} | ||
|
||
[Test, Category("Unit")] | ||
public void Execute_ReturnsFalse_WhenCompilationFails() { | ||
_compileConfigurationCommand.ClearReceivedCalls(); | ||
PushPackageCommand command = Container.Resolve<PushPackageCommand>(); | ||
PushPkgOptions options = new() { | ||
ForceCompilation = true | ||
}; | ||
_packageInstaller.Install(Arg.Any<string>(), Arg.Any<EnvironmentSettings>(), | ||
Arg.Any<PackageInstallOptions>(), Arg.Any<string>()) | ||
.Returns(true); | ||
_compileConfigurationCommand.Execute(Arg.Any<CompileConfigurationOptions>()) | ||
.Returns(1); | ||
int result = command.Execute(options); | ||
result.Should().Be(1); | ||
} | ||
|
||
} |
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