Skip to content
Merged
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
Expand Up @@ -24,7 +24,7 @@
public const string BuildAssertionGroup = "MethodAssertionGroup";

private static readonly DiagnosticDescriptor MethodMustBeStaticRule = new DiagnosticDescriptor(
id: GeneratorDiagnosticIds.AssertionMethodMustBeStatic,

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 27 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN006' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
title: "Method must be static",
messageFormat: "Method '{0}' decorated with [GenerateAssertion] must be static",
category: "TUnit.Assertions.SourceGenerator",
Expand All @@ -33,7 +33,7 @@
description: "Methods decorated with [GenerateAssertion] must be static to be used in generated assertions.");

private static readonly DiagnosticDescriptor MethodMustHaveParametersRule = new DiagnosticDescriptor(
id: GeneratorDiagnosticIds.AssertionMethodMustHaveParameters,

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 36 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN007' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
title: "Method must have at least one parameter",
messageFormat: "Method '{0}' decorated with [GenerateAssertion] must have at least one parameter (the value to assert)",
category: "TUnit.Assertions.SourceGenerator",
Expand All @@ -42,18 +42,18 @@
description: "Methods decorated with [GenerateAssertion] must have at least one parameter representing the value being asserted.");

private static readonly DiagnosticDescriptor UnsupportedReturnTypeRule = new DiagnosticDescriptor(
id: GeneratorDiagnosticIds.AssertionUnsupportedReturnType,

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 45 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN008' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
title: "Unsupported return type",
messageFormat: "Method '{0}' decorated with [GenerateAssertion] has unsupported return type '{1}'. Supported types are: bool, AssertionResult, AssertionResult<T>, Task<bool>, Task<AssertionResult>, Task<AssertionResult<T>>",

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 47 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period
category: "TUnit.Assertions.SourceGenerator",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Methods decorated with [GenerateAssertion] must return bool, AssertionResult, Task<bool>, or Task<AssertionResult>.");

private static readonly DiagnosticDescriptor RefStructRequiresInliningRule = new DiagnosticDescriptor(
id: GeneratorDiagnosticIds.RefStructRequiresInlining,

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 54 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

Enable analyzer release tracking for the analyzer project containing rule 'TUNITGEN004' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
title: "Ref struct parameter requires method body inlining",
messageFormat: "Method '{0}' has ref struct parameter '{1}' of type '{2}'. Use InlineMethodBody = true and ensure the method has a single-expression or single-return-statement body",

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period

Check warning on line 56 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period
category: "TUnit.Assertions.SourceGenerator",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
Expand Down Expand Up @@ -572,7 +572,7 @@
innerNamed.TypeArguments.Length == 1)
{
var resultType = innerNamed.TypeArguments[0].ToDisplayString();
return new ReturnTypeInfo(ReturnTypeKind.TaskAssertionResultOfT, resultType);
return new ReturnTypeInfo(ReturnTypeKind.TaskAssertionResultOfT, resultType, innerNamed.TypeArguments[0].IsValueType);
}
}
}
Expand All @@ -583,7 +583,7 @@
namedType.TypeArguments.Length == 1)
{
var resultType = namedType.TypeArguments[0].ToDisplayString();
return new ReturnTypeInfo(ReturnTypeKind.AssertionResultOfT, resultType);
return new ReturnTypeInfo(ReturnTypeKind.AssertionResultOfT, resultType, namedType.TypeArguments[0].IsValueType);
}

// AssertionResult (non-generic)
Expand Down Expand Up @@ -731,7 +731,9 @@
if (isTerminal)
{
var resultType = data.ReturnTypeInfo.ResultTypeFullName!;
sb.AppendLine($" private {resultType}? _result;");
// A value type keeps its own type: T? on a value type is Nullable<T>, which the awaiter cannot return as T.
var nullableMarker = data.ReturnTypeInfo.ResultIsValueType ? "" : "?";
sb.AppendLine($" private {resultType}{nullableMarker} _result;");
}

