From 2d5e1dd1dbdf4c684ed691e8690b1835fe2be01d Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 13 Mar 2023 09:32:30 +0300 Subject: [PATCH] Add API approval test --- .gitignore | 5 +- .../ApiApprovalTests.cs | 25 ++++++++++ ...erilog.Settings.Configuration.Tests.csproj | 3 +- ...erilog.Settings.Configuration.approved.txt | 50 +++++++++++++++++++ 4 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 test/Serilog.Settings.Configuration.Tests/ApiApprovalTests.cs create mode 100644 test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.approved.txt diff --git a/.gitignore b/.gitignore index 29e6b229..c90bd95b 100644 --- a/.gitignore +++ b/.gitignore @@ -132,7 +132,7 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj @@ -200,7 +200,4 @@ FakesAssemblies/ project.lock.json -#Test files -*.txt - artifacts/ diff --git a/test/Serilog.Settings.Configuration.Tests/ApiApprovalTests.cs b/test/Serilog.Settings.Configuration.Tests/ApiApprovalTests.cs new file mode 100644 index 00000000..08bf7f46 --- /dev/null +++ b/test/Serilog.Settings.Configuration.Tests/ApiApprovalTests.cs @@ -0,0 +1,25 @@ +#if NET7_0 + +using PublicApiGenerator; +using Shouldly; + +namespace Serilog.Settings.Configuration.Tests; + +public class ApiApprovalTests +{ + [Fact] + public void PublicApi_Should_Not_Change_Unintentionally() + { + var assembly = typeof(ConfigurationReaderOptions).Assembly; + var publicApi = assembly.GeneratePublicApi( + new() + { + 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.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj index 5836bfb6..246d9765 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -19,10 +19,11 @@ - + + diff --git a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.approved.txt b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.approved.txt new file mode 100644 index 00000000..912f1716 --- /dev/null +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.approved.txt @@ -0,0 +1,50 @@ +namespace Serilog +{ + public static class ConfigurationLoggerConfigurationExtensions + { + public const string DefaultSectionName = "Serilog"; + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, Microsoft.Extensions.DependencyModel.DependencyContext dependencyContext) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, Serilog.Settings.Configuration.ConfigurationAssemblySource configurationAssemblySource) { } + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, Serilog.Settings.Configuration.ConfigurationReaderOptions readerOptions = null) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, params System.Reflection.Assembly[] assemblies) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, string sectionName, Microsoft.Extensions.DependencyModel.DependencyContext dependencyContext = null) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, string sectionName, Serilog.Settings.Configuration.ConfigurationAssemblySource configurationAssemblySource) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, ConfigurationReaderOptio" + + "ns readerOptions) instead.")] + public static Serilog.LoggerConfiguration Configuration(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfiguration configuration, string sectionName, params System.Reflection.Assembly[] assemblies) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, string sectionName, Depe" + + "ndencyContext dependencyContext) instead.")] + public static Serilog.LoggerConfiguration ConfigurationSection(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfigurationSection configSection, Microsoft.Extensions.DependencyModel.DependencyContext dependencyContext = null) { } + [System.Obsolete("Use ReadFrom.Configuration(IConfiguration configuration, string sectionName, Conf" + + "igurationAssemblySource configurationAssemblySource) instead.")] + public static Serilog.LoggerConfiguration ConfigurationSection(this Serilog.Configuration.LoggerSettingsConfiguration settingConfiguration, Microsoft.Extensions.Configuration.IConfigurationSection configSection, Serilog.Settings.Configuration.ConfigurationAssemblySource configurationAssemblySource) { } + } +} +namespace Serilog.Settings.Configuration +{ + public enum ConfigurationAssemblySource + { + UseLoadedAssemblies = 0, + AlwaysScanDllFiles = 1, + } + public sealed class ConfigurationReaderOptions + { + public ConfigurationReaderOptions() { } + public ConfigurationReaderOptions(Microsoft.Extensions.DependencyModel.DependencyContext dependencyContext) { } + public ConfigurationReaderOptions(Serilog.Settings.Configuration.ConfigurationAssemblySource configurationAssemblySource) { } + public ConfigurationReaderOptions(params System.Reflection.Assembly[] assemblies) { } + public System.IFormatProvider FormatProvider { get; init; } + public System.Action OnLevelSwitchCreated { get; init; } + public string SectionName { get; init; } + } +} \ No newline at end of file