Skip to content

Commit 870a913

Browse files
authored
Merge pull request #308 from TraGicCode/chore/refactor-integration-tests-on-cli-validations
Refactor CLI validations
2 parents 5e9600a + 49dc030 commit 870a913

3 files changed

Lines changed: 85 additions & 38 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using BuslyCLI.Commands.NsbCommand;
2+
3+
namespace BuslyCLI.Console.Tests.Commands;
4+
5+
[TestFixture]
6+
public class CommonCommandSettingsTests
7+
{
8+
[Test]
9+
public void ShouldFailWhenDestinationEndpointIsMissing()
10+
{
11+
var settings = new SendCommandSettings
12+
{
13+
ContentType = "application/json",
14+
EnclosedMessageType = "MessageContracts.Commands.CreateOrder",
15+
MessageBody = "{}",
16+
DestinationEndpoint = null!
17+
};
18+
19+
var result = settings.Validate();
20+
21+
Assert.That(result.Successful, Is.False);
22+
Assert.That(result.Message, Does.Contain("must specify a 'destination-endpoint'."));
23+
}
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using BuslyCLI.Commands.NsbEvent;
2+
3+
namespace BuslyCLI.Console.Tests.Commands;
4+
5+
[TestFixture]
6+
public class CommonMessageSettingsTests
7+
{
8+
[Test]
9+
public void ShouldFailWhenContentTypeIsMissing()
10+
{
11+
var settings = new PublishCommandSettings
12+
{
13+
ContentType = null!,
14+
EnclosedMessageType = "MessageContracts.Commands.CreateOrder",
15+
MessageBody = "{}"
16+
};
17+
18+
var result = settings.Validate();
19+
20+
Assert.That(result.Successful, Is.False);
21+
Assert.That(result.Message, Does.Contain("must specify a 'content-type'."));
22+
}
23+
24+
[Test]
25+
public void ShouldFailWhenEnclosedMessageTypeIsMissing()
26+
{
27+
var settings = new PublishCommandSettings
28+
{
29+
ContentType = "application/json",
30+
EnclosedMessageType = null!,
31+
MessageBody = "{}"
32+
};
33+
34+
var result = settings.Validate();
35+
36+
Assert.That(result.Successful, Is.False);
37+
Assert.That(result.Message, Does.Contain("must specify an 'enclosed-message-type'."));
38+
}
39+
40+
[Test]
41+
public void ShouldFailWhenMessageBodyIsMissing()
42+
{
43+
var settings = new PublishCommandSettings
44+
{
45+
ContentType = "application/json",
46+
EnclosedMessageType = "MessageContracts.Commands.CreateOrder",
47+
MessageBody = null!
48+
};
49+
50+
var result = settings.Validate();
51+
52+
Assert.That(result.Successful, Is.False);
53+
Assert.That(result.Message, Does.Contain("must specify a 'message-body'."));
54+
}
55+
}
Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
1-
// using Microsoft.Extensions.DependencyInjection;
2-
// using BuslyCLI.DependencyInjection;
3-
// using BuslyCLI.Spectre;
4-
// using Spectre.Console.Cli.Extensions.DependencyInjection;
5-
// using Spectre.Console.Testing;
6-
//
7-
// namespace BuslyCLI.Console.Tests.Commands.NsbCommand;
8-
//
9-
// public class SendCommandTests
10-
// {
11-
// private CommandAppTester _sut;
12-
//
13-
// [SetUp]
14-
// public void Setup()
15-
// {
16-
// var registrations = new ServiceCollection();
17-
// registrations.AddBuslyCLIServices();
18-
// using var registrar = new DependencyInjectionRegistrar(registrations);
19-
// _sut = new CommandAppTester(registrar);
20-
// _sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
21-
// }
22-
//
23-
// [TestCase("Error: must specify a 'content-type'.", "command", "send")]
24-
// [TestCase("Error: Option 'content-type' is defined but no value has been provided.", "command", "send", "--content-type")]
25-
// [TestCase("Error: must specify an 'enclosed-message-type'.", "command", "send", "--content-type", "application/json")]
26-
// [TestCase("Error: Option 'enclosed-message-type' is defined but no value has been provided.", "command", "send", "--content-type", "application/json", "--enclosed-message-type")]
27-
// [TestCase("Error: must specify a 'message-body'.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder")]
28-
// [TestCase("Error: Option 'message-body' is defined but no value has been provided.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder", "--message-body")]
29-
// [TestCase("Error: must specify a 'destination-endpoint'.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder", "--message-body", "test")]
30-
// [TestCase("Error: Option 'destination-endpoint' is defined but no value has been provided.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder", "--message-body", "test", "--destination-endpoint")]
31-
// public async Task ShouldValidateRequiredOptions(string expectedSubstring, params string[] args)
32-
// {
33-
// var result = _sut.Run(args);
34-
//
35-
// Assert.That(result.ExitCode, Is.Not.EqualTo(0));
36-
// Assert.That(result.Output, Does.Contain(expectedSubstring), $"Expected output to contain: {expectedSubstring}");
37-
// }
38-
// }
1+
namespace BuslyCLI.Console.Tests.Commands.NsbCommand;
2+
3+
// Validation of required options is covered in CommonMessageSettingsTests and CommonCommandSettingsTests.
4+
public class SendCommandTests : CommandTestBase
5+
{
6+
}

0 commit comments

Comments
 (0)