From 3f05e2765f6988e46dd9ad86885ff06dcb0ec168 Mon Sep 17 00:00:00 2001 From: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:29:19 +0000 Subject: [PATCH] Switch to blocked namespace in new test class * Suppress ConfigureAwait warnings in unit test class Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> --- .../Hooks/LoggingHookTests.cs | 804 +++++++++--------- 1 file changed, 404 insertions(+), 400 deletions(-) diff --git a/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs b/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs index 044c93e6..51ec8cb1 100644 --- a/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs +++ b/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; @@ -7,33 +8,35 @@ using OpenFeature.Model; using Xunit; -namespace OpenFeature.Tests.Hooks; - -public class LoggingHookTests +namespace OpenFeature.Tests.Hooks { - [Fact] - public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log() + [SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task")] + + public class LoggingHookTests { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - // Act - await hook.BeforeAsync(context); + // Act + await hook.BeforeAsync(context); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; + var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); - Assert.Equal( + Assert.Equal(LogLevel.Debug, record.Level); + Assert.Equal( """ Before Flag Evaluation Domain:client ProviderName:provider @@ -41,29 +44,29 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log() DefaultValue:False """, - record.Message); - } + record.Message); + } - [Fact] - public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - // Act - await hook.BeforeAsync(context); + // Act + await hook.BeforeAsync(context); - // Assert - var record = logger.LatestRecord; + // Assert + var record = logger.LatestRecord; - Assert.Equal( + Assert.Equal( """ Before Flag Evaluation Domain:client ProviderName:provider @@ -71,40 +74,40 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Me DefaultValue:False """, - record.Message); - } + record.Message); + } - [Fact] - public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", "value") - .Set("key_2", false) - .Set("key_3", 1.531) - .Set("key_4", 42) - .Set("key_5", DateTime.Parse("2025-01-01T11:00:00.0000000Z")) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", "value") + .Set("key_2", false) + .Set("key_3", 1.531) + .Set("key_4", 42) + .Set("key_5", DateTime.Parse("2025-01-01T11:00:00.0000000Z")) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.BeforeAsync(context); + // Act + await hook.BeforeAsync(context); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Debug, record.Level); - Assert.Contains( + Assert.Contains( """ Before Flag Evaluation Domain:client ProviderName:provider @@ -112,40 +115,40 @@ public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Messa DefaultValue:False Context: """, - record.Message); - Assert.Multiple( - () => Assert.Contains("key_1:value", record.Message), - () => Assert.Contains("key_2:False", record.Message), - () => Assert.Contains("key_3:1.531", record.Message), - () => Assert.Contains("key_4:42", record.Message), - () => Assert.Contains("key_5:2025-01-01T11:00:00.0000000+00:00", record.Message) - ); - } + record.Message); + Assert.Multiple( + () => Assert.Contains("key_1:value", record.Message), + () => Assert.Contains("key_2:False", record.Message), + () => Assert.Contains("key_3:1.531", record.Message), + () => Assert.Contains("key_4:42", record.Message), + () => Assert.Contains("key_5:2025-01-01T11:00:00.0000000+00:00", record.Message) + ); + } - [Fact] - public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - // Act - var hook = new LoggingHook(logger, includeContext: true); + // Act + var hook = new LoggingHook(logger, includeContext: true); - await hook.BeforeAsync(context); + await hook.BeforeAsync(context); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Debug, record.Level); - Assert.Equal( + Assert.Equal( """ Before Flag Evaluation Domain:client ProviderName:provider @@ -154,57 +157,57 @@ public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Me Context: """, - record.Message); - } + record.Message); + } - [Fact] - public async Task ErrorAsync_Without_EvaluationContext_Generates_Error_Log() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task ErrorAsync_Without_EvaluationContext_Generates_Error_Log() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - var exception = new Exception("Error within hook!"); + var exception = new Exception("Error within hook!"); - // Act - await hook.ErrorAsync(context, exception); + // Act + await hook.ErrorAsync(context, exception); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; + var record = logger.LatestRecord; - Assert.Equal(LogLevel.Error, record.Level); - } + Assert.Equal(LogLevel.Error, record.Level); + } - [Fact] - public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - var exception = new Exception("Error within hook!"); + var exception = new Exception("Error within hook!"); - // Act - await hook.ErrorAsync(context, exception); + // Act + await hook.ErrorAsync(context, exception); - // Assert - var record = logger.LatestRecord; + // Assert + var record = logger.LatestRecord; - Assert.Equal( + Assert.Equal( """ Error during Flag Evaluation Domain:client ProviderName:provider @@ -212,42 +215,42 @@ public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Mes DefaultValue:False """, - record.Message); - } + record.Message); + } - [Fact] - public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", " ") - .Set("key_2", true) - .Set("key_3", 0.002154) - .Set("key_4", -15) - .Set("key_5", DateTime.Parse("2099-01-01T01:00:00.0000000Z")) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", " ") + .Set("key_2", true) + .Set("key_3", 0.002154) + .Set("key_4", -15) + .Set("key_5", DateTime.Parse("2099-01-01T01:00:00.0000000Z")) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - var exception = new Exception("Error within hook!"); + var exception = new Exception("Error within hook!"); - // Act - await hook.ErrorAsync(context, exception); + // Act + await hook.ErrorAsync(context, exception); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Error, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Error, record.Level); - Assert.Contains( + Assert.Contains( """ Error during Flag Evaluation Domain:client ProviderName:provider @@ -255,41 +258,41 @@ public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Messag DefaultValue:False Context: """, - record.Message); - Assert.Multiple( - () => Assert.Contains("key_1: ", record.Message), - () => Assert.Contains("key_2:True", record.Message), - () => Assert.Contains("key_3:0.002154", record.Message), - () => Assert.Contains("key_4:-15", record.Message), - () => Assert.Contains("key_5:2099-01-01T01:00:00.0000000+00:00", record.Message) - ); - } + record.Message); + Assert.Multiple( + () => Assert.Contains("key_1: ", record.Message), + () => Assert.Contains("key_2:True", record.Message), + () => Assert.Contains("key_3:0.002154", record.Message), + () => Assert.Contains("key_4:-15", record.Message), + () => Assert.Contains("key_5:2099-01-01T01:00:00.0000000+00:00", record.Message) + ); + } - [Fact] - public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - var exception = new Exception("Error within hook!"); + var exception = new Exception("Error within hook!"); - // Act - await hook.ErrorAsync(context, exception); + // Act + await hook.ErrorAsync(context, exception); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Error, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Error, record.Level); - Assert.Equal( + Assert.Equal( """ Error during Flag Evaluation Domain:client ProviderName:provider @@ -298,56 +301,56 @@ public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes Context: """, - record.Message); - } + record.Message); + } - [Fact] - public async Task AfterAsync_Without_EvaluationContext_Generates_Debug_Log() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task AfterAsync_Without_EvaluationContext_Generates_Debug_Log() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); - } + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Debug, record.Level); + } - [Fact] - public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: false); + var hook = new LoggingHook(logger, includeContext: false); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; + // Assert + var record = logger.LatestRecord; - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:provider @@ -355,42 +358,42 @@ public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Mes DefaultValue:False """, - record.Message); - } + record.Message); + } - [Fact] - public async Task AfterAsync_With_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task AfterAsync_With_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", "") - .Set("key_2", false) - .Set("key_3", double.MinValue) - .Set("key_4", int.MaxValue) - .Set("key_5", DateTime.MinValue) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", "") + .Set("key_2", false) + .Set("key_3", double.MinValue) + .Set("key_4", int.MaxValue) + .Set("key_5", DateTime.MinValue) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Debug, record.Level); - Assert.Contains( + Assert.Contains( """ After Flag Evaluation Domain:client ProviderName:provider @@ -398,49 +401,49 @@ public async Task AfterAsync_With_EvaluationContext_Generates_Correct_Log_Messag DefaultValue:False Context: """, - record.Message); + record.Message); - // .NET Framework uses G15 formatter on double.ToString - // .NET uses G17 formatter on double.ToString + // .NET Framework uses G15 formatter on double.ToString + // .NET uses G17 formatter on double.ToString #if NET462 - var expectedMaxDoubleString = "-1.79769313486232E+308"; + var expectedMaxDoubleString = "-1.79769313486232E+308"; #else - var expectedMaxDoubleString = "-1.7976931348623157E+308"; + var expectedMaxDoubleString = "-1.7976931348623157E+308"; #endif - Assert.Multiple( - () => Assert.Contains("key_1:", record.Message), - () => Assert.Contains("key_2:False", record.Message), - () => Assert.Contains($"key_3:{expectedMaxDoubleString}", record.Message), - () => Assert.Contains("key_4:2147483647", record.Message), - () => Assert.Contains("key_5:0001-01-01T00:00:00.0000000", record.Message) - ); - } + Assert.Multiple( + () => Assert.Contains("key_1:", record.Message), + () => Assert.Contains("key_2:False", record.Message), + () => Assert.Contains($"key_3:{expectedMaxDoubleString}", record.Message), + () => Assert.Contains("key_4:2147483647", record.Message), + () => Assert.Contains("key_5:0001-01-01T00:00:00.0000000", record.Message) + ); + } - [Fact] - public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Message() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, EvaluationContext.Empty); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, EvaluationContext.Empty); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - Assert.Equal(1, logger.Collector.Count); + // Assert + Assert.Equal(1, logger.Collector.Count); - var record = logger.LatestRecord; - Assert.Equal(LogLevel.Debug, record.Level); + var record = logger.LatestRecord; + Assert.Equal(LogLevel.Debug, record.Level); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:provider @@ -449,44 +452,44 @@ public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes Context: """, - record.Message); - } + record.Message); + } - [Fact] - public void Create_LoggingHook_Without_Logger() - { - Assert.Throws(() => new LoggingHook(null!, includeContext: true)); - } + [Fact] + public void Create_LoggingHook_Without_Logger() + { + Assert.Throws(() => new LoggingHook(null!, includeContext: true)); + } - [Fact] - public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", Structure.Builder().Set("inner_key_1", false).Build()) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", Structure.Builder().Set("inner_key_1", false).Build()) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; + // Assert + var record = logger.LatestRecord; - // Raw string literals will convert tab to spaces (the File index style) - var message = NormalizeLogRecord(record); + // Raw string literals will convert tab to spaces (the File index style) + var message = NormalizeLogRecord(record); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:provider @@ -496,37 +499,37 @@ public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value key_1:OpenFeature.Model.Value """, - message - ); - } + message + ); + } - [Fact] - public async Task Without_Domain_Returns_Missing() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task Without_Domain_Returns_Missing() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata(null, "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", true) - .Build(); + var clientMetadata = new ClientMetadata(null, "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", true) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; - var message = NormalizeLogRecord(record); + // Assert + var record = logger.LatestRecord; + var message = NormalizeLogRecord(record); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:missing ProviderName:provider @@ -536,37 +539,37 @@ public async Task Without_Domain_Returns_Missing() key_1:True """, - message - ); - } + message + ); + } - [Fact] - public async Task Without_Provider_Returns_Missing() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task Without_Provider_Returns_Missing() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata(null); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", true) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata(null); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", true) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; - var message = NormalizeLogRecord(record); + // Assert + var record = logger.LatestRecord; + var message = NormalizeLogRecord(record); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:missing @@ -576,37 +579,37 @@ public async Task Without_Provider_Returns_Missing() key_1:True """, - message - ); - } + message + ); + } - [Fact] - public async Task Without_DefaultValue_Returns_Missing() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task Without_DefaultValue_Returns_Missing() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", true) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", true) + .Build(); - var context = new HookContext("test", null!, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", null!, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", "true", ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", "true", ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; - var message = NormalizeLogRecord(record); + // Assert + var record = logger.LatestRecord; + var message = NormalizeLogRecord(record); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:provider @@ -616,37 +619,37 @@ public async Task Without_DefaultValue_Returns_Missing() key_1:True """, - message - ); - } + message + ); + } - [Fact] - public async Task Without_EvaluationContextValue_Returns_Nothing() - { - // Arrange - var logger = new FakeLogger(); + [Fact] + public async Task Without_EvaluationContextValue_Returns_Nothing() + { + // Arrange + var logger = new FakeLogger(); - var clientMetadata = new ClientMetadata("client", "1.0.0"); - var providerMetadata = new Metadata("provider"); - var evaluationContext = EvaluationContext.Builder() - .Set("key_1", (string)null!) - .Build(); + var clientMetadata = new ClientMetadata("client", "1.0.0"); + var providerMetadata = new Metadata("provider"); + var evaluationContext = EvaluationContext.Builder() + .Set("key_1", (string)null!) + .Build(); - var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, - providerMetadata, evaluationContext); + var context = new HookContext("test", false, FlagValueType.Object, clientMetadata, + providerMetadata, evaluationContext); - var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); + var details = new FlagEvaluationDetails("test", true, ErrorType.None, reason: null, variant: null); - var hook = new LoggingHook(logger, includeContext: true); + var hook = new LoggingHook(logger, includeContext: true); - // Act - await hook.AfterAsync(context, details); + // Act + await hook.AfterAsync(context, details); - // Assert - var record = logger.LatestRecord; - var message = NormalizeLogRecord(record); + // Assert + var record = logger.LatestRecord; + var message = NormalizeLogRecord(record); - Assert.Equal( + Assert.Equal( """ After Flag Evaluation Domain:client ProviderName:provider @@ -656,15 +659,16 @@ public async Task Without_EvaluationContextValue_Returns_Nothing() key_1: """, - message - ); - } + message + ); + } - private static string NormalizeLogRecord(FakeLogRecord record) - { - // Raw string literals will convert tab to spaces (the File index style) - const int tabSize = 4; + private static string NormalizeLogRecord(FakeLogRecord record) + { + // Raw string literals will convert tab to spaces (the File index style) + const int tabSize = 4; - return record.Message.Replace("\t", new string(' ', tabSize)); + return record.Message.Replace("\t", new string(' ', tabSize)); + } } }