-
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.
Add unit tests for InstallerCommand and CreatioInstallerService
Introduce comprehensive unit tests for InstallerCommand's execution modes and CreatioInstallerService's build file path resolution. This ensures that different scenarios for silent and non-silent installations, as well as file path retrieval from remote servers, are properly covered. Also removed redundant InstallerCommandTests file to streamline the code. Signed-off-by: Kirill Krylov <[email protected]>
- Loading branch information
1 parent
29f3410
commit 7727ef3
Showing
11 changed files
with
986 additions
and
309 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,108 @@ | ||
using System; | ||
using System.IO; | ||
using Autofac; | ||
using Clio.Command.CreatioInstallCommand; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Clio.Tests.Command; | ||
|
||
[Author("Kirill Krylov", "[email protected]")] | ||
[Category("UnitTests")] | ||
[TestFixture] | ||
internal class InstallerCommandTests : BaseCommandTests<PfInstallerOptions> | ||
{ | ||
|
||
|
||
ICreatioInstallerService _creatioInstallerServiceMock = Substitute.For<ICreatioInstallerService>(); | ||
protected override void AdditionalRegistrations(ContainerBuilder containerBuilder){ | ||
base.AdditionalRegistrations(containerBuilder); | ||
containerBuilder.RegisterInstance(_creatioInstallerServiceMock); | ||
|
||
} | ||
|
||
[Test(Description = "Should return without waiting for user input")] | ||
public void Execute_ReturnsWithoutWaitingForInput_WhenSilent(){ | ||
//Arrange | ||
var command = Container.Resolve<InstallerCommand>(); | ||
PfInstallerOptions options = new () { | ||
IsSilent = true | ||
}; | ||
_creatioInstallerServiceMock.Execute(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
//Act | ||
var actual = command.Execute(options); | ||
|
||
//Assert | ||
actual.Should().Be(0); | ||
} | ||
|
||
[Test(Description = "Execute completes on Enter when not silent")] | ||
public void Execute_ReturnsAfterConsoleInput_WhenNotSilent(){ | ||
//Arrange | ||
var command = Container.Resolve<InstallerCommand>(); | ||
PfInstallerOptions options = new () { | ||
IsSilent = false | ||
}; | ||
_creatioInstallerServiceMock.Execute(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
//Act | ||
var stringReader = new StringReader("A"); | ||
Console.SetIn(stringReader); | ||
|
||
var actual = command.Execute(options); | ||
//Assert | ||
actual.Should().Be(0); | ||
|
||
} | ||
|
||
[Test(Description = "Should return 0 when OK")] | ||
public void Execute_DoesNotOpenBrowser_WhenSilent(){ | ||
//Arrange | ||
var command = Container.Resolve<InstallerCommand>(); | ||
PfInstallerOptions options = new PfInstallerOptions() { | ||
IsSilent = true | ||
}; | ||
_creatioInstallerServiceMock.Execute(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
_creatioInstallerServiceMock.StartWebBrowser(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
//Act | ||
var actual = command.Execute(options); | ||
|
||
//Assert | ||
actual.Should().Be(0); | ||
_creatioInstallerServiceMock.Received(0).StartWebBrowser(options); | ||
} | ||
|
||
[Test(Description = "Should open browser")] | ||
public void Execute_OpensBrowser_WhenNotSilent(){ | ||
//Arrange | ||
var command = Container.Resolve<InstallerCommand>(); | ||
PfInstallerOptions options = new PfInstallerOptions() { | ||
IsSilent = false | ||
}; | ||
_creatioInstallerServiceMock.Execute(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
_creatioInstallerServiceMock.StartWebBrowser(Arg.Any<PfInstallerOptions>()) | ||
.Returns(0); | ||
|
||
var stringReader = new StringReader("A"); | ||
Console.SetIn(stringReader); | ||
|
||
//Act | ||
var actual = command.Execute(options); | ||
//Assert | ||
actual.Should().Be(0); | ||
|
||
|
||
_creatioInstallerServiceMock.Received(1).StartWebBrowser(options); | ||
} | ||
|
||
} |
Oops, something went wrong.