Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default values for TimeOut, RetryCount, RetryDelay in RemoteCom… #301

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clio.tests/Command/AssemblyCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public void Execute_ShouldWriteResponse_WhenItIsSuccessful(){
string executorType = typeof(AssemblyCommand).FullName;
_applicationClientMock.ExecutePostRequest(
Arg.Is<string>(path => path.EndsWith("/IDE/ExecuteScript")),
Arg.Is<string>(request => CheckRequest(request, executorType)))
Arg.Is<string>(request => CheckRequest(request, executorType)),
Arg.Any<int>(), Arg.Any<int>(), Arg.Any<int>()
)
.Returns("responseFromServer");

// Act
Expand Down
2 changes: 1 addition & 1 deletion clio.tests/Command/DeletePackageCommand.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Delete_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetFra
deleteCommand.Execute(deleteOptions);
applicationClient.Received(1).ExecutePostRequest(
deleteOptions.Uri + "/0/ServiceModel/AppInstallerService.svc/DeletePackage",
"\"TestPackage\"", Arg.Any<int>());
"\"TestPackage\"", Arg.Any<int>(), Arg.Any<int>(), Arg.Any<int>());
}
}
}
56 changes: 41 additions & 15 deletions clio.tests/Command/PingAppCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,77 @@
using Autofac;
using Clio.Command;
using Clio.Common;
using Creatio.Client;
using FluentAssertions;
using NSubstitute;
using NSubstitute.ReceivedExtensions;
using NUnit.Framework;

