Skip to content
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

Warning xUnit2020 : Do not use Assert.True(false, message) #869

Merged
Merged
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
@@ -81,7 +81,7 @@ public async Task CanDestructureTaskAsync()
try
{
await Task.Delay(1000, cancellationTokenSource.Token);
Assert.True(false, "TaskCanceledException was not thrown.");
Assert.Fail("TaskCanceledException was not thrown.");
return;
}
catch (TaskCanceledException taskCancelledException)
@@ -438,7 +438,7 @@ private static Exception ThrowAndCatchException(Action throwingAction)
return ex;
}

Assert.True(false, $"{nameof(throwingAction)} did not throw");
Assert.Fail($"{nameof(throwingAction)} did not throw");
return null!; // We should never reach this line.
}


Unchanged files with check annotations Beta

nameof(Exception.StackTrace));
#endif
private readonly List<IExceptionDestructurer> destructurers = new();

Check warning on line 44 in Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

GitHub Actions / Build-ubuntu-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 44 in Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

GitHub Actions / Build-ubuntu-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 44 in Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 44 in Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 44 in Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

GitHub Actions / Build-macOS-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)
/// <summary>
/// Gets the name of the property which value will be filled with destructured exception.
private const int AcceptableNumberOfSameNameProperties = 5;
private readonly Exception exception;
private readonly IExceptionPropertyFilter? filter;
private readonly Dictionary<string, object?> properties = new();

Check warning on line 17 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-ubuntu-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 17 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 17 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 17 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-macOS-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)
/// <summary>
/// We keep a note on whether the results were collected to be sure that after that there are no changes. This
/// </summary>
/// <param name="exception">The exception which properties will be added to the bag.</param>
/// <param name="filter">Filter that should be applied to each property just before adding it to the bag.</param>
public ExceptionPropertiesBag(Exception exception, IExceptionPropertyFilter? filter = null)

Check warning on line 30 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-windows-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)

Check warning on line 30 in Source/Serilog.Exceptions/Core/ExceptionPropertiesBag.cs

GitHub Actions / Build-macOS-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)
{
this.exception = exception ?? throw new ArgumentNullException(nameof(exception));
this.filter = filter;
/// <param name="name">The of the property without type name.</param>
/// <param name="declaringType">The type which declares the property.</param>
/// <param name="getter">Runtime function that can extract value of the property from object.</param>
public ReflectionPropertyInfo(string name, Type? declaringType, Func<object, object> getter)

Check warning on line 20 in Source/Serilog.Exceptions/Reflection/ReflectionPropertyInfo.cs

GitHub Actions / Build-ubuntu-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)

Check warning on line 20 in Source/Serilog.Exceptions/Reflection/ReflectionPropertyInfo.cs

GitHub Actions / Build-macOS-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)
{
this.Name = name;
this.DeclaringType = declaringType;
/// </summary>
/// <param name="properties">All properties for a type.</param>
/// <param name="propertiesExceptBaseOnes">All properties except of <see cref="Exception"/> properties which are handled separately.</param>
public ReflectionInfo(

Check warning on line 14 in Source/Serilog.Exceptions/Reflection/ReflectionInfo.cs

GitHub Actions / Build-ubuntu-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)

Check warning on line 14 in Source/Serilog.Exceptions/Reflection/ReflectionInfo.cs

GitHub Actions / Build-macOS-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)
ReflectionPropertyInfo[] properties,
ReflectionPropertyInfo[] propertiesExceptBaseOnes)
{
/// Initializes a new instance of the <see cref="IgnorePropertyByNameExceptionFilter"/> class.
/// </summary>
/// <param name="propertiesToIgnore">The properties to ignore.</param>
public IgnorePropertyByNameExceptionFilter(params string[] propertiesToIgnore) =>

Check warning on line 20 in Source/Serilog.Exceptions/Filters/IgnorePropertyByNameExceptionFilter.cs

GitHub Actions / Build-ubuntu-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)

Check warning on line 20 in Source/Serilog.Exceptions/Filters/IgnorePropertyByNameExceptionFilter.cs

GitHub Actions / Build-macOS-latest

Use primary constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290)
this.propertiesToIgnore = propertiesToIgnore;
/// <inheritdoc />
public class SocketExceptionDestructurer : ExceptionDestructurer
{
// obtained from https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socketerror
private static readonly IReadOnlyDictionary<SocketError, string> SocketErrorDocumentationBySocketError =

Check warning on line 12 in Source/Serilog.Exceptions/Destructurers/SocketExceptionDestructurer.cs

GitHub Actions / Build-ubuntu-latest

Change type of field 'SocketErrorDocumentationBySocketError' from 'System.Collections.Generic.IReadOnlyDictionary<System.Net.Sockets.SocketError, string>' to 'System.Collections.Generic.Dictionary<System.Net.Sockets.SocketError, string>' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)

