-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Destructurama.Attributed.Tests/Approval/ApiApprovalTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using NUnit.Framework; | ||
using PublicApiGenerator; | ||
using Shouldly; | ||
|
||
namespace Destructurama.Attributed.Tests; | ||
|
||
/// <summary>Tests for checking changes to the public API.</summary> | ||
[TestFixture] | ||
public class ApiApprovalTests | ||
{ | ||
/// <summary>Check for changes to the public APIs.</summary> | ||
/// <param name="type">The type used as a marker for the assembly whose public API change you want to check.</param> | ||
[TestCase(typeof(LoggerConfigurationAppSettingsExtensions))] | ||
public void PublicApi_Should_Not_Change_Unintentionally(Type type) | ||
{ | ||
string publicApi = type.Assembly.GeneratePublicApi(new() | ||
{ | ||
IncludeAssemblyAttributes = false, | ||
AllowNamespacePrefixes = ["System", "Microsoft.Extensions.DependencyInjection"], | ||
ExcludeAttributes = ["System.Diagnostics.DebuggerDisplayAttribute"], | ||
}); | ||
|
||
publicApi.ShouldMatchApproved(options => options.NoDiff().WithFilenameGenerator((testMethodInfo, discriminator, fileType, fileExtension) => $"{type.Assembly.GetName().Name!}.{fileType}.{fileExtension}")); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/Destructurama.Attributed.Tests/Approval/Destructurama.Attributed.approved.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace Destructurama.Attributed | ||
{ | ||
public class AttributedDestructuringPolicyOptions | ||
{ | ||
public AttributedDestructuringPolicyOptions() { } | ||
public bool IgnoreNullProperties { get; set; } | ||
} | ||
public interface IPropertyDestructuringAttribute | ||
{ | ||
bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out Serilog.Events.LogEventProperty? property); | ||
} | ||
public interface IPropertyOptionalIgnoreAttribute | ||
{ | ||
bool ShouldPropertyBeIgnored(string name, object? value, System.Type type); | ||
} | ||
public interface ITypeDestructuringAttribute | ||
{ | ||
Serilog.Events.LogEventPropertyValue CreateLogEventPropertyValue(object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory); | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Property)] | ||
public class LogAsScalarAttribute : System.Attribute, Destructurama.Attributed.IPropertyDestructuringAttribute, Destructurama.Attributed.ITypeDestructuringAttribute | ||
{ | ||
public LogAsScalarAttribute(bool isMutable = false) { } | ||
public Serilog.Events.LogEventPropertyValue CreateLogEventPropertyValue(object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory) { } | ||
public bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, out Serilog.Events.LogEventProperty property) { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class LogMaskedAttribute : System.Attribute, Destructurama.Attributed.IPropertyDestructuringAttribute | ||
{ | ||
public LogMaskedAttribute() { } | ||
public bool PreserveLength { get; set; } | ||
public int ShowFirst { get; set; } | ||
public int ShowLast { get; set; } | ||
public string Text { get; set; } | ||
public bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, out Serilog.Events.LogEventProperty property) { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class LogReplacedAttribute : System.Attribute, Destructurama.Attributed.IPropertyDestructuringAttribute | ||
{ | ||
public LogReplacedAttribute(string pattern, string replacement) { } | ||
public System.Text.RegularExpressions.RegexOptions Options { get; set; } | ||
public System.TimeSpan Timeout { get; set; } | ||
public bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out Serilog.Events.LogEventProperty? property) { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class LogWithNameAttribute : System.Attribute, Destructurama.Attributed.IPropertyDestructuringAttribute | ||
{ | ||
public LogWithNameAttribute(string newName) { } | ||
public bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out Serilog.Events.LogEventProperty? property) { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class NotLoggedAttribute : System.Attribute, Destructurama.Attributed.IPropertyDestructuringAttribute | ||
{ | ||
public NotLoggedAttribute() { } | ||
public bool TryCreateLogEventProperty(string name, object? value, Serilog.Core.ILogEventPropertyValueFactory propertyValueFactory, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out Serilog.Events.LogEventProperty? property) { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class NotLoggedIfDefaultAttribute : System.Attribute, Destructurama.Attributed.IPropertyOptionalIgnoreAttribute | ||
{ | ||
public NotLoggedIfDefaultAttribute() { } | ||
} | ||
[System.AttributeUsage(System.AttributeTargets.Property)] | ||
public class NotLoggedIfNullAttribute : System.Attribute, Destructurama.Attributed.IPropertyOptionalIgnoreAttribute | ||
{ | ||
public NotLoggedIfNullAttribute() { } | ||
} | ||
} | ||
namespace Destructurama | ||
{ | ||
public static class LoggerConfigurationAppSettingsExtensions | ||
{ | ||
public static Serilog.LoggerConfiguration UsingAttributes(this Serilog.Configuration.LoggerDestructuringConfiguration configuration) { } | ||
public static Serilog.LoggerConfiguration UsingAttributes(this Serilog.Configuration.LoggerDestructuringConfiguration configuration, System.Action<Destructurama.Attributed.AttributedDestructuringPolicyOptions> configure) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters