From 0391d84c46df94080f9d8cf672ef67ea37a9639b Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 13 Mar 2023 20:58:40 +0300 Subject: [PATCH] Add API approval test --- .../Approval/ApiApprovalTests.cs | 27 +++++++ .../Serilog.Sinks.Console.approved.txt | 70 +++++++++++++++++++ .../Serilog.Sinks.Console.Tests.csproj | 4 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 test/Serilog.Sinks.Console.Tests/Approval/ApiApprovalTests.cs create mode 100644 test/Serilog.Sinks.Console.Tests/Approval/Serilog.Sinks.Console.approved.txt diff --git a/test/Serilog.Sinks.Console.Tests/Approval/ApiApprovalTests.cs b/test/Serilog.Sinks.Console.Tests/Approval/ApiApprovalTests.cs new file mode 100644 index 0000000..46b1c72 --- /dev/null +++ b/test/Serilog.Sinks.Console.Tests/Approval/ApiApprovalTests.cs @@ -0,0 +1,27 @@ +#if NET5_0 + +using PublicApiGenerator; +using Shouldly; +using Xunit; + +namespace Serilog.Sinks.Console.Tests.Approval +{ + public class ApiApprovalTests + { + [Fact] + public void PublicApi_Should_Not_Change_Unintentionally() + { + var assembly = typeof(ConsoleLoggerConfigurationExtensions).Assembly; + var publicApi = assembly.GeneratePublicApi( + new ApiGeneratorOptions() + { + IncludeAssemblyAttributes = false, + ExcludeAttributes = new[] { "System.Diagnostics.DebuggerDisplayAttribute" }, + }); + + publicApi.ShouldMatchApproved(options => options.WithFilenameGenerator((_, __, fileType, fileExtension) => $"{assembly.GetName().Name!}.{fileType}.{fileExtension}")); + } + } +} + +#endif diff --git a/test/Serilog.Sinks.Console.Tests/Approval/Serilog.Sinks.Console.approved.txt b/test/Serilog.Sinks.Console.Tests/Approval/Serilog.Sinks.Console.approved.txt new file mode 100644 index 0000000..25fdc2e --- /dev/null +++ b/test/Serilog.Sinks.Console.Tests/Approval/Serilog.Sinks.Console.approved.txt @@ -0,0 +1,70 @@ +namespace Serilog +{ + public static class ConsoleLoggerConfigurationExtensions + { + public static Serilog.LoggerConfiguration Console(this Serilog.Configuration.LoggerSinkConfiguration sinkConfiguration, Serilog.Formatting.ITextFormatter formatter, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, Serilog.Core.LoggingLevelSwitch? levelSwitch = null, Serilog.Events.LogEventLevel? standardErrorFromLevel = default, object? syncRoot = null) { } + public static Serilog.LoggerConfiguration Console(this Serilog.Configuration.LoggerSinkConfiguration sinkConfiguration, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, string outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}", System.IFormatProvider? formatProvider = null, Serilog.Core.LoggingLevelSwitch? levelSwitch = null, Serilog.Events.LogEventLevel? standardErrorFromLevel = default, Serilog.Sinks.SystemConsole.Themes.ConsoleTheme? theme = null, bool applyThemeToRedirectedOutput = false, object? syncRoot = null) { } + } +} +namespace Serilog.Sinks.SystemConsole.Themes +{ + public class AnsiConsoleTheme : Serilog.Sinks.SystemConsole.Themes.ConsoleTheme + { + public AnsiConsoleTheme(System.Collections.Generic.IReadOnlyDictionary styles) { } + public override bool CanBuffer { get; } + protected override int ResetCharCount { get; } + public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Code { get; } + public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Grayscale { get; } + public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Literate { get; } + public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Sixteen { get; } + public override void Reset(System.IO.TextWriter output) { } + public override int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style) { } + } + public abstract class ConsoleTheme + { + protected ConsoleTheme() { } + public abstract bool CanBuffer { get; } + protected abstract int ResetCharCount { get; } + public static Serilog.Sinks.SystemConsole.Themes.ConsoleTheme None { get; } + public abstract void Reset(System.IO.TextWriter output); + public abstract int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style); + } + public enum ConsoleThemeStyle + { + Text = 0, + SecondaryText = 1, + TertiaryText = 2, + Invalid = 3, + Null = 4, + Name = 5, + String = 6, + Number = 7, + Boolean = 8, + Scalar = 9, + [System.Obsolete("Use ConsoleThemeStyle.Scalar instead")] + Object = 9, + LevelVerbose = 10, + LevelDebug = 11, + LevelInformation = 12, + LevelWarning = 13, + LevelError = 14, + LevelFatal = 15, + } + public class SystemConsoleTheme : Serilog.Sinks.SystemConsole.Themes.ConsoleTheme + { + public SystemConsoleTheme(System.Collections.Generic.IReadOnlyDictionary styles) { } + public override bool CanBuffer { get; } + protected override int ResetCharCount { get; } + public System.Collections.Generic.IReadOnlyDictionary Styles { get; } + public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Colored { get; } + public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Grayscale { get; } + public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Literate { get; } + public override void Reset(System.IO.TextWriter output) { } + public override int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style) { } + } + public struct SystemConsoleThemeStyle + { + public System.ConsoleColor? Background; + public System.ConsoleColor? Foreground; + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index e7717cc..57b8025 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48;net5.0 @@ -19,6 +19,8 @@ + +