From 701aac323025e0b4e24d7c72ac7b15b3639a6653 Mon Sep 17 00:00:00 2001
From: Michael Fyffe <6224270+TraGicCode@users.noreply.github.com>
Date: Wed, 3 Dec 2025 16:52:51 -0600
Subject: [PATCH 1/3] Add fluentvalidation to be able to handle issues in busly
config file
---
src/BuslyCLI.Console/BuslyCLI.Console.csproj | 2 +
.../Config/INServiceBusConfiguration.cs | 7 +-
.../LearningTransportConfigValidator.cs | 12 +++
.../Config/Validators/RootConfigValidator.cs | 22 +++++
.../Validators/TransportConfigValidator.cs | 19 ++++
.../ServiceCollectionExtensions.cs | 3 +
.../BuslyCLI.Console.Tests.csproj | 9 ++
.../LearningTransportConfigValidatorTests.cs | 48 ++++++++++
.../Validators/RootConfigValidatorTests.cs | 91 +++++++++++++++++++
.../TransportConfigValidatorTests.cs | 48 ++++++++++
10 files changed, 259 insertions(+), 2 deletions(-)
create mode 100644 src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
create mode 100644 src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
create mode 100644 src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
create mode 100644 tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
create mode 100644 tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
create mode 100644 tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
diff --git a/src/BuslyCLI.Console/BuslyCLI.Console.csproj b/src/BuslyCLI.Console/BuslyCLI.Console.csproj
index b450974..c8652db 100644
--- a/src/BuslyCLI.Console/BuslyCLI.Console.csproj
+++ b/src/BuslyCLI.Console/BuslyCLI.Console.csproj
@@ -25,6 +25,8 @@
+
+
diff --git a/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs b/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
index 63c0e2a..b61e99e 100644
--- a/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
+++ b/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
@@ -1,4 +1,5 @@
-using YamlDotNet.Serialization;
+using FluentValidation;
+using YamlDotNet.Serialization;
namespace BuslyCLI.Config;
@@ -9,7 +10,7 @@ public interface INServiceBusConfiguration
Task PersistConfiguration(string path, NServiceBusConfig config);
}
-public class NServiceBusConfiguration(IDeserializer yamlDeserializer, ISerializer yamlSerializer) : INServiceBusConfiguration
+public class NServiceBusConfiguration(IDeserializer yamlDeserializer, ISerializer yamlSerializer, IValidator validator) : INServiceBusConfiguration
{
public async Task GetConfigurationAsync(string path)
@@ -17,6 +18,8 @@ public async Task GetConfigurationAsync(string path)
if (File.Exists(path))
{
var yaml = await File.ReadAllTextAsync(path);
+ var config = yamlDeserializer.Deserialize(yaml);
+ await validator.ValidateAsync(config, opts => opts.ThrowOnFailures());
return yamlDeserializer.Deserialize(yaml);
}
diff --git a/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
new file mode 100644
index 0000000..87580c0
--- /dev/null
+++ b/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
@@ -0,0 +1,12 @@
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class LearningTransportConfigValidator : AbstractValidator
+{
+ public LearningTransportConfigValidator()
+ {
+ RuleFor(x => x.StorageDirectory)
+ .NotEmpty();
+ }
+}
\ No newline at end of file
diff --git a/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
new file mode 100644
index 0000000..917bd14
--- /dev/null
+++ b/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
@@ -0,0 +1,22 @@
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class RootConfigValidator : AbstractValidator
+{
+ public RootConfigValidator()
+ {
+ RuleFor(x => x.CurrentTransport).NotEmpty();
+
+ RuleFor(x => x.Transports)
+ .NotEmpty()
+ .ForEach(x => x.SetValidator(new TransportConfigValidator()));
+
+ RuleFor(x => x.CurrentTransport)
+ .Must((model, currentTransport) =>
+ model.Transports.Any(t => t.Name == currentTransport))
+ .WithMessage("current-transport must match one of the defined transports.")
+ .When(x => x.Transports != null);
+
+ }
+}
\ No newline at end of file
diff --git a/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
new file mode 100644
index 0000000..2d5d508
--- /dev/null
+++ b/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
@@ -0,0 +1,19 @@
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class TransportConfigValidator : AbstractValidator
+{
+ public TransportConfigValidator()
+ {
+ RuleFor(x => x.Name).NotEmpty();
+
+ RuleFor(x => x.Config)
+ .NotEmpty()
+ .WithMessage("Transport must define exactly one transport configuration.");
+
+ RuleFor(x => x.LearningTransportConfig)
+ .SetValidator(new LearningTransportConfigValidator())
+ .When(x => x.Config is not null);
+ }
+}
\ No newline at end of file
diff --git a/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs b/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
index fb4d4a8..82d3864 100644
--- a/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
+++ b/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
@@ -1,5 +1,7 @@
using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
using BuslyCLI.Factories;
+using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
@@ -11,6 +13,7 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddBuslyCLIServices(this IServiceCollection services)
{
services.AddScoped();
+ services.AddValidatorsFromAssemblyContaining();
return services;
}
diff --git a/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj b/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
index 92ca217..ba67bbf 100644
--- a/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
+++ b/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
@@ -8,12 +8,16 @@
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
@@ -46,4 +50,9 @@
+
+
+
+
+
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
new file mode 100644
index 0000000..6fcb468
--- /dev/null
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
@@ -0,0 +1,48 @@
+using Bogus;
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class LearningTransportConfigValidatorTests
+{
+ private readonly LearningTransportConfigValidator _validator;
+
+ public LearningTransportConfigValidatorTests()
+ {
+ _validator = new LearningTransportConfigValidator();
+ }
+
+ [Test]
+ public async Task ShouldErrorWhenStorageDirectoryIsNotPassed()
+ {
+ // Arrange
+ var learningTransportConfig = new LearningTransportConfig
+ {
+ StorageDirectory = null
+ };
+ // Act
+ var result = await _validator.TestValidateAsync(learningTransportConfig);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.StorageDirectory)
+ .WithErrorMessage("'Storage Directory' must not be empty.");
+ }
+
+ [Test]
+ public async Task ShouldNotErrorStorageDirectoryIsPassed()
+ {
+ // Arrange
+ var learningTransportConfig = new LearningTransportConfig
+ {
+ StorageDirectory = new Faker().System.DirectoryPath()
+ };
+ // Act
+ var result = await _validator.TestValidateAsync(learningTransportConfig);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(c => c.StorageDirectory);
+ }
+}
\ No newline at end of file
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
new file mode 100644
index 0000000..60f2a89
--- /dev/null
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
@@ -0,0 +1,91 @@
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class RootConfigValidatorTests
+{
+ private readonly RootConfigValidator _validator;
+
+ public RootConfigValidatorTests()
+ {
+ _validator = new RootConfigValidator();
+ }
+
+ [Test]
+ public void ShouldNotErrorWhenCurrentTransportIsDefined()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "local-learning",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(x => x.CurrentTransport);
+ }
+
+
+ [Test]
+ public void ShouldErrorWhenCurrentTransportIsNotDefined()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
+ .WithErrorMessage("'Current Transport' must not be empty.");
+ }
+
+ [Test]
+ public void ShouldErrorWhenCurrentTransportDoesntMatchAnyConfiguredTransports()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "d",
+ Transports = new List()
+ {
+ new TransportConfig { Name = "a" },
+ new TransportConfig { Name = "b" }
+ }
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
+ .WithErrorMessage("current-transport must match one of the defined transports.");
+ }
+
+
+ [Test]
+ public void ShouldErrorWhenTransportsArrayIsEmpty()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "d",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.Transports)
+ .WithErrorMessage("'Transports' must not be empty.");
+ }
+
+}
\ No newline at end of file
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
new file mode 100644
index 0000000..8fbc095
--- /dev/null
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
@@ -0,0 +1,48 @@
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class TransportConfigValidatorTests
+{
+ private readonly TransportConfigValidator _validator;
+
+ public TransportConfigValidatorTests()
+ {
+ _validator = new TransportConfigValidator();
+ }
+
+ [Test]
+ public async Task ShouldNotErrorWhenCurrentNameIsDefined()
+ {
+ var config = new TransportConfig()
+ {
+ Name = "local-learning"
+ };
+
+ // Act
+ var result = await _validator.TestValidateAsync(config);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(x => x.Name);
+ }
+
+ [Test]
+ public async Task ShouldErrorWhenCurrentTransportIsNotDefined()
+ {
+ // Arrange
+ var config = new TransportConfig()
+ {
+ Name = null
+ };
+
+ // Act
+ var result = await _validator.TestValidateAsync(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.Name)
+ .WithErrorMessage("'Name' must not be empty.");
+ }
+}
\ No newline at end of file
From b2c4c175c23c9330b438b27952a88e24b00da3b0 Mon Sep 17 00:00:00 2001
From: Michael Fyffe <6224270+TraGicCode@users.noreply.github.com>
Date: Wed, 3 Dec 2025 16:55:26 -0600
Subject: [PATCH 2/3] Fix formatting issues
---
.../LearningTransportConfigValidator.cs | 22 +--
.../Config/Validators/RootConfigValidator.cs | 42 ++--
.../Validators/TransportConfigValidator.cs | 36 ++--
.../LearningTransportConfigValidatorTests.cs | 94 ++++-----
.../Validators/RootConfigValidatorTests.cs | 180 +++++++++---------
.../TransportConfigValidatorTests.cs | 94 ++++-----
6 files changed, 234 insertions(+), 234 deletions(-)
diff --git a/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
index 87580c0..15fc54f 100644
--- a/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
+++ b/src/BuslyCLI.Console/Config/Validators/LearningTransportConfigValidator.cs
@@ -1,12 +1,12 @@
-using FluentValidation;
-
-namespace BuslyCLI.Config.Validators;
-
-public class LearningTransportConfigValidator : AbstractValidator
-{
- public LearningTransportConfigValidator()
- {
- RuleFor(x => x.StorageDirectory)
- .NotEmpty();
- }
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class LearningTransportConfigValidator : AbstractValidator
+{
+ public LearningTransportConfigValidator()
+ {
+ RuleFor(x => x.StorageDirectory)
+ .NotEmpty();
+ }
}
\ No newline at end of file
diff --git a/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
index 917bd14..4181351 100644
--- a/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
+++ b/src/BuslyCLI.Console/Config/Validators/RootConfigValidator.cs
@@ -1,22 +1,22 @@
-using FluentValidation;
-
-namespace BuslyCLI.Config.Validators;
-
-public class RootConfigValidator : AbstractValidator
-{
- public RootConfigValidator()
- {
- RuleFor(x => x.CurrentTransport).NotEmpty();
-
- RuleFor(x => x.Transports)
- .NotEmpty()
- .ForEach(x => x.SetValidator(new TransportConfigValidator()));
-
- RuleFor(x => x.CurrentTransport)
- .Must((model, currentTransport) =>
- model.Transports.Any(t => t.Name == currentTransport))
- .WithMessage("current-transport must match one of the defined transports.")
- .When(x => x.Transports != null);
-
- }
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class RootConfigValidator : AbstractValidator
+{
+ public RootConfigValidator()
+ {
+ RuleFor(x => x.CurrentTransport).NotEmpty();
+
+ RuleFor(x => x.Transports)
+ .NotEmpty()
+ .ForEach(x => x.SetValidator(new TransportConfigValidator()));
+
+ RuleFor(x => x.CurrentTransport)
+ .Must((model, currentTransport) =>
+ model.Transports.Any(t => t.Name == currentTransport))
+ .WithMessage("current-transport must match one of the defined transports.")
+ .When(x => x.Transports != null);
+
+ }
}
\ No newline at end of file
diff --git a/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs b/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
index 2d5d508..3baddcd 100644
--- a/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
+++ b/src/BuslyCLI.Console/Config/Validators/TransportConfigValidator.cs
@@ -1,19 +1,19 @@
-using FluentValidation;
-
-namespace BuslyCLI.Config.Validators;
-
-public class TransportConfigValidator : AbstractValidator
-{
- public TransportConfigValidator()
- {
- RuleFor(x => x.Name).NotEmpty();
-
- RuleFor(x => x.Config)
- .NotEmpty()
- .WithMessage("Transport must define exactly one transport configuration.");
-
- RuleFor(x => x.LearningTransportConfig)
- .SetValidator(new LearningTransportConfigValidator())
- .When(x => x.Config is not null);
- }
+using FluentValidation;
+
+namespace BuslyCLI.Config.Validators;
+
+public class TransportConfigValidator : AbstractValidator
+{
+ public TransportConfigValidator()
+ {
+ RuleFor(x => x.Name).NotEmpty();
+
+ RuleFor(x => x.Config)
+ .NotEmpty()
+ .WithMessage("Transport must define exactly one transport configuration.");
+
+ RuleFor(x => x.LearningTransportConfig)
+ .SetValidator(new LearningTransportConfigValidator())
+ .When(x => x.Config is not null);
+ }
}
\ No newline at end of file
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
index 6fcb468..d76e75e 100644
--- a/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/LearningTransportConfigValidatorTests.cs
@@ -1,48 +1,48 @@
-using Bogus;
-using BuslyCLI.Config;
-using BuslyCLI.Config.Validators;
-using FluentValidation.TestHelper;
-
-namespace BuslyCLI.Console.Tests.Config.Validators;
-
-[TestFixture]
-public class LearningTransportConfigValidatorTests
-{
- private readonly LearningTransportConfigValidator _validator;
-
- public LearningTransportConfigValidatorTests()
- {
- _validator = new LearningTransportConfigValidator();
- }
-
- [Test]
- public async Task ShouldErrorWhenStorageDirectoryIsNotPassed()
- {
- // Arrange
- var learningTransportConfig = new LearningTransportConfig
- {
- StorageDirectory = null
- };
- // Act
- var result = await _validator.TestValidateAsync(learningTransportConfig);
-
- // Assert
- result.ShouldHaveValidationErrorFor(c => c.StorageDirectory)
- .WithErrorMessage("'Storage Directory' must not be empty.");
- }
-
- [Test]
- public async Task ShouldNotErrorStorageDirectoryIsPassed()
- {
- // Arrange
- var learningTransportConfig = new LearningTransportConfig
- {
- StorageDirectory = new Faker().System.DirectoryPath()
- };
- // Act
- var result = await _validator.TestValidateAsync(learningTransportConfig);
-
- // Assert
- result.ShouldNotHaveValidationErrorFor(c => c.StorageDirectory);
- }
+using Bogus;
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class LearningTransportConfigValidatorTests
+{
+ private readonly LearningTransportConfigValidator _validator;
+
+ public LearningTransportConfigValidatorTests()
+ {
+ _validator = new LearningTransportConfigValidator();
+ }
+
+ [Test]
+ public async Task ShouldErrorWhenStorageDirectoryIsNotPassed()
+ {
+ // Arrange
+ var learningTransportConfig = new LearningTransportConfig
+ {
+ StorageDirectory = null
+ };
+ // Act
+ var result = await _validator.TestValidateAsync(learningTransportConfig);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.StorageDirectory)
+ .WithErrorMessage("'Storage Directory' must not be empty.");
+ }
+
+ [Test]
+ public async Task ShouldNotErrorStorageDirectoryIsPassed()
+ {
+ // Arrange
+ var learningTransportConfig = new LearningTransportConfig
+ {
+ StorageDirectory = new Faker().System.DirectoryPath()
+ };
+ // Act
+ var result = await _validator.TestValidateAsync(learningTransportConfig);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(c => c.StorageDirectory);
+ }
}
\ No newline at end of file
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
index 60f2a89..2ac8c0e 100644
--- a/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/RootConfigValidatorTests.cs
@@ -1,91 +1,91 @@
-using BuslyCLI.Config;
-using BuslyCLI.Config.Validators;
-using FluentValidation.TestHelper;
-
-namespace BuslyCLI.Console.Tests.Config.Validators;
-
-[TestFixture]
-public class RootConfigValidatorTests
-{
- private readonly RootConfigValidator _validator;
-
- public RootConfigValidatorTests()
- {
- _validator = new RootConfigValidator();
- }
-
- [Test]
- public void ShouldNotErrorWhenCurrentTransportIsDefined()
- {
- // Arrange
- var config = new NServiceBusConfig
- {
- CurrentTransport = "local-learning",
- };
-
- // Act
- var result = _validator.TestValidate(config);
-
- // Assert
- result.ShouldNotHaveValidationErrorFor(x => x.CurrentTransport);
- }
-
-
- [Test]
- public void ShouldErrorWhenCurrentTransportIsNotDefined()
- {
- // Arrange
- var config = new NServiceBusConfig
- {
- CurrentTransport = "",
- };
-
- // Act
- var result = _validator.TestValidate(config);
-
- // Assert
- result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
- .WithErrorMessage("'Current Transport' must not be empty.");
- }
-
- [Test]
- public void ShouldErrorWhenCurrentTransportDoesntMatchAnyConfiguredTransports()
- {
- // Arrange
- var config = new NServiceBusConfig
- {
- CurrentTransport = "d",
- Transports = new List()
- {
- new TransportConfig { Name = "a" },
- new TransportConfig { Name = "b" }
- }
- };
-
- // Act
- var result = _validator.TestValidate(config);
-
- // Assert
- result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
- .WithErrorMessage("current-transport must match one of the defined transports.");
- }
-
-
- [Test]
- public void ShouldErrorWhenTransportsArrayIsEmpty()
- {
- // Arrange
- var config = new NServiceBusConfig
- {
- CurrentTransport = "d",
- };
-
- // Act
- var result = _validator.TestValidate(config);
-
- // Assert
- result.ShouldHaveValidationErrorFor(c => c.Transports)
- .WithErrorMessage("'Transports' must not be empty.");
- }
-
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class RootConfigValidatorTests
+{
+ private readonly RootConfigValidator _validator;
+
+ public RootConfigValidatorTests()
+ {
+ _validator = new RootConfigValidator();
+ }
+
+ [Test]
+ public void ShouldNotErrorWhenCurrentTransportIsDefined()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "local-learning",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(x => x.CurrentTransport);
+ }
+
+
+ [Test]
+ public void ShouldErrorWhenCurrentTransportIsNotDefined()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
+ .WithErrorMessage("'Current Transport' must not be empty.");
+ }
+
+ [Test]
+ public void ShouldErrorWhenCurrentTransportDoesntMatchAnyConfiguredTransports()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "d",
+ Transports = new List()
+ {
+ new TransportConfig { Name = "a" },
+ new TransportConfig { Name = "b" }
+ }
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.CurrentTransport)
+ .WithErrorMessage("current-transport must match one of the defined transports.");
+ }
+
+
+ [Test]
+ public void ShouldErrorWhenTransportsArrayIsEmpty()
+ {
+ // Arrange
+ var config = new NServiceBusConfig
+ {
+ CurrentTransport = "d",
+ };
+
+ // Act
+ var result = _validator.TestValidate(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.Transports)
+ .WithErrorMessage("'Transports' must not be empty.");
+ }
+
}
\ No newline at end of file
diff --git a/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs b/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
index 8fbc095..5255bf3 100644
--- a/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Config/Validators/TransportConfigValidatorTests.cs
@@ -1,48 +1,48 @@
-using BuslyCLI.Config;
-using BuslyCLI.Config.Validators;
-using FluentValidation.TestHelper;
-
-namespace BuslyCLI.Console.Tests.Config.Validators;
-
-[TestFixture]
-public class TransportConfigValidatorTests
-{
- private readonly TransportConfigValidator _validator;
-
- public TransportConfigValidatorTests()
- {
- _validator = new TransportConfigValidator();
- }
-
- [Test]
- public async Task ShouldNotErrorWhenCurrentNameIsDefined()
- {
- var config = new TransportConfig()
- {
- Name = "local-learning"
- };
-
- // Act
- var result = await _validator.TestValidateAsync(config);
-
- // Assert
- result.ShouldNotHaveValidationErrorFor(x => x.Name);
- }
-
- [Test]
- public async Task ShouldErrorWhenCurrentTransportIsNotDefined()
- {
- // Arrange
- var config = new TransportConfig()
- {
- Name = null
- };
-
- // Act
- var result = await _validator.TestValidateAsync(config);
-
- // Assert
- result.ShouldHaveValidationErrorFor(c => c.Name)
- .WithErrorMessage("'Name' must not be empty.");
- }
+using BuslyCLI.Config;
+using BuslyCLI.Config.Validators;
+using FluentValidation.TestHelper;
+
+namespace BuslyCLI.Console.Tests.Config.Validators;
+
+[TestFixture]
+public class TransportConfigValidatorTests
+{
+ private readonly TransportConfigValidator _validator;
+
+ public TransportConfigValidatorTests()
+ {
+ _validator = new TransportConfigValidator();
+ }
+
+ [Test]
+ public async Task ShouldNotErrorWhenCurrentNameIsDefined()
+ {
+ var config = new TransportConfig()
+ {
+ Name = "local-learning"
+ };
+
+ // Act
+ var result = await _validator.TestValidateAsync(config);
+
+ // Assert
+ result.ShouldNotHaveValidationErrorFor(x => x.Name);
+ }
+
+ [Test]
+ public async Task ShouldErrorWhenCurrentTransportIsNotDefined()
+ {
+ // Arrange
+ var config = new TransportConfig()
+ {
+ Name = null
+ };
+
+ // Act
+ var result = await _validator.TestValidateAsync(config);
+
+ // Assert
+ result.ShouldHaveValidationErrorFor(c => c.Name)
+ .WithErrorMessage("'Name' must not be empty.");
+ }
}
\ No newline at end of file
From 5b6f0d6ccdee2271a1dd8af61058b4159945216d Mon Sep 17 00:00:00 2001
From: Michael Fyffe <6224270+TraGicCode@users.noreply.github.com>
Date: Thu, 4 Dec 2025 04:31:37 -0600
Subject: [PATCH 3/3] More changes around fluent validation
---
.../Commands/Command/SendCommand.cs | 2 +-
.../Commands/Demo/StartCommand.cs | 2 +-
.../Commands/Event/PublishCommand.cs | 2 +-
.../Transport/CurrentTransportCommand.cs | 2 +-
.../Transport/DeleteTransportCommand.cs | 2 +-
.../Transport/ListTransportsCommand.cs | 4 +--
.../Commands/Transport/SetTransportCommand.cs | 2 +-
.../Config/INServiceBusConfiguration.cs | 32 +++++++++++++------
.../ServiceCollectionExtensions.cs | 7 ++--
src/BuslyCLI.Console/Program.cs | 4 ---
.../BuslyCLI.Console.Tests.csproj | 7 ----
.../Transport/CurrentTransportTests.cs | 6 +---
.../Transport/DeleteTransportTests.cs | 6 +---
.../Commands/Transport/ListTransportTests.cs | 26 +++++++++++----
.../Commands/Transport/SetTransportTests.cs | 14 ++++----
...dCommandAmazonSqsEndToEndAmazonSqsTests.cs | 5 ---
...SendCommandAzureServiceBusEndToEndTests.cs | 5 ---
.../SendCommandEndToEndLearningTests.cs | 5 ---
.../SendCommandRabbitMqEndToEndTests.cs | 5 ---
19 files changed, 64 insertions(+), 74 deletions(-)
diff --git a/src/BuslyCLI.Console/Commands/Command/SendCommand.cs b/src/BuslyCLI.Console/Commands/Command/SendCommand.cs
index 935a3a5..1094394 100644
--- a/src/BuslyCLI.Console/Commands/Command/SendCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Command/SendCommand.cs
@@ -11,7 +11,7 @@ public class SendCommand(IRawEndpointFactory rawEndpointFactory, INServiceBusCon
{
public override async Task ExecuteAsync(CommandContext context, SendCommandSettings settings, CancellationToken cancellationToken)
{
- var config = await nServiceBusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var config = await nServiceBusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var rawEndpoint = await rawEndpointFactory.CreateRawSendOnlyEndpoint(Constants.DefaultOriginatingEndpoint, config.CurrentTransportConfig);
// TODO: Validate body is valid json/xml
var headers = new Dictionary
diff --git a/src/BuslyCLI.Console/Commands/Demo/StartCommand.cs b/src/BuslyCLI.Console/Commands/Demo/StartCommand.cs
index 421380f..c8457f3 100644
--- a/src/BuslyCLI.Console/Commands/Demo/StartCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Demo/StartCommand.cs
@@ -13,7 +13,7 @@ public class StartDemoCommand(IAnsiConsole console, IRawEndpointFactory rawEndpo
public override async Task ExecuteAsync(CommandContext context, CurrentTransportSettings settings, CancellationToken cancellationToken)
{
console.WriteLine("Starting demo endpoint for quick start guide...");
- var config = await nServiceBusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var config = await nServiceBusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var rawEndpoint = await rawEndpointFactory.CreateRawEndpoint(Constants.DemoDefaultOriginatingEndpoint, config.CurrentTransportConfig);
await rawEndpoint.StartEndpoint();
diff --git a/src/BuslyCLI.Console/Commands/Event/PublishCommand.cs b/src/BuslyCLI.Console/Commands/Event/PublishCommand.cs
index 4f6a092..f0896d8 100644
--- a/src/BuslyCLI.Console/Commands/Event/PublishCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Event/PublishCommand.cs
@@ -13,7 +13,7 @@ public class PublishCommand(IRawEndpointFactory rawEndpointFactory, INServiceBus
{
public override async Task ExecuteAsync(CommandContext context, PublishCommandSettings settings, CancellationToken cancellationToken)
{
- var config = await nServiceBusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var config = await nServiceBusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var rawEndpoint = await rawEndpointFactory.CreateRawSendOnlyEndpoint(Constants.DefaultOriginatingEndpoint, config.CurrentTransportConfig);
// TODO: Validate body is valid json/xml
var headers = new Dictionary
diff --git a/src/BuslyCLI.Console/Commands/Transport/CurrentTransportCommand.cs b/src/BuslyCLI.Console/Commands/Transport/CurrentTransportCommand.cs
index 30fd817..32eabee 100644
--- a/src/BuslyCLI.Console/Commands/Transport/CurrentTransportCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Transport/CurrentTransportCommand.cs
@@ -9,7 +9,7 @@ public class CurrentTransportCommand(IAnsiConsole console, INServiceBusConfigura
{
public override async Task ExecuteAsync(CommandContext context, CurrentTransportSettings settings, CancellationToken cancellationToken)
{
- var nsbConfiguration = await nservicebusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var nsbConfiguration = await nservicebusConfiguration.GetUnValidatedConfigurationAsync(settings.Config.Path);
console.WriteLine(nsbConfiguration != null && nsbConfiguration.CurrentTransport is not null ? nsbConfiguration.CurrentTransport : "Current transport is not set.");
return 0;
diff --git a/src/BuslyCLI.Console/Commands/Transport/DeleteTransportCommand.cs b/src/BuslyCLI.Console/Commands/Transport/DeleteTransportCommand.cs
index fa20632..9fb70af 100644
--- a/src/BuslyCLI.Console/Commands/Transport/DeleteTransportCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Transport/DeleteTransportCommand.cs
@@ -9,7 +9,7 @@ public class DeleteTransportCommand(IAnsiConsole console, INServiceBusConfigurat
{
public override async Task ExecuteAsync(CommandContext context, DeleteTransportSettings settings, CancellationToken cancellationToken)
{
- var nsbConfiguration = await nservicebusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var nsbConfiguration = await nservicebusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var targetTransport = settings.TransportName.ToLower();
if (nsbConfiguration.Transports.Select(x => x.Name.ToLower()).Contains(targetTransport))
{
diff --git a/src/BuslyCLI.Console/Commands/Transport/ListTransportsCommand.cs b/src/BuslyCLI.Console/Commands/Transport/ListTransportsCommand.cs
index c903deb..96040f5 100644
--- a/src/BuslyCLI.Console/Commands/Transport/ListTransportsCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Transport/ListTransportsCommand.cs
@@ -32,9 +32,9 @@ public override async Task ExecuteAsync(CommandContext context, ListTranspo
// Add header row
grid.AddRow("CURRENT", "NAME", "TRANSPORT-TYPE");
- var nsbConfiguration = await nservicebusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var nsbConfiguration = await nservicebusConfiguration.GetUnValidatedConfigurationAsync(settings.Config.Path);
- if (nsbConfiguration != null)
+ if (nsbConfiguration is { Transports: not null })
{
foreach (var transport in nsbConfiguration.Transports)
{
diff --git a/src/BuslyCLI.Console/Commands/Transport/SetTransportCommand.cs b/src/BuslyCLI.Console/Commands/Transport/SetTransportCommand.cs
index 0160056..469eeab 100644
--- a/src/BuslyCLI.Console/Commands/Transport/SetTransportCommand.cs
+++ b/src/BuslyCLI.Console/Commands/Transport/SetTransportCommand.cs
@@ -9,7 +9,7 @@ public class SetTransportCommand(IAnsiConsole console, INServiceBusConfiguration
{
public override async Task ExecuteAsync(CommandContext context, SetTransportSettings settings, CancellationToken cancellationToken)
{
- var nsbConfiguration = await nservicebusConfiguration.GetConfigurationAsync(settings.Config.Path);
+ var nsbConfiguration = await nservicebusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var targetTransport = settings.TransportName.ToLower();
if (nsbConfiguration.Transports.Select(x => x.Name.ToLower()).Contains(targetTransport))
{
diff --git a/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs b/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
index b61e99e..14060bd 100644
--- a/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
+++ b/src/BuslyCLI.Console/Config/INServiceBusConfiguration.cs
@@ -5,7 +5,9 @@ namespace BuslyCLI.Config;
public interface INServiceBusConfiguration
{
- Task GetConfigurationAsync(string path);
+ Task GetValidatedConfigurationAsync(string path);
+
+ Task GetUnValidatedConfigurationAsync(string path);
Task PersistConfiguration(string path, NServiceBusConfig config);
}
@@ -13,19 +15,31 @@ public interface INServiceBusConfiguration
public class NServiceBusConfiguration(IDeserializer yamlDeserializer, ISerializer yamlSerializer, IValidator validator) : INServiceBusConfiguration
{
- public async Task GetConfigurationAsync(string path)
+
+ private async Task LoadConfigurationAsync(
+ string path,
+ bool validate)
{
- if (File.Exists(path))
- {
- var yaml = await File.ReadAllTextAsync(path);
- var config = yamlDeserializer.Deserialize(yaml);
+ if (!File.Exists(path)) return null;
+
+ var yaml = await File.ReadAllTextAsync(path);
+ var config = yamlDeserializer.Deserialize(yaml);
+
+ // config is null if yaml file is empty
+ if (config is null) return null;
+
+ if (validate)
await validator.ValidateAsync(config, opts => opts.ThrowOnFailures());
- return yamlDeserializer.Deserialize(yaml);
- }
- return null;
+ return config;
}
+ public async Task GetValidatedConfigurationAsync(string path)
+ => await LoadConfigurationAsync(path, validate: true);
+
+ public async Task GetUnValidatedConfigurationAsync(string path)
+ => await LoadConfigurationAsync(path, validate: false);
+
public async Task PersistConfiguration(string path, NServiceBusConfig config)
{
var yaml = yamlSerializer.Serialize(config);
diff --git a/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs b/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
index 82d3864..e1ed09f 100644
--- a/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
+++ b/src/BuslyCLI.Console/DependencyInjection/ServiceCollectionExtensions.cs
@@ -13,12 +13,15 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddBuslyCLIServices(this IServiceCollection services)
{
services.AddScoped();
+ services.AddSingleton();
services.AddValidatorsFromAssemblyContaining();
+ services.AddYamlDeserializer();
+ services.AddYamlSerializer();
return services;
}
- public static IServiceCollection AddYamlDeserializer(this IServiceCollection services)
+ private static IServiceCollection AddYamlDeserializer(this IServiceCollection services)
{
services.AddSingleton(
new DeserializerBuilder()
@@ -39,7 +42,7 @@ public static IServiceCollection AddYamlDeserializer(this IServiceCollection ser
return services;
}
- public static IServiceCollection AddYamlSerializer(this IServiceCollection services)
+ private static IServiceCollection AddYamlSerializer(this IServiceCollection services)
{
services.AddSingleton(
new SerializerBuilder()
diff --git a/src/BuslyCLI.Console/Program.cs b/src/BuslyCLI.Console/Program.cs
index 9548c24..fef0a6b 100644
--- a/src/BuslyCLI.Console/Program.cs
+++ b/src/BuslyCLI.Console/Program.cs
@@ -1,5 +1,4 @@
using System.Diagnostics;
-using BuslyCLI.Config;
using BuslyCLI.DependencyInjection;
using BuslyCLI.Spectre;
using Microsoft.Extensions.DependencyInjection;
@@ -14,9 +13,6 @@
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
-registrations.AddYamlDeserializer();
-registrations.AddYamlSerializer();
-registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
var app = new CommandApp(registrar);
app.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj b/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
index ba67bbf..f9de6b7 100644
--- a/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
+++ b/tests/BuslyCLI.Console.Tests/BuslyCLI.Console.Tests.csproj
@@ -14,10 +14,8 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
@@ -50,9 +48,4 @@
-
-
-
-
-
diff --git a/tests/BuslyCLI.Console.Tests/Commands/Transport/CurrentTransportTests.cs b/tests/BuslyCLI.Console.Tests/Commands/Transport/CurrentTransportTests.cs
index ae70c81..43cf0a9 100644
--- a/tests/BuslyCLI.Console.Tests/Commands/Transport/CurrentTransportTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Commands/Transport/CurrentTransportTests.cs
@@ -1,5 +1,4 @@
-using BuslyCLI.Config;
-using BuslyCLI.Console.Tests.TestHelpers;
+using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
using BuslyCLI.Spectre;
using Microsoft.Extensions.DependencyInjection;
@@ -18,9 +17,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/Commands/Transport/DeleteTransportTests.cs b/tests/BuslyCLI.Console.Tests/Commands/Transport/DeleteTransportTests.cs
index 539578b..9fb4879 100644
--- a/tests/BuslyCLI.Console.Tests/Commands/Transport/DeleteTransportTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Commands/Transport/DeleteTransportTests.cs
@@ -1,5 +1,4 @@
-using BuslyCLI.Config;
-using BuslyCLI.Console.Tests.TestHelpers;
+using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
using BuslyCLI.Spectre;
using Microsoft.Extensions.DependencyInjection;
@@ -18,9 +17,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/Commands/Transport/ListTransportTests.cs b/tests/BuslyCLI.Console.Tests/Commands/Transport/ListTransportTests.cs
index 711ba0a..cb554b6 100644
--- a/tests/BuslyCLI.Console.Tests/Commands/Transport/ListTransportTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Commands/Transport/ListTransportTests.cs
@@ -1,5 +1,4 @@
-using BuslyCLI.Config;
-using BuslyCLI.Console.Tests.TestHelpers;
+using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
using BuslyCLI.Spectre;
using Microsoft.Extensions.DependencyInjection;
@@ -18,19 +17,18 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
}
[Test]
- public void ShouldOutputAnEmptyGrid()
+ public void ShouldOutputAnEmptyGridWhenConfigFileIsEmptyYaml()
{
// Arrange
- var yamlFile = "---";
+ var yamlFile = """
+ ---
+ """;
using var configFile = new TestableNServiceBusConfigurationFile(yamlFile);
var result = _sut.Run("transport", "list", "--config", configFile.FilePath);
@@ -38,6 +36,20 @@ public void ShouldOutputAnEmptyGrid()
Assert.That(result.Output, Is.EqualTo("CURRENT NAME TRANSPORT-TYPE"));
}
+ [Test]
+ public void ShouldOutputAnEmptyGridWhenTransportArrayIsEmpty()
+ {
+ // Arrange
+ var yamlFile = """
+ ---
+ transports:
+ """;
+ using var configFile = new TestableNServiceBusConfigurationFile(yamlFile);
+ var result = _sut.Run("transport", "list", "--config", configFile.FilePath);
+
+ Assert.That(result.ExitCode, Is.EqualTo(0));
+ Assert.That(result.Output, Is.EqualTo("CURRENT NAME TRANSPORT-TYPE"));
+ }
[Test]
public void ShouldOutputASingleTransport()
{
diff --git a/tests/BuslyCLI.Console.Tests/Commands/Transport/SetTransportTests.cs b/tests/BuslyCLI.Console.Tests/Commands/Transport/SetTransportTests.cs
index 93d1ffc..43c97a7 100644
--- a/tests/BuslyCLI.Console.Tests/Commands/Transport/SetTransportTests.cs
+++ b/tests/BuslyCLI.Console.Tests/Commands/Transport/SetTransportTests.cs
@@ -1,5 +1,4 @@
-using BuslyCLI.Config;
-using BuslyCLI.Console.Tests.TestHelpers;
+using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
using BuslyCLI.Spectre;
using Microsoft.Extensions.DependencyInjection;
@@ -18,9 +17,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
@@ -59,21 +55,25 @@ public void ShouldOutputAMessageWhenTransportIsSet()
// Arrange
var yamlFile = """
---
+ current-transport: local-learning
transports:
- name: local-learning
learning-transport-config:
storage-directory: .learningtransport
+ - name: local-learning2
+ learning-transport-config:
+ storage-directory: .learningtransport
""";
using var configFile = new TestableNServiceBusConfigurationFile(yamlFile);
// Act
- var result = _sut.Run("transport", "set", "local-learning", "--config", configFile.FilePath);
+ var result = _sut.Run("transport", "set", "local-learning2", "--config", configFile.FilePath);
// Assert
Assert.That(result.ExitCode, Is.EqualTo(0));
Assert.That(result.Output, Is.EqualTo(
$"""
- Switched to transport "local-learning".
+ Switched to transport "local-learning2".
""".NormalizeLineEndings()
));
}
diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs
index 71a2d7b..93215b3 100644
--- a/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs
+++ b/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
-using BuslyCLI.Config;
using BuslyCLI.Console.Tests.EndToEnd.Infrastructure;
using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
@@ -8,7 +7,6 @@
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli.Testing;
-using Spectre.Console.Testing;
namespace BuslyCLI.Console.Tests.EndToEnd.AmazonSQS;
@@ -20,9 +18,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs
index 8d24c09..2240655 100644
--- a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs
+++ b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
-using BuslyCLI.Config;
using BuslyCLI.Console.Tests.EndToEnd.Infrastructure;
using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
@@ -8,7 +7,6 @@
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli.Testing;
-using Spectre.Console.Testing;
namespace BuslyCLI.Console.Tests.EndToEnd.AzureServiceBus;
@@ -23,9 +21,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs
index 449c0c7..75bbc75 100644
--- a/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs
+++ b/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
-using BuslyCLI.Config;
using BuslyCLI.Console.Tests.EndToEnd.Infrastructure;
using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
@@ -8,7 +7,6 @@
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli.Testing;
-using Spectre.Console.Testing;
namespace BuslyCLI.Console.Tests.EndToEnd.Learning;
@@ -20,9 +18,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs
index c25bc4f..2b1e906 100644
--- a/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs
+++ b/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
-using BuslyCLI.Config;
using BuslyCLI.Console.Tests.EndToEnd.Infrastructure;
using BuslyCLI.Console.Tests.TestHelpers;
using BuslyCLI.DependencyInjection;
@@ -8,7 +7,6 @@
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli.Testing;
-using Spectre.Console.Testing;
namespace BuslyCLI.Console.Tests.EndToEnd.RabbitMQ;
@@ -20,9 +18,6 @@ public void Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
- registrations.AddYamlDeserializer();
- registrations.AddYamlSerializer();
- registrations.AddSingleton();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());