if (data.AdditionalParameters.Count > 0 || isTerminal)
Expand Down Expand Up @@ -987,7 +989,7 @@
// Add null-forgiving operator for reference types if not already present
// This is safe because we've already checked for null above
var isNullable = data.TargetType.IsNullable;
if (isNullable && !string.IsNullOrEmpty(inlinedBody) && !inlinedBody.StartsWith("value!", StringComparison.Ordinal))

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / nuget-package-tests-windows

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / mock AOT

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (sv-SE)

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / AOT (windows-latest)

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / AOT (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Engine tests (windows-latest)

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Apple smoke tests

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Android smoke test

Dereference of a possibly null reference.

Check warning on line 992 in src/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs

View workflow job for this annotation

GitHub Actions / Browser smoke test

Dereference of a possibly null reference.
{
// Replace null-conditional operators with null-forgiving + regular operators
// value?.Member becomes value!.Member (safe because we already null-checked)
Expand Down Expand Up @@ -1406,7 +1408,7 @@
TaskAssertionResultOfT
}

private readonly record struct ReturnTypeInfo(ReturnTypeKind Kind, string? ResultTypeFullName = null);
private readonly record struct ReturnTypeInfo(ReturnTypeKind Kind, string? ResultTypeFullName = null, bool ResultIsValueType = false);

private record AssertionMethodData(
MethodData Method,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
[
// <auto-generated/>
#pragma warning disable
#nullable enable

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using TUnit.Assertions.Core;
using TUnit.Assertions.Tests.TestData;

namespace TUnit.Assertions.Extensions;

/// <summary>
/// Generated assertion for ParsesAsInt
/// </summary>
public sealed class String_ParsesAsInt_Assertion : Assertion<string>
{
private int _result;

public String_ParsesAsInt_Assertion(AssertionContext<string> context)
: base(context)
{
}

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<string> metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;

if (exception != null)
{
return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().FullName}"));
}

if (value is null)
{
return Task.FromResult(AssertionResult.Failed("Actual value is null"));
}

var typedResult = value!.ParsesAsInt();
if (typedResult.IsPassed)
{
_result = typedResult.Value;
}
return Task.FromResult(typedResult.IsPassed
? AssertionResult.Passed
: AssertionResult.Failed(typedResult.Message));
}

protected override string GetExpectation()
{
return "to parse as an integer";
}

/// <summary>
/// Adds a custom message explaining why this assertion should pass.
/// Awaiting it still returns the result value.
/// </summary>
public new String_ParsesAsInt_Assertion Because(string message)
{
base.Because(message);
return this;
}

public new System.Runtime.CompilerServices.TaskAwaiter<int> GetAwaiter()
{
return ExecuteAndReturnResultAsync().GetAwaiter();
}

private async Task<int> ExecuteAndReturnResultAsync()
{
await AssertAsync();
return _result!;
}
}

/// <summary>
/// Generated assertion for ParsesAsIntAsync
/// </summary>
public sealed class String_ParsesAsIntAsync_Assertion : Assertion<string>
{
private int _result;

public String_ParsesAsIntAsync_Assertion(AssertionContext<string> context)
: base(context)
{
}

protected override async Task<AssertionResult> CheckAsync(EvaluationMetadata<string> metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;

if (exception != null)
{
return AssertionResult.Failed($"threw {exception.GetType().FullName}");
}

if (value is null)
{
return AssertionResult.Failed("Actual value is null");
}

var typedResult = await value!.ParsesAsIntAsync();
if (typedResult.IsPassed)
{
_result = typedResult.Value;
}
return typedResult.IsPassed
? AssertionResult.Passed
: AssertionResult.Failed(typedResult.Message);
}

protected override string GetExpectation()
{
return "to parse as an integer";
}

/// <summary>
/// Adds a custom message explaining why this assertion should pass.
/// Awaiting it still returns the result value.
/// </summary>
public new String_ParsesAsIntAsync_Assertion Because(string message)
{
base.Because(message);
return this;
}

public new System.Runtime.CompilerServices.TaskAwaiter<int> GetAwaiter()
{
return ExecuteAndReturnResultAsync().GetAwaiter();
}

private async Task<int> ExecuteAndReturnResultAsync()
{
await AssertAsync();
return _result!;
}
}

/// <summary>
/// Generated assertion for MaybeLength
/// </summary>
public sealed class String_MaybeLength_Assertion : Assertion<string>
{
private int? _result;

public String_MaybeLength_Assertion(AssertionContext<string> context)
: base(context)
{
}

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<string> metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;

if (exception != null)
{
return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().FullName}"));
}

if (value is null)
{
return Task.FromResult(AssertionResult.Failed("Actual value is null"));
}

var typedResult = value!.MaybeLength();
if (typedResult.IsPassed)
{
_result = typedResult.Value;
}
return Task.FromResult(typedResult.IsPassed
? AssertionResult.Passed
: AssertionResult.Failed(typedResult.Message));
}