namespace Clio.Tests.Command
{

[TestFixture]
[TestFixture(Category = "Unit")]
internal class PingAppCommandTests : BaseClioModuleTests
{

private IApplicationClient creatioClient = NSubstitute.Substitute.For<IApplicationClient>();
private readonly IApplicationClient _creatioClient = Substitute.For<IApplicationClient>();

public override void Setup(){}

protected override void AdditionalRegistrations(ContainerBuilder containerBuilder) {
_environmentSettings.IsNetCore = true;
base.AdditionalRegistrations(containerBuilder);
containerBuilder.RegisterInstance(creatioClient).As<IApplicationClient>();
containerBuilder.RegisterInstance(_creatioClient).As<IApplicationClient>();
}

[Test]
public void PingAppCommandShoulBeUsesAllRetryOptions() {
[TestCase(true)]
[TestCase(false)]
public void PingAppCommandShouldBeUsesAllRetryOptions(bool isNetCore) {
//Arrange
_environmentSettings.IsNetCore = isNetCore;
_fileSystem = CreateFs();
BindingsModule bindingModule = new(_fileSystem);
_container = bindingModule.Register(_environmentSettings, true, AdditionalRegistrations);

PingAppCommand command = _container.Resolve<PingAppCommand>();
PingAppOptions options = new PingAppOptions() { TimeOut = 1, RetryCount = 2, RetryDelay = 3 };

// Act
command.Execute(options);

//Assert
creatioClient.Received(1).ExecutePostRequest(Arg.Any<string>(), Arg.Any<string>(), 1, 2, 3);
// Assert
if(isNetCore) {
_creatioClient.Received(1)
.ExecuteGetRequest(Arg.Any<string>(), 1, 2, 3);
}else {
_creatioClient.Received(1)
.ExecutePostRequest(Arg.Any<string>(), Arg.Any<string>(), 1, 2, 3);
}
_creatioClient.ClearReceivedCalls();
}

[Test]
public void PingAppCommandShoulBeUsesAllRetryOptionsOnNet6Environment() {
[TestCase(true)]
[TestCase(false)]
public void PingAppCommandShouldBeUsesAllRetryOptionsOnNet6Environment(bool isNetCore) {
//Arrange
_fileSystem = CreateFs();
BindingsModule bindingModule = new(_fileSystem);
_container = bindingModule.Register(_environmentSettings, true, AdditionalRegistrations);
PingAppCommand command = _container.Resolve<PingAppCommand>();
PingAppOptions options = new PingAppOptions() {
TimeOut = 1,
RetryCount = 2,
RetryDelay = 3,
IsNetCore = true
IsNetCore = isNetCore
};
command.EnvironmentSettings.IsNetCore = true;

// Act
command.Execute(options);

//Assert
creatioClient.Received(1).ExecuteGetRequest(Arg.Any<string>(), 1, 2, 3);
if(isNetCore) {

}else {
_creatioClient.Received(1).ExecuteGetRequest(Arg.Any<string>(), 1, 2, 3);
}
_creatioClient.ClearReceivedCalls();
}
}
}
17 changes: 13 additions & 4 deletions clio.tests/Command/RedisCommand.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Clio.Tests.Command
{
using System.Threading;
using Clio.Command;
using Clio.Command;
using Clio.Common;
using NSubstitute;
using NUnit.Framework;
Expand All @@ -11,6 +10,7 @@ public class RedisCommandTestCase
{
[Test, Category("Unit")]
public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetFramework() {
//Arrange
IApplicationClient applicationClient = Substitute.For<IApplicationClient>();
var testUri = "TestUri";
var settings = new EnvironmentSettings {
Expand All @@ -19,14 +19,19 @@ public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnder
};
RedisCommand redisCommand = new RedisCommand(applicationClient, settings);
var clearRedisOptions = Substitute.For<ClearRedisOptions>();

//Act
redisCommand.Execute(clearRedisOptions);

//Assert
applicationClient.Received(1).ExecutePostRequest(
testUri + "/0/ServiceModel/AppInstallerService.svc/ClearRedisDb",
"{}", Timeout.Infinite);
"{}", 100_000,3,1);
}

[Test, Category("Unit")]
public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetCore() {
//Arrange
IApplicationClient applicationClient = Substitute.For<IApplicationClient>();
var testUri = "TestUri";
var settings = new EnvironmentSettings {
Expand All @@ -35,10 +40,14 @@ public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnder
};
RedisCommand redisCommand = new RedisCommand(applicationClient, settings);
var clearRedisOptions = Substitute.For<ClearRedisOptions>();

//Act
redisCommand.Execute(clearRedisOptions);

//Assert
applicationClient.Received(1).ExecutePostRequest(
testUri + "/ServiceModel/AppInstallerService.svc/ClearRedisDb",
"{}", Timeout.Infinite);
"{}", 100_000,3,1);
}
}
}
17 changes: 13 additions & 4 deletions clio.tests/Command/RestartCommand.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Clio.Tests.Command
{
using System.Threading;
using Clio.Command;
using Clio.Command;
using Clio.Common;
using NSubstitute;
using NUnit.Framework;
Expand All @@ -11,6 +10,7 @@ public class RestartCommandTestCase
{
[Test, Category("Unit")]
public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetFrameworkAndSettingsPickedFromEnvironment() {
//Arrange
IApplicationClient applicationClient = Substitute.For<IApplicationClient>();
var environmentSettings = new EnvironmentSettings {
Login = "Test",
Expand All @@ -21,14 +21,19 @@ public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnd
};
RestartCommand restartCommand = new RestartCommand(applicationClient, environmentSettings);
var options = Substitute.For<RestartOptions>();

//Act
restartCommand.Execute(options);

//Assert
applicationClient.Received(1).ExecutePostRequest(
environmentSettings.Uri + "/0/ServiceModel/AppInstallerService.svc/UnloadAppDomain",
"{}", Timeout.Infinite);
"{}", 100_000,3,1);
}

[Test, Category("Unit")]
public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetCoreAndSettingsPickedFromEnvironment() {
//Arrange
IApplicationClient applicationClient = Substitute.For<IApplicationClient>();
var environmentSettings = new EnvironmentSettings {
Login = "Test",
Expand All @@ -39,10 +44,14 @@ public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnd
};
RestartCommand restartCommand = new RestartCommand(applicationClient, environmentSettings);
var options = Substitute.For<RestartOptions>();

//Act
restartCommand.Execute(options);

//Assert
applicationClient.Received(1).ExecutePostRequest(
environmentSettings.Uri + "/ServiceModel/AppInstallerService.svc/RestartApp",
"{}", Timeout.Infinite);
"{}", 100_000,3,1);
}
}
}
36 changes: 6 additions & 30 deletions clio/Command/RemoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,9 @@ namespace Clio.Command;

public class RemoteCommandOptions : EnvironmentNameOptions
{
public int TimeOut
{
get;
internal set;
}
public int RetryCount
{
get;
internal set;
}
public int RetryDelay
{
get;
internal set;
}
public int TimeOut { get; internal set; } = 100_000;
public int RetryCount { get; internal set; } = 3;
public int RetryDelay { get; internal set; } = 1;

}

Expand Down Expand Up @@ -72,21 +60,9 @@ protected RemoteCommand(EnvironmentSettings environmentSettings){

public virtual HttpMethod HttpMethod => HttpMethod.Post;

public int RequestTimeout
{
get;
set;
}
public int RetryCount
{
get;
set;
}
public int DelaySec
{
get;
set;
}
public int RequestTimeout { get; set; }
public int RetryCount { get; set; }
public int DelaySec { get; set; }

public ILogger Logger { get; set; } = ConsoleLogger.Instance;

Expand Down
2 changes: 1 addition & 1 deletion clio/Common/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void PrintInternal(){
}

private void PrintTableInternal(object table){
WriteLine(table.ToString());
WriteLineInternal(table.ToString());
}

private void WriteErrorInternal(string value){
Expand Down
Loading