Check warning on line 12 in Source/Serilog.Exceptions/Destructurers/SocketExceptionDestructurer.cs

GitHub Actions / Build-windows-latest

Change type of field 'SocketErrorDocumentationBySocketError' from 'System.Collections.Generic.IReadOnlyDictionary<System.Net.Sockets.SocketError, string>' to 'System.Collections.Generic.Dictionary<System.Net.Sockets.SocketError, string>' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)

Check warning on line 12 in Source/Serilog.Exceptions/Destructurers/SocketExceptionDestructurer.cs

GitHub Actions / Build-macOS-latest

Change type of field 'SocketErrorDocumentationBySocketError' from 'System.Collections.Generic.IReadOnlyDictionary<System.Net.Sockets.SocketError, string>' to 'System.Collections.Generic.Dictionary<System.Net.Sockets.SocketError, string>' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
new Dictionary<SocketError, string>
{
{ SocketError.AccessDenied, "An attempt was made to access a Socket in a way that is forbidden by its access permissions." },
return refId;
}
private static object DestructureUri(Uri value) => value.ToString();

Check warning on line 116 in Source/Serilog.Exceptions/Destructurers/ReflectionBasedDestructurer.cs

GitHub Actions / Build-ubuntu-latest

Change return type of method 'DestructureUri' from 'object' to 'string' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
private static void AppendTypeIfPossible(IExceptionPropertiesBag propertiesBag, Type valueType)
{
return resultList;
}
private object DestructureValueDictionary(

Check warning on line 263 in Source/Serilog.Exceptions/Destructurers/ReflectionBasedDestructurer.cs

GitHub Actions / Build-ubuntu-latest

Change return type of method 'DestructureValueDictionary' from 'object' to 'System.Collections.Generic.Dictionary<string, object?>' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
IDictionary value,
int level,
IDictionary<object, IDictionary<string, object?>> destructuredObjects,
return destructuredDictionary;
}
private IDictionary<string, object?> DestructureObject(

Check warning on line 291 in Source/Serilog.Exceptions/Destructurers/ReflectionBasedDestructurer.cs

GitHub Actions / Build-ubuntu-latest

Change return type of method 'DestructureObject' from 'System.Collections.Generic.IDictionary<string, object?>' to 'System.Collections.Generic.Dictionary<string, object?>' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
object value,
Type valueType,
int level,
};
#pragma warning restore IDE0001 // Simplify Names
return targetTypes.ToArray();

Check warning on line 163 in Source/Serilog.Exceptions/Destructurers/ExceptionDestructurer.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0305)

Check warning on line 163 in Source/Serilog.Exceptions/Destructurers/ExceptionDestructurer.cs

GitHub Actions / Build-macOS-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0305)
}
}
/// </summary>
public sealed class ExceptionEnricher : ILogEventEnricher
{
private readonly IExceptionDestructurer reflectionBasedDestructurer;

Check warning on line 12 in Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

GitHub Actions / Build-windows-latest

Change type of field 'reflectionBasedDestructurer' from 'Serilog.Exceptions.Destructurers.IExceptionDestructurer' to 'Serilog.Exceptions.Destructurers.ReflectionBasedDestructurer' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)

Check warning on line 12 in Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

GitHub Actions / Build-macOS-latest

Change type of field 'reflectionBasedDestructurer' from 'Serilog.Exceptions.Destructurers.IExceptionDestructurer' to 'Serilog.Exceptions.Destructurers.ReflectionBasedDestructurer' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
private readonly Dictionary<Type, IExceptionDestructurer> destructurers;
private readonly IDestructuringOptions destructuringOptions;
this.destructuringOptions = destructuringOptions ?? throw new ArgumentNullException(nameof(destructuringOptions));
this.reflectionBasedDestructurer = new ReflectionBasedDestructurer(destructuringOptions.DestructuringDepth);
this.destructurers = new Dictionary<Type, IExceptionDestructurer>();

Check warning on line 33 in Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 33 in Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

GitHub Actions / Build-windows-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 33 in Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

GitHub Actions / Build-macOS-latest

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)
foreach (var destructurer in this.destructuringOptions.Destructurers)
{
foreach (var targetType in destructurer.TargetTypes)