Skip to content

Test on net4 #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if NETCOREAPP
#pragma warning disable CA1307
namespace Serilog.Exceptions.Test.Destructurers;

using System.IO;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -100,3 +102,5 @@ internal class TestDbUpdateExceptionDestructurer : DbUpdateExceptionDestructurer
public override Type[] TargetTypes => [typeof(TestDbUpdateException)];
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEnumerable<int>, object> Reference { get; }
}

#if NETCOREAPP
[Fact]
public void WhenExceptionContainsDbContext_ShouldSkipIQueryableProperties()
{
Expand All @@ -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<IEnumerable<int>, 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) :
Expand All @@ -212,4 +213,6 @@ public class CustomerEntity
public int Id { get; set; }
}
}

#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ public void CanDestructureFaultedTask()

Assert.Contains("Message", taskFirstLevelExceptionDictionary.Keys);
var message = Assert.IsType<string>(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<IReadOnlyCollection<object>>(taskFirstLevelExceptionDictionary["InnerExceptions"], exactMatch: false);
Expand Down
6 changes: 5 additions & 1 deletion Tests/Serilog.Exceptions.Test/Serilog.Exceptions.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;net481</TargetFrameworks>
<NoWarn>$(NoWarn);CA1861;CA2007</NoWarn>
</PropertyGroup>

Expand Down Expand Up @@ -37,4 +37,8 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
Loading