diff --git a/Tests/Serilog.Exceptions.Test/Destructurers/DbUpdateExceptionDestructurerTest.cs b/Tests/Serilog.Exceptions.Test/Destructurers/DbUpdateExceptionDestructurerTest.cs index c5f498ed..d96baa89 100644 --- a/Tests/Serilog.Exceptions.Test/Destructurers/DbUpdateExceptionDestructurerTest.cs +++ b/Tests/Serilog.Exceptions.Test/Destructurers/DbUpdateExceptionDestructurerTest.cs @@ -1,3 +1,5 @@ +#if NETCOREAPP +#pragma warning disable CA1307 namespace Serilog.Exceptions.Test.Destructurers; using System.IO; @@ -31,8 +33,8 @@ public void WithoutDbUpdateExceptionDestructurerShouldLogDbValues() logger.Error(new TestDbUpdateException("DbUpdate Error", entry), "Error"); var writtenJson = jsonWriter.ToString(); - Assert.True(writtenJson.Contains(TestContext.UserIdIDoNotWantToSee, StringComparison.Ordinal) || - writtenJson.Contains("\"Users\":\"threw System.TypeInitializationException", StringComparison.Ordinal)); + Assert.True(writtenJson.Contains(TestContext.UserIdIDoNotWantToSee) || + writtenJson.Contains("\"Users\":\"threw System.TypeInitializationException")); } [Fact] @@ -100,3 +102,5 @@ internal class TestDbUpdateExceptionDestructurer : DbUpdateExceptionDestructurer public override Type[] TargetTypes => [typeof(TestDbUpdateException)]; } } + +#endif diff --git a/Tests/Serilog.Exceptions.Test/Destructurers/ExceptionDestructurerTest.cs b/Tests/Serilog.Exceptions.Test/Destructurers/ExceptionDestructurerTest.cs index d56f63e4..0f468ada 100644 --- a/Tests/Serilog.Exceptions.Test/Destructurers/ExceptionDestructurerTest.cs +++ b/Tests/Serilog.Exceptions.Test/Destructurers/ExceptionDestructurerTest.cs @@ -148,6 +148,22 @@ public void WhenExceptionContainsDictionaryWithNonScalarValue_ShouldNotThrow() Assert.Equal("System.Collections.Generic.List`1[System.Int32]", property.Name); } + public class DictNonScalarKeyException : Exception + { + public DictNonScalarKeyException() => this.Reference = []; + + public DictNonScalarKeyException(string message) + : base(message) => + this.Reference = []; + + public DictNonScalarKeyException(string message, Exception innerException) + : base(message, innerException) => + this.Reference = []; + + public Dictionary, object> Reference { get; } + } + +#if NETCOREAPP [Fact] public void WhenExceptionContainsDbContext_ShouldSkipIQueryableProperties() { @@ -172,21 +188,6 @@ public void WhenExceptionContainsDbContext_ShouldSkipIQueryableProperties() Assert.Equal("IQueryable skipped", value); } - public class DictNonScalarKeyException : Exception - { - public DictNonScalarKeyException() => this.Reference = []; - - public DictNonScalarKeyException(string message) - : base(message) => - this.Reference = []; - - public DictNonScalarKeyException(string message, Exception innerException) - : base(message, innerException) => - this.Reference = []; - - public Dictionary, object> Reference { get; } - } - #pragma warning disable CS3001 // Argument type is not CLS-compliant #pragma warning disable CS3003 // Type is not CLS-compliant public class CustomDbContextException(string name, DbContext context) : @@ -212,4 +213,6 @@ public class CustomerEntity public int Id { get; set; } } } + +#endif } diff --git a/Tests/Serilog.Exceptions.Test/Destructurers/ReflectionBasedDestructurerTest.cs b/Tests/Serilog.Exceptions.Test/Destructurers/ReflectionBasedDestructurerTest.cs index 22301cd3..8ebfec33 100644 --- a/Tests/Serilog.Exceptions.Test/Destructurers/ReflectionBasedDestructurerTest.cs +++ b/Tests/Serilog.Exceptions.Test/Destructurers/ReflectionBasedDestructurerTest.cs @@ -135,7 +135,12 @@ public void CanDestructureFaultedTask() Assert.Contains("Message", taskFirstLevelExceptionDictionary.Keys); var message = Assert.IsType(taskFirstLevelExceptionDictionary["Message"]); + +#if NETCOREAPP Assert.Equal("One or more errors occurred. (INNER EXCEPTION MESSAGE)", message); +#else + Assert.Equal("One or more errors occurred.", message); +#endif Assert.Contains("InnerExceptions", taskFirstLevelExceptionDictionary.Keys); var innerExceptions = Assert.IsType>(taskFirstLevelExceptionDictionary["InnerExceptions"], exactMatch: false); diff --git a/Tests/Serilog.Exceptions.Test/Serilog.Exceptions.Test.csproj b/Tests/Serilog.Exceptions.Test/Serilog.Exceptions.Test.csproj index fd009d1d..a4a462dc 100644 --- a/Tests/Serilog.Exceptions.Test/Serilog.Exceptions.Test.csproj +++ b/Tests/Serilog.Exceptions.Test/Serilog.Exceptions.Test.csproj @@ -1,7 +1,7 @@ - net9.0;net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0;net481 $(NoWarn);CA1861;CA2007 @@ -37,4 +37,8 @@ + + + +