From 85ab210a854986e906233d3bd8aab737abd9162f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Feb 2025 15:37:08 +1100 Subject: [PATCH] test on net4 --- .../DbUpdateExceptionDestructurerTest.cs | 8 +++-- .../ExceptionDestructurerTest.cs | 33 ++++++++++--------- .../ReflectionBasedDestructurerTest.cs | 5 +++ .../Serilog.Exceptions.Test.csproj | 6 +++- 4 files changed, 34 insertions(+), 18 deletions(-) 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 db92a7e5..745315e0 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.IsAssignableFrom>(taskFirstLevelExceptionDictionary["InnerExceptions"]); 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 @@ + + + +