From 73d0f8756f2c569d6b73919a1d30b054a300685b Mon Sep 17 00:00:00 2001 From: Luciana Regina Lino Date: Mon, 17 Jun 2024 09:47:15 -0300 Subject: [PATCH] feat: Swap LiquidConfiguration for IOptions. --- .../Decorators/LiquidContextDecorator.cs | 9 +-- .../Decorators/LiquidCultureDecorator.cs | 9 +-- .../LiquidScopedLoggingDecorator.cs | 7 +- .../IServiceCollectionLiquidExtension.cs | 12 +--- .../Implementations/LiquidConfiguration.cs | 36 ---------- .../Interfaces/ILiquidConfiguration.cs | 14 ---- .../Localization/JsonFileLocalization.cs | 9 ++- .../IApplicationBuilderExtensions.cs | 5 +- .../IServiceCollectionExtensions.cs | 18 +++-- .../Middlewares/LiquidContextMiddleware.cs | 9 +-- .../Middlewares/LiquidCultureMiddleware.cs | 9 +-- .../LiquidScopedLoggingMiddleware.cs | 7 +- .../Core/LiquidConfigurationTest.cs | 69 ------------------- .../IServiceCollectionExtensionTest.cs | 6 +- .../Messaging/LiquidContextDecoratorTest.cs | 7 +- .../Messaging/LiquidCultureDecoratorTest.cs | 9 +-- .../LiquidScopedLoggingDecoratorTest.cs | 7 +- 17 files changed, 64 insertions(+), 178 deletions(-) delete mode 100644 src/Liquid.Core/Implementations/LiquidConfiguration.cs delete mode 100644 src/Liquid.Core/Interfaces/ILiquidConfiguration.cs delete mode 100644 test/Liquid.Core.Tests/Core/LiquidConfigurationTest.cs diff --git a/src/Liquid.Core/Decorators/LiquidContextDecorator.cs b/src/Liquid.Core/Decorators/LiquidContextDecorator.cs index 51b218ef..9525f6c7 100644 --- a/src/Liquid.Core/Decorators/LiquidContextDecorator.cs +++ b/src/Liquid.Core/Decorators/LiquidContextDecorator.cs @@ -2,6 +2,7 @@ using Liquid.Core.Exceptions; using Liquid.Core.Interfaces; using Liquid.Core.Settings; +using Microsoft.Extensions.Options; using System; using System.Globalization; using System.Threading; @@ -17,7 +18,7 @@ public class LiquidContextDecorator : ILiquidWorker { private readonly ILiquidWorker _inner; private readonly ILiquidContext _context; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; /// /// Initialize a new instance of @@ -25,7 +26,7 @@ public class LiquidContextDecorator : ILiquidWorker /// Decorated service. /// Scoped Context service. /// Scoped context keys set. - public LiquidContextDecorator(ILiquidWorker inner, ILiquidContext context, ILiquidConfiguration options) + public LiquidContextDecorator(ILiquidWorker inner, ILiquidContext context, IOptions options) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); _context = context ?? throw new ArgumentNullException(nameof(context)); @@ -37,7 +38,7 @@ public async Task ProcessMessageAsync(ConsumerMessageEventArgs args, Ca { object value = default; - foreach (var key in _options.Settings.Keys) + foreach (var key in _options.Value.Keys) { args.Headers?.TryGetValue(key.KeyName, out value); @@ -47,7 +48,7 @@ public async Task ProcessMessageAsync(ConsumerMessageEventArgs args, Ca _context.Upsert(key.KeyName, value); } - if (_options.Settings.Culture) + if (_options.Value.Culture) { _context.Upsert("culture", CultureInfo.CurrentCulture.Name); } diff --git a/src/Liquid.Core/Decorators/LiquidCultureDecorator.cs b/src/Liquid.Core/Decorators/LiquidCultureDecorator.cs index c4fd4aee..6394b9d0 100644 --- a/src/Liquid.Core/Decorators/LiquidCultureDecorator.cs +++ b/src/Liquid.Core/Decorators/LiquidCultureDecorator.cs @@ -1,6 +1,7 @@ using Liquid.Core.Entities; using Liquid.Core.Interfaces; using Liquid.Core.Settings; +using Microsoft.Extensions.Options; using System; using System.Globalization; using System.Threading; @@ -15,7 +16,7 @@ namespace Liquid.Core.Decorators public class LiquidCultureDecorator : ILiquidWorker { private const string _culture = "culture"; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; private readonly ILiquidWorker _inner; /// @@ -23,7 +24,7 @@ public class LiquidCultureDecorator : ILiquidWorker /// /// Decorated service. /// Default culture configuration. - public LiquidCultureDecorator(ILiquidWorker inner, ILiquidConfiguration options) + public LiquidCultureDecorator(ILiquidWorker inner, IOptions options) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); _options = options ?? throw new ArgumentNullException(nameof(options)); @@ -36,9 +37,9 @@ public async Task ProcessMessageAsync(ConsumerMessageEventArgs args, Ca args.Headers?.TryGetValue(_culture, out cultureCode); - if (cultureCode is null && !string.IsNullOrEmpty(_options.Settings.DefaultCulture)) + if (cultureCode is null && !string.IsNullOrEmpty(_options.Value.DefaultCulture)) { - cultureCode = _options.Settings.DefaultCulture; + cultureCode = _options.Value.DefaultCulture; } if (cultureCode != null) diff --git a/src/Liquid.Core/Decorators/LiquidScopedLoggingDecorator.cs b/src/Liquid.Core/Decorators/LiquidScopedLoggingDecorator.cs index 13c654ce..69cec8d5 100644 --- a/src/Liquid.Core/Decorators/LiquidScopedLoggingDecorator.cs +++ b/src/Liquid.Core/Decorators/LiquidScopedLoggingDecorator.cs @@ -3,6 +3,7 @@ using Liquid.Core.Interfaces; using Liquid.Core.Settings; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Threading; @@ -17,7 +18,7 @@ namespace Liquid.Core.Decorators public class LiquidScopedLoggingDecorator : ILiquidWorker { private readonly ILogger> _logger; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; private readonly ILiquidWorker _inner; /// @@ -27,7 +28,7 @@ public class LiquidScopedLoggingDecorator : ILiquidWorker /// Default culture configuration. /// Logger service instance. public LiquidScopedLoggingDecorator(ILiquidWorker inner - , ILiquidConfiguration options + , IOptions options , ILogger> logger) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); @@ -42,7 +43,7 @@ public async Task ProcessMessageAsync(ConsumerMessageEventArgs args, Ca object value = default; - foreach (var key in _options.Settings.Keys) + foreach (var key in _options.Value.Keys) { args.Headers?.TryGetValue(key.KeyName, out value); diff --git a/src/Liquid.Core/Extensions/DependencyInjection/IServiceCollectionLiquidExtension.cs b/src/Liquid.Core/Extensions/DependencyInjection/IServiceCollectionLiquidExtension.cs index babc31c0..4757886c 100644 --- a/src/Liquid.Core/Extensions/DependencyInjection/IServiceCollectionLiquidExtension.cs +++ b/src/Liquid.Core/Extensions/DependencyInjection/IServiceCollectionLiquidExtension.cs @@ -13,17 +13,7 @@ namespace Liquid.Core.Extensions.DependencyInjection /// public static class IServiceCollectionLiquidExtension { - /// - /// Inject a for each configuration section entity. - /// - /// Extended IServiceCollection instance. - public static IServiceCollection AddLiquidConfiguration(this IServiceCollection services) - { - services.TryAddTransient(typeof(ILiquidConfiguration<>), typeof(LiquidConfiguration<>)); - - return services; - } - + /// /// Register telemetry interceptor for defined services. /// diff --git a/src/Liquid.Core/Implementations/LiquidConfiguration.cs b/src/Liquid.Core/Implementations/LiquidConfiguration.cs deleted file mode 100644 index d59f73f8..00000000 --- a/src/Liquid.Core/Implementations/LiquidConfiguration.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Liquid.Core.Attributes; -using Liquid.Core.Interfaces; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using System; -using System.Reflection; - -namespace Liquid.Core.Implementations -{ - /// - public class LiquidConfiguration : ILiquidConfiguration where T : class, new() - { - /// - public T Settings { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Configured application settigs instance. - /// A set of key/value application settigs properties. - public LiquidConfiguration(IOptions options, IConfiguration configuration) - { - Settings = configuration.GetSection(GetSectionName(typeof(T))).Get() ?? options.Value; - - if (Settings is null) - throw new ArgumentNullException(GetSectionName(typeof(T))); - } - - private string GetSectionName(Type type) - { - var sectionAttibute = type.GetCustomAttribute(); - - return sectionAttibute?.SectionName ?? type.Name; - } - } -} \ No newline at end of file diff --git a/src/Liquid.Core/Interfaces/ILiquidConfiguration.cs b/src/Liquid.Core/Interfaces/ILiquidConfiguration.cs deleted file mode 100644 index cc93621f..00000000 --- a/src/Liquid.Core/Interfaces/ILiquidConfiguration.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Liquid.Core.Interfaces -{ - /// - /// Represents a set of key/value Liquid configuration properties. - /// - /// Type of settings entity. - public interface ILiquidConfiguration - { - /// - /// Set of key/value configuration section properties. - /// - TConfiguration Settings { get; } - } -} \ No newline at end of file diff --git a/src/Liquid.Core/Localization/JsonFileLocalization.cs b/src/Liquid.Core/Localization/JsonFileLocalization.cs index 67b35ce5..ae7894de 100644 --- a/src/Liquid.Core/Localization/JsonFileLocalization.cs +++ b/src/Liquid.Core/Localization/JsonFileLocalization.cs @@ -1,7 +1,7 @@ using Liquid.Core.Extensions; -using Liquid.Core.Interfaces; using Liquid.Core.Localization.Entities; using Liquid.Core.Settings; +using Microsoft.Extensions.Options; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -26,7 +26,7 @@ public class JsonFileLocalization : ILocalization /// Initializes a new instance of the class. /// /// The configuration. - public JsonFileLocalization(ILiquidConfiguration configuration) + public JsonFileLocalization(IOptions configuration) { _localizationItems = ReadLocalizationFiles(configuration); } @@ -101,9 +101,8 @@ public string Get(string key, CultureInfo culture, string channel = null) /// Reads the resource collection from file. /// /// The configuration. - /// /// - private static IDictionary ReadLocalizationFiles(ILiquidConfiguration configuration) + private static IDictionary ReadLocalizationFiles(IOptions configuration) { var items = new ConcurrentDictionary(); try @@ -115,7 +114,7 @@ private static IDictionary ReadLocalization { var fileInfo = new FileInfo(fileName); var filenameParts = fileInfo.Name.Split('.'); - var culture = filenameParts.Length == 2 ? configuration.Settings.DefaultCulture : filenameParts[1]; + var culture = filenameParts.Length == 2 ? configuration.Value.DefaultCulture : filenameParts[1]; using var fileReader = new StreamReader(fileName); var json = fileReader.ReadToEnd(); diff --git a/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IApplicationBuilderExtensions.cs b/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IApplicationBuilderExtensions.cs index 9edb5b65..f4819316 100644 --- a/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IApplicationBuilderExtensions.cs +++ b/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IApplicationBuilderExtensions.cs @@ -4,6 +4,7 @@ using Liquid.WebApi.Http.Settings; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace Liquid.WebApi.Http.Extensions.DependencyInjection { @@ -55,9 +56,9 @@ public static IApplicationBuilder UseLiquidScopedLogging(this IApplicationBuilde /// Extended application builder. public static IApplicationBuilder UseLiquidSwagger(this IApplicationBuilder builder) { - var configuration = builder.ApplicationServices.GetService>(); + var configuration = builder.ApplicationServices.GetService>(); - var swaggerSettings = configuration.Settings; + var swaggerSettings = configuration.Value; builder.UseSwagger().UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerSettings.SwaggerEndpoint.Url, swaggerSettings.SwaggerEndpoint.Name); diff --git a/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IServiceCollectionExtensions.cs b/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IServiceCollectionExtensions.cs index 2826c7a2..0f18f173 100644 --- a/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IServiceCollectionExtensions.cs +++ b/src/Liquid.WebApi.Http/Extensions/DependencyInjection/IServiceCollectionExtensions.cs @@ -5,7 +5,9 @@ using Liquid.Core.Interfaces; using Liquid.WebApi.Http.Filters.Swagger; using Liquid.WebApi.Http.Settings; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using System; using System.Diagnostics.CodeAnalysis; @@ -23,18 +25,22 @@ public static class IServiceCollectionExtensions { /// /// Registers a service and execute registration methods - /// to configure , /// set mapping , /// register domain handlers , /// and swagger /// /// Extended service collection instance. /// Array of assemblies that the domain handlers are implemented. - public static IServiceCollection AddLiquidHttp(this IServiceCollection services, params Assembly[] assemblies) + /// Swagger configuration section name. + public static IServiceCollection AddLiquidHttp(this IServiceCollection services, string sectionName, params Assembly[] assemblies) { services.AddScoped(); services.AddLiquidSerializers(); - services.AddLiquidConfiguration(); + services.AddOptions() + .Configure((settings, configuration) => + { + configuration.GetSection(sectionName).Bind(settings); + }); services.AddAutoMapper(assemblies); services.AddLiquidHandlers(true, true, assemblies); @@ -52,10 +58,10 @@ public static IServiceCollection AddLiquidSwagger(this IServiceCollection servic { var serviceProvider = services.BuildServiceProvider(); - var configuration = serviceProvider.GetService>(); - if (configuration?.Settings == null) throw new LiquidException("'swagger' settings does not exist in appsettings.json file. Please check the file."); + var configuration = serviceProvider.GetService>(); + if (configuration?.Value == null) throw new LiquidException("'swagger' settings does not exist in appsettings.json file. Please check the file."); - var swaggerSettings = configuration.Settings; + var swaggerSettings = configuration.Value; services.AddSwaggerGen(options => { options.SwaggerDoc(swaggerSettings.Name, diff --git a/src/Liquid.WebApi.Http/Middlewares/LiquidContextMiddleware.cs b/src/Liquid.WebApi.Http/Middlewares/LiquidContextMiddleware.cs index 4305ff16..598c6494 100644 --- a/src/Liquid.WebApi.Http/Middlewares/LiquidContextMiddleware.cs +++ b/src/Liquid.WebApi.Http/Middlewares/LiquidContextMiddleware.cs @@ -5,6 +5,7 @@ using Liquid.WebApi.Http.Extensions; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Threading.Tasks; @@ -19,14 +20,14 @@ namespace Liquid.WebApi.Http.Middlewares public class LiquidContextMiddleware { private readonly RequestDelegate _next; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; /// /// Initialize a instance of /// /// Invoked request. /// Context keys configuration. - public LiquidContextMiddleware(RequestDelegate next, ILiquidConfiguration options) + public LiquidContextMiddleware(RequestDelegate next, IOptions options) { _next = next; _options = options; @@ -44,7 +45,7 @@ public async Task InvokeAsync(HttpContext context) var value = string.Empty; - foreach (var key in _options.Settings.Keys) + foreach (var key in _options.Value.Keys) { value = context.GetValueFromHeader(key.KeyName); @@ -57,7 +58,7 @@ public async Task InvokeAsync(HttpContext context) liquidContext.Upsert(key.KeyName, value); } - if (_options.Settings.Culture) + if (_options.Value.Culture) { liquidContext.Upsert("culture", CultureInfo.CurrentCulture.Name); } diff --git a/src/Liquid.WebApi.Http/Middlewares/LiquidCultureMiddleware.cs b/src/Liquid.WebApi.Http/Middlewares/LiquidCultureMiddleware.cs index aa375cf1..56891a18 100644 --- a/src/Liquid.WebApi.Http/Middlewares/LiquidCultureMiddleware.cs +++ b/src/Liquid.WebApi.Http/Middlewares/LiquidCultureMiddleware.cs @@ -2,6 +2,7 @@ using Liquid.Core.Settings; using Liquid.WebApi.Http.Extensions; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Threading.Tasks; @@ -16,7 +17,7 @@ namespace Liquid.WebApi.Http.Middlewares public sealed class LiquidCultureMiddleware { private const string _culture = "culture"; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; private readonly RequestDelegate _next; /// @@ -24,7 +25,7 @@ public sealed class LiquidCultureMiddleware /// /// The next. /// - public LiquidCultureMiddleware(RequestDelegate next, ILiquidConfiguration options) + public LiquidCultureMiddleware(RequestDelegate next, IOptions options) { _next = next; _options = options; @@ -44,9 +45,9 @@ public async Task InvokeAsync(HttpContext context) cultureCode = context.GetValueFromQuery(_culture).ToString(); } - if (string.IsNullOrEmpty(cultureCode) && !string.IsNullOrEmpty(_options.Settings.DefaultCulture)) + if (string.IsNullOrEmpty(cultureCode) && !string.IsNullOrEmpty(_options.Value.DefaultCulture)) { - cultureCode = _options.Settings.DefaultCulture; + cultureCode = _options.Value.DefaultCulture; } if (!string.IsNullOrEmpty(cultureCode)) diff --git a/src/Liquid.WebApi.Http/Middlewares/LiquidScopedLoggingMiddleware.cs b/src/Liquid.WebApi.Http/Middlewares/LiquidScopedLoggingMiddleware.cs index 1de86d74..4090f0b5 100644 --- a/src/Liquid.WebApi.Http/Middlewares/LiquidScopedLoggingMiddleware.cs +++ b/src/Liquid.WebApi.Http/Middlewares/LiquidScopedLoggingMiddleware.cs @@ -4,6 +4,7 @@ using Liquid.WebApi.Http.Extensions; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; @@ -19,7 +20,7 @@ public class LiquidScopedLoggingMiddleware { private readonly RequestDelegate _next; private readonly ILogger _logger; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; /// /// Initialize a new instance of @@ -27,7 +28,7 @@ public class LiquidScopedLoggingMiddleware /// Invoked request. /// Logger service instance. /// Context keys set. - public LiquidScopedLoggingMiddleware(RequestDelegate next, ILogger logger, ILiquidConfiguration options) + public LiquidScopedLoggingMiddleware(RequestDelegate next, ILogger logger, IOptions options) { _next = next; _logger = logger; @@ -43,7 +44,7 @@ public async Task InvokeAsync(HttpContext context) { var scope = new List>(); - foreach (var key in _options.Settings.Keys) + foreach (var key in _options.Value.Keys) { var value = context.GetValueFromHeader(key.KeyName); diff --git a/test/Liquid.Core.Tests/Core/LiquidConfigurationTest.cs b/test/Liquid.Core.Tests/Core/LiquidConfigurationTest.cs deleted file mode 100644 index bbea18c7..00000000 --- a/test/Liquid.Core.Tests/Core/LiquidConfigurationTest.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Liquid.Core.Implementations; -using Liquid.Core.Tests.Mocks; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using NSubstitute; -using System; -using Xunit; - -namespace Liquid.Core.Tests.Core -{ - public class LiquidConfigurationTest - { - private IOptions _options = Substitute.For>(); - private IConfiguration _config = Substitute.For(); - private MockSettings _settings = new MockSettings(); - - [Fact] - public void Ctor_WhenInjectOptions_Success() - { - _settings.MyProperty = "options"; - - _options.Value.Returns(_settings); - - var sut = new LiquidConfiguration(_options, _config); - - Assert.True(sut.Settings.MyProperty == _settings.MyProperty); - } - - [Fact] - public void Ctor_WhenInjectLiquidConfiguration_Success() - { - _settings.MyProperty = "Liquid"; - - var builder = new ConfigurationBuilder(); - - builder.AddJsonFile("appsettings.json"); - - _config = builder.Build(); - - var sut = new LiquidConfiguration(_options, _config); - - Assert.True(sut.Settings.MyProperty == _settings.MyProperty); - } - - [Fact] - public void Ctor_WhenInjectSectionDoesntExists_ArgumentNullException() - { - Assert.Throws(() => new LiquidConfiguration(_options, _config)); - } - - [Fact] - public void Ctor_WhenEntityHasNoAttribute_Success() - { - _settings.MyProperty = "Liquid"; - - var builder = new ConfigurationBuilder(); - - builder.AddJsonFile("appsettings.json"); - - _config = builder.Build(); - - var options = Substitute.For>(); - - var sut = new LiquidConfiguration(options, _config); - - Assert.True(sut.Settings.MyProperty == _settings.MyProperty); - } - } -} diff --git a/test/Liquid.Core.Tests/Messaging/IServiceCollectionExtensionTest.cs b/test/Liquid.Core.Tests/Messaging/IServiceCollectionExtensionTest.cs index 83a76086..52e5ada8 100644 --- a/test/Liquid.Core.Tests/Messaging/IServiceCollectionExtensionTest.cs +++ b/test/Liquid.Core.Tests/Messaging/IServiceCollectionExtensionTest.cs @@ -85,9 +85,9 @@ private void ConfigureServices() _services.AddSingleton(Substitute.For>()); _services.AddSingleton(Substitute.For>()); _services.AddSingleton(Substitute.For>()); - _services.AddSingleton(Substitute.For>()); - _services.AddSingleton(Substitute.For>()); - _services.AddSingleton(Substitute.For>()); + _services.AddSingleton(Substitute.For>()); + _services.AddSingleton(Substitute.For>()); + _services.AddSingleton(Substitute.For>()); _services.AddSingleton(Substitute.For>>()); } } diff --git a/test/Liquid.Core.Tests/Messaging/LiquidContextDecoratorTest.cs b/test/Liquid.Core.Tests/Messaging/LiquidContextDecoratorTest.cs index b017764a..dc962865 100644 --- a/test/Liquid.Core.Tests/Messaging/LiquidContextDecoratorTest.cs +++ b/test/Liquid.Core.Tests/Messaging/LiquidContextDecoratorTest.cs @@ -11,6 +11,7 @@ using Xunit; using Liquid.Core.Tests.Mocks; using Liquid.Core.Entities; +using Microsoft.Extensions.Options; namespace Liquid.Core.Tests.Messaging { @@ -18,18 +19,18 @@ public class LiquidContextDecoratorTest { private readonly ILiquidWorker _inner; private readonly ILiquidContext _context; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; public LiquidContextDecoratorTest() { _inner = Substitute.For>(); _context = new LiquidContext(); - _options = Substitute.For>(); + _options = Substitute.For>(); var settings = new ScopedContextSettings(); settings.Keys.Add(new ScopedKey() { KeyName = "test", Required = true }); settings.Culture = true; - _options.Settings.Returns(settings); + _options.Value.Returns(settings); } diff --git a/test/Liquid.Core.Tests/Messaging/LiquidCultureDecoratorTest.cs b/test/Liquid.Core.Tests/Messaging/LiquidCultureDecoratorTest.cs index 898eb92f..4b0d68cb 100644 --- a/test/Liquid.Core.Tests/Messaging/LiquidCultureDecoratorTest.cs +++ b/test/Liquid.Core.Tests/Messaging/LiquidCultureDecoratorTest.cs @@ -3,6 +3,7 @@ using Liquid.Core.Interfaces; using Liquid.Core.Settings; using Liquid.Core.Tests.Mocks; +using Microsoft.Extensions.Options; using NSubstitute; using System.Globalization; using System.Threading; @@ -13,20 +14,20 @@ namespace Liquid.Core.Tests.Messaging { public class LiquidCultureDecoratorTest { - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; private readonly ILiquidWorker _inner; public LiquidCultureDecoratorTest() { _inner = Substitute.For>(); - _options = Substitute.For>(); + _options = Substitute.For>(); } [Fact] public async Task ProcessMessageAsync_CultureSettingsIsNull_CurrentCultureNotChanged() { var settings = new CultureSettings(); - _options.Settings.Returns(settings); + _options.Value.Returns(settings); var currentculture = CultureInfo.CurrentCulture.Name; @@ -41,7 +42,7 @@ public async Task ProcessMessageAsync_CultureSettingsIsNull_CurrentCultureNotCha public async Task ProcessMessageAsync_CultureSettingsIsNotNull_CurrentCultureChanged() { var settings = new CultureSettings() { DefaultCulture = "pt-BR" }; - _options.Settings.Returns(settings); + _options.Value.Returns(settings); var currentculture = CultureInfo.CurrentCulture.Name; diff --git a/test/Liquid.Core.Tests/Messaging/LiquidScopedLoggingDecoratorTest.cs b/test/Liquid.Core.Tests/Messaging/LiquidScopedLoggingDecoratorTest.cs index f039dacf..9d286ad6 100644 --- a/test/Liquid.Core.Tests/Messaging/LiquidScopedLoggingDecoratorTest.cs +++ b/test/Liquid.Core.Tests/Messaging/LiquidScopedLoggingDecoratorTest.cs @@ -5,6 +5,7 @@ using Liquid.Core.Settings; using Liquid.Core.Tests.Mocks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using NSubstitute; using System; using System.Collections.Generic; @@ -17,20 +18,20 @@ namespace Liquid.Core.Tests.Messaging public class LiquidScopedLoggingDecoratorTest { private readonly ILogger> _logger; - private readonly ILiquidConfiguration _options; + private readonly IOptions _options; private readonly ILiquidWorker _inner; public LiquidScopedLoggingDecoratorTest() { _logger = Substitute.For>>(); - _options = Substitute.For>(); + _options = Substitute.For>(); _inner = Substitute.For>(); var settings = new ScopedLoggingSettings(); settings.Keys.Add(new ScopedKey() { KeyName = "test", Required = true }); - _options.Settings.Returns(settings); + _options.Value.Returns(settings); } [Fact]