diff --git a/tests/BuslyCLI.Console.Tests/Commands/CommonCommandSettingsTests.cs b/tests/BuslyCLI.Console.Tests/Commands/CommonCommandSettingsTests.cs new file mode 100644 index 0000000..d5d4c50 --- /dev/null +++ b/tests/BuslyCLI.Console.Tests/Commands/CommonCommandSettingsTests.cs @@ -0,0 +1,24 @@ +using BuslyCLI.Commands.NsbCommand; + +namespace BuslyCLI.Console.Tests.Commands; + +[TestFixture] +public class CommonCommandSettingsTests +{ + [Test] + public void ShouldFailWhenDestinationEndpointIsMissing() + { + var settings = new SendCommandSettings + { + ContentType = "application/json", + EnclosedMessageType = "MessageContracts.Commands.CreateOrder", + MessageBody = "{}", + DestinationEndpoint = null! + }; + + var result = settings.Validate(); + + Assert.That(result.Successful, Is.False); + Assert.That(result.Message, Does.Contain("must specify a 'destination-endpoint'.")); + } +} \ No newline at end of file diff --git a/tests/BuslyCLI.Console.Tests/Commands/CommonMessageSettingsTests.cs b/tests/BuslyCLI.Console.Tests/Commands/CommonMessageSettingsTests.cs new file mode 100644 index 0000000..c64cdb8 --- /dev/null +++ b/tests/BuslyCLI.Console.Tests/Commands/CommonMessageSettingsTests.cs @@ -0,0 +1,55 @@ +using BuslyCLI.Commands.NsbEvent; + +namespace BuslyCLI.Console.Tests.Commands; + +[TestFixture] +public class CommonMessageSettingsTests +{ + [Test] + public void ShouldFailWhenContentTypeIsMissing() + { + var settings = new PublishCommandSettings + { + ContentType = null!, + EnclosedMessageType = "MessageContracts.Commands.CreateOrder", + MessageBody = "{}" + }; + + var result = settings.Validate(); + + Assert.That(result.Successful, Is.False); + Assert.That(result.Message, Does.Contain("must specify a 'content-type'.")); + } + + [Test] + public void ShouldFailWhenEnclosedMessageTypeIsMissing() + { + var settings = new PublishCommandSettings + { + ContentType = "application/json", + EnclosedMessageType = null!, + MessageBody = "{}" + }; + + var result = settings.Validate(); + + Assert.That(result.Successful, Is.False); + Assert.That(result.Message, Does.Contain("must specify an 'enclosed-message-type'.")); + } + + [Test] + public void ShouldFailWhenMessageBodyIsMissing() + { + var settings = new PublishCommandSettings + { + ContentType = "application/json", + EnclosedMessageType = "MessageContracts.Commands.CreateOrder", + MessageBody = null! + }; + + var result = settings.Validate(); + + Assert.That(result.Successful, Is.False); + Assert.That(result.Message, Does.Contain("must specify a 'message-body'.")); + } +} \ No newline at end of file diff --git a/tests/BuslyCLI.Console.Tests/Commands/NsbCommand/SendCommandTests.cs b/tests/BuslyCLI.Console.Tests/Commands/NsbCommand/SendCommandTests.cs index 4aca4e2..4d8d57a 100644 --- a/tests/BuslyCLI.Console.Tests/Commands/NsbCommand/SendCommandTests.cs +++ b/tests/BuslyCLI.Console.Tests/Commands/NsbCommand/SendCommandTests.cs @@ -1,38 +1,6 @@ -// using Microsoft.Extensions.DependencyInjection; -// using BuslyCLI.DependencyInjection; -// using BuslyCLI.Spectre; -// using Spectre.Console.Cli.Extensions.DependencyInjection; -// using Spectre.Console.Testing; -// -// namespace BuslyCLI.Console.Tests.Commands.NsbCommand; -// -// public class SendCommandTests -// { -// private CommandAppTester _sut; -// -// [SetUp] -// public void Setup() -// { -// var registrations = new ServiceCollection(); -// registrations.AddBuslyCLIServices(); -// using var registrar = new DependencyInjectionRegistrar(registrations); -// _sut = new CommandAppTester(registrar); -// _sut.Configure(AppConfiguration.GetSpectreCommandConfiguration()); -// } -// -// [TestCase("Error: must specify a 'content-type'.", "command", "send")] -// [TestCase("Error: Option 'content-type' is defined but no value has been provided.", "command", "send", "--content-type")] -// [TestCase("Error: must specify an 'enclosed-message-type'.", "command", "send", "--content-type", "application/json")] -// [TestCase("Error: Option 'enclosed-message-type' is defined but no value has been provided.", "command", "send", "--content-type", "application/json", "--enclosed-message-type")] -// [TestCase("Error: must specify a 'message-body'.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder")] -// [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")] -// [TestCase("Error: must specify a 'destination-endpoint'.", "command", "send", "--content-type", "application/json", "--enclosed-message-type", "MessageContracts.Commands.CreateOrder", "--message-body", "test")] -// [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")] -// public async Task ShouldValidateRequiredOptions(string expectedSubstring, params string[] args) -// { -// var result = _sut.Run(args); -// -// Assert.That(result.ExitCode, Is.Not.EqualTo(0)); -// Assert.That(result.Output, Does.Contain(expectedSubstring), $"Expected output to contain: {expectedSubstring}"); -// } -// } \ No newline at end of file +namespace BuslyCLI.Console.Tests.Commands.NsbCommand; + +// Validation of required options is covered in CommonMessageSettingsTests and CommonCommandSettingsTests. +public class SendCommandTests : CommandTestBase +{ +} \ No newline at end of file