Skip to content

Commit

Permalink
Fixed unit-test warnings about using Assert.Single with Predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Oct 27, 2024
1 parent cb3adfb commit b57f815
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions test/NLog.Extensions.Logging.Tests/NLogLoggingConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void LoadSimpleConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand Down Expand Up @@ -100,8 +100,8 @@ public void LoadSimpleConfigWithCustomKey()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -117,8 +117,8 @@ public void LoadSimpleConfigAndTrimSpace()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -135,9 +135,9 @@ public void LoadWrapperConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(3, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper));
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper);
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("wrappedFile") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -154,9 +154,9 @@ public void LoadWrapperConfigExplicitName()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(3, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper));
Assert.Single(logConfig.AllTargets.Where(t => t is MemoryTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper);
Assert.Single(logConfig.AllTargets, (t) => t is MemoryTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.NotNull(logConfig.FindTargetByName("wrappedMem") as MemoryTarget);
}

Expand All @@ -171,8 +171,8 @@ public void LoadWrapperConfigWithoutName()

Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper));
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper);
Assert.True(logConfig.FindTargetByName<AsyncTargetWrapper>("file")?.WrappedTarget is MemoryTarget);
}

Expand All @@ -189,8 +189,8 @@ public void LoadVariablesConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -209,8 +209,8 @@ public void LoadVariablesDependentConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello/world.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -234,8 +234,8 @@ public void LoadVariableJsonLayoutConfig()
Assert.Single(logConfig.Variables);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal(2, logConfig.AllTargets.Count(t => (t as TargetWithLayout)?.Layout is NLog.Layouts.JsonLayout));
}

Expand All @@ -259,8 +259,8 @@ public void LoadVariableDependentJsonLayoutConfig()
Assert.Equal(3, logConfig.Variables.Count);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal(2, logConfig.AllTargets.Count(t => (t as TargetWithLayout)?.Layout is NLog.Layouts.JsonLayout));
}

Expand All @@ -278,8 +278,8 @@ public void LoadDefaultWrapperConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, (logConfig.AllTargets.Count(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.BatchSize == 1)));
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is ConsoleTarget);
Assert.Equal("hello.txt", ((logConfig.FindTargetByName("file") as AsyncTargetWrapper)?.WrappedTarget as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -297,8 +297,8 @@ public void LoadTargetDefaultWrapperConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, (logConfig.AllTargets.Count(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.BatchSize == 1)));
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is AsyncTargetWrapper asyncTarget && asyncTarget.WrappedTarget is ConsoleTarget);
Assert.Equal("hello.txt", ((logConfig.FindTargetByName("file") as AsyncTargetWrapper)?.WrappedTarget as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
}

Expand All @@ -315,8 +315,8 @@ public void LoadDefaultTargetParametersConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName?.Render(LogEventInfo.CreateNullEvent()));
Assert.True((logConfig.FindTargetByName("console") as ConsoleTarget)?.StdErr);
}
Expand All @@ -334,8 +334,8 @@ public void LoadTargetDefaultParametersConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName?.Render(LogEventInfo.CreateNullEvent()));
Assert.True((logConfig.FindTargetByName("console") as ConsoleTarget)?.StdErr);
}
Expand All @@ -359,8 +359,8 @@ public void LoadDefaultTargetParametersJsonLayoutConfig()
Assert.Single(logConfig.LoggingRules);
Assert.Equal(2, logConfig.LoggingRules[0].Targets.Count);
Assert.Equal(2, logConfig.AllTargets.Count);
Assert.Single(logConfig.AllTargets.Where(t => t is FileTarget));
Assert.Single(logConfig.AllTargets.Where(t => t is ConsoleTarget));
Assert.Single(logConfig.AllTargets, (t) => t is FileTarget);
Assert.Single(logConfig.AllTargets, (t) => t is ConsoleTarget);
Assert.Equal("hello.txt", (logConfig.FindTargetByName("file") as FileTarget)?.FileName.Render(LogEventInfo.CreateNullEvent()));
Assert.Equal(3, ((logConfig.FindTargetByName("file") as FileTarget)?.Layout as NLog.Layouts.JsonLayout)?.Attributes?.Count);
}
Expand Down

0 comments on commit b57f815

Please sign in to comment.