Skip to content

Commit

Permalink
Add unit tests for InstallerCommand and CreatioInstallerService
Browse files Browse the repository at this point in the history
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
kirillkrylov committed Aug 15, 2024
1 parent 29f3410 commit 7727ef3
Show file tree
Hide file tree
Showing 11 changed files with 986 additions and 309 deletions.
108 changes: 108 additions & 0 deletions clio.tests/Command/InstallerCommand.cs
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);
}

}
Loading

0 comments on commit 7727ef3

Please sign in to comment.