protected override string GetExpectation()
{
return "to have a length";
}

/// <summary>
/// Adds a custom message explaining why this assertion should pass.
/// Awaiting it still returns the result value.
/// </summary>
public new String_MaybeLength_Assertion Because(string message)
{
base.Because(message);
return this;
}

public new System.Runtime.CompilerServices.TaskAwaiter<int?> GetAwaiter()
{
return ExecuteAndReturnResultAsync().GetAwaiter();
}

private async Task<int?> ExecuteAndReturnResultAsync()
{
await AssertAsync();
return _result!;
}
}

/// <summary>
/// Generated assertion for IsPositiveValue
/// </summary>
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2091", Justification = "Generic type parameter is only used for property access, not instantiation")]
public sealed class T_IsPositiveValue_Assertion<T> : Assertion<T>
where T : struct, System.IComparable<T>
{
private T _result;

public T_IsPositiveValue_Assertion(AssertionContext<T> context)
: base(context)
{
}

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<T> metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;

if (exception != null)
{
return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().FullName}"));
}

var typedResult = value!.IsPositiveValue<T>();
if (typedResult.IsPassed)
{
_result = typedResult.Value;
}
return Task.FromResult(typedResult.IsPassed
? AssertionResult.Passed
: AssertionResult.Failed(typedResult.Message));
}

protected override string GetExpectation()
{
return "to be positive";
}

/// <summary>
/// Adds a custom message explaining why this assertion should pass.
/// Awaiting it still returns the result value.
/// </summary>
public new T_IsPositiveValue_Assertion<T> Because(string message)
{
base.Because(message);
return this;
}

public new System.Runtime.CompilerServices.TaskAwaiter<T> GetAwaiter()
{
return ExecuteAndReturnResultAsync().GetAwaiter();
}

private async Task<T> ExecuteAndReturnResultAsync()
{
await AssertAsync();
return _result!;
}
}

public static partial class AssertionResultOfValueTypeExtensions
{
/// <summary>
/// Generated extension method for ParsesAsInt
/// </summary>
public static String_ParsesAsInt_Assertion ParsesAsInt(this IAssertionSource<string> source)
{
source.Context.ExpressionBuilder.Append(".ParsesAsInt()");
return new String_ParsesAsInt_Assertion(source.Context);
}

/// <summary>
/// Generated extension method for ParsesAsIntAsync
/// </summary>
public static String_ParsesAsIntAsync_Assertion ParsesAsIntAsync(this IAssertionSource<string> source)
{
source.Context.ExpressionBuilder.Append(".ParsesAsIntAsync()");
return new String_ParsesAsIntAsync_Assertion(source.Context);
}

/// <summary>
/// Generated extension method for MaybeLength
/// </summary>
public static String_MaybeLength_Assertion MaybeLength(this IAssertionSource<string> source)
{
source.Context.ExpressionBuilder.Append(".MaybeLength()");
return new String_MaybeLength_Assertion(source.Context);
}

/// <summary>
/// Generated extension method for IsPositiveValue
/// </summary>
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2091", Justification = "Generic type parameter is only used for property access, not instantiation")]
public static T_IsPositiveValue_Assertion<T> IsPositiveValue<T>(this IAssertionSource<T> source)
where T : struct, System.IComparable<T>
{
source.Context.ExpressionBuilder.Append(".IsPositiveValue()");
return new T_IsPositiveValue_Assertion<T>(source.Context);
}

}

]
Loading
Loading