Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix: update access modifiers for consistency and add AOT compatibilit…
…y attributes
  • Loading branch information
thomhurst committed Oct 5, 2025
commit 124b6a33b292d1b2831bb36fbca9e322cc60e295
4 changes: 2 additions & 2 deletions TUnit.Analyzers.CodeFixers/InheritsTestsCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace TUnit.Analyzers.CodeFixers;
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(InheritsTestsCodeFixProvider)), Shared]
public class InheritsTestsCodeFixProvider : CodeFixProvider
{
public override sealed ImmutableArray<string> FixableDiagnosticIds { get; } =
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(Rules.DoesNotInheritTestsWarning.Id);

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;

public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand Down
4 changes: 2 additions & 2 deletions TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace TUnit.Analyzers.CodeFixers;
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(XUnitMigrationCodeFixProvider)), Shared]
public class XUnitMigrationCodeFixProvider : CodeFixProvider
{
public override sealed ImmutableArray<string> FixableDiagnosticIds { get; } =
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(Rules.XunitMigration.Id);

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;

public override sealed Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Analyzers.Tests/AnalyzerTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static CSharpSuppressorTest<TSuppressor, DefaultVerifier> CreateSuppresso
}
}

file static class DiagnosticSeverityExtensions
static file class DiagnosticSeverityExtensions
{
public static ReportDiagnostic ToReportDiagnostic(this DiagnosticSeverity severity)
=> severity switch
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Analyzers/ConcurrentDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TUnit.Analyzers;

public abstract class ConcurrentDiagnosticAnalyzer : DiagnosticAnalyzer
{
public override sealed void Initialize(AnalysisContext context)
public sealed override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace TUnit.Assertions.Analyzers.CodeFixers;
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AwaitAssertionCodeFixProvider)), Shared]
public class AwaitAssertionCodeFixProvider : CodeFixProvider
{
public override sealed ImmutableArray<string> FixableDiagnosticIds { get; } =
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(Rules.AwaitAssertion.Id);

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;

public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace TUnit.Assertions.Analyzers.CodeFixers;
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(XUnitAssertionCodeFixProvider)), Shared]
public class XUnitAssertionCodeFixProvider : CodeFixProvider
{
public override sealed ImmutableArray<string> FixableDiagnosticIds { get; } =
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(Rules.XUnitAssertion.Id);

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;

public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions.Analyzers/ConcurrentDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TUnit.Assertions.Analyzers;

public abstract class ConcurrentDiagnosticAnalyzer : DiagnosticAnalyzer
{
public override sealed void Initialize(AnalysisContext context)
public sealed override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions/AssertConditions/BaseAssertCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AssertionResult FailWithMessage(string message)
/// </summary>
public virtual TimeSpan? WaitFor { get; protected set; }

internal protected abstract string GetExpectation();
protected internal abstract string GetExpectation();

internal virtual string GetExpectationWithReason()
=> $"{GetExpectation()}{GetBecauseReason()}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public AndAssertCondition(BaseAssertCondition condition1, BaseAssertCondition co


// Not used, as GetExpectationWithReason is overridden
internal protected override string GetExpectation() => "";
protected internal override string GetExpectation() => "";

internal override string GetExpectationWithReason()
=> $"{_condition1.GetExpectationWithReason()}{Environment.NewLine} and {_condition2.GetExpectationWithReason()}";

internal override sealed async ValueTask<AssertionResult> GetAssertionResult(object? actualValue, Exception? exception, AssertionMetadata assertionMetadata, string? actualExpression)
internal sealed override async ValueTask<AssertionResult> GetAssertionResult(object? actualValue, Exception? exception, AssertionMetadata assertionMetadata, string? actualExpression)
{
return (await _condition1.GetAssertionResult(actualValue, exception, assertionMetadata, actualExpression))
.And(await _condition2.GetAssertionResult(actualValue, exception, assertionMetadata, actualExpression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public OrAssertCondition(BaseAssertCondition condition1, BaseAssertCondition con
}

// Not used, as GetExpectationWithReason is overridden
internal protected override string GetExpectation() => "";
protected internal override string GetExpectation() => "";

internal override string GetExpectationWithReason()
=> $"{_condition1.GetExpectationWithReason()}{Environment.NewLine} or {_condition2.GetExpectationWithReason()}";

internal override sealed async ValueTask<AssertionResult> GetAssertionResult(object? actualValue, Exception? exception, AssertionMetadata assertionMetadata, string? actualExpression)
internal sealed override async ValueTask<AssertionResult> GetAssertionResult(object? actualValue, Exception? exception, AssertionMetadata assertionMetadata, string? actualExpression)
{
return await (await _condition1.GetAssertionResult(actualValue, exception, assertionMetadata, actualExpression))
.OrAsync(() => _condition2.GetAssertionResult(actualValue, exception, assertionMetadata, actualExpression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public abstract class ConvertToAssertCondition<TFromType, TToType> : BaseAssertC

public TToType? ConvertedValue { get; private set; }

protected override sealed async ValueTask<AssertionResult> GetResult(TFromType? actualValue, Exception? exception, AssertionMetadata assertionMetadata)
protected sealed override async ValueTask<AssertionResult> GetResult(TFromType? actualValue, Exception? exception, AssertionMetadata assertionMetadata)
{
var (result, convertedValue) = await ConvertValue(actualValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ AssertionMetadata assertionMetadata

protected virtual string GetFailureMessage(TException? exception) => "";

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
return GetFailureMessage(Exception as TException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public EnumerableSatisfiesAssertCondition(Func<TInner?, Task<TExpected>?> mapper
SetSubject(mapperExpression);
}

internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"to satisfy {_assertionBuilderExpression}";

protected override async ValueTask<AssertionResult> GetResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ExceptionMessageContainingExpectedValueAssertCondition<TException>(
: ExpectedValueAssertCondition<TException, string>(expected)
where TException : Exception
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"message to contain {Formatter.Format(ExpectedValue).TruncateWithEllipsis(100)}";

protected override ValueTask<AssertionResult> GetResult(TException? actualValue, string? expectedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ExceptionMessageEndingWithExpectedValueAssertCondition<TException>(
: ExpectedValueAssertCondition<TException, string>(expected)
where TException : Exception
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"message to end with {Formatter.Format(ExpectedValue).TruncateWithEllipsis(100)}";

protected override ValueTask<AssertionResult> GetResult(TException? actualValue, string? expectedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ExceptionMessageEqualsExpectedValueAssertCondition<TException>(stri
: ExpectedValueAssertCondition<TException, string>(expected)
where TException : Exception
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"message to be equal to {Formatter.Format(expected).TruncateWithEllipsis(100)}";

protected override ValueTask<AssertionResult> GetResult(TException? actualValue, string? expectedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ExceptionMessageMatchingExpectedAssertCondition<TException>(StringM
: ExpectedValueAssertCondition<TException, StringMatcher>(match)
where TException : Exception
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"message to match {Formatter.Format(ExpectedValue).TruncateWithEllipsis(100)}";

protected override ValueTask<AssertionResult> GetResult(TException? actualValue, StringMatcher? expectedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ExceptionMessageStartingWithExpectedValueAssertCondition<TException
: ExpectedValueAssertCondition<TException, string>(expected)
where TException : Exception
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"message to start with {Formatter.Format(ExpectedValue).TruncateWithEllipsis(100)}";

protected override ValueTask<AssertionResult> GetResult(TException? actualValue, string? expectedValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace TUnit.Assertions.AssertConditions;

public abstract class ExpectedValueAssertCondition<TActual, TExpected>(TExpected? expected) : BaseAssertCondition<TActual>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ string expectation
)
: ExpectedValueAssertCondition<TActual, TExpected>(expected)
{
internal protected override string GetExpectation() => expectation;
protected internal override string GetExpectation() => expectation;

protected override ValueTask<AssertionResult> GetResult(TActual? actualValue, TExpected? expectedValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace TUnit.Assertions.AssertConditions;

public class NotNullExpectedValueAssertCondition<TActual> : ConvertToAssertCondition<TActual?, TActual> where TActual : class?
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> "to not be null";

public override ValueTask<(AssertionResult, TActual?)> ConvertValue(TActual? value)
Expand All @@ -19,7 +19,7 @@ internal protected override string GetExpectation()

public class NotNullStructExpectedValueAssertCondition<TActual> : ConvertToAssertCondition<TActual?, TActual> where TActual : struct
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> "to not be null";

public override ValueTask<(AssertionResult, TActual)> ConvertValue(TActual? value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace TUnit.Assertions.AssertConditions;

public class NullExpectedValueAssertCondition<TActual> : BaseAssertCondition<TActual>
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> "to be null";

protected override ValueTask<AssertionResult> GetResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SatisfiesAssertCondition(Func<TActual, Task<TExpected>?> mapper,
SetSubject(mapperExpression);
}

internal protected override string GetExpectation()
protected internal override string GetExpectation()
=> $"to satisfy {_assertionBuilderExpression}";

protected override async ValueTask<AssertionResult> GetResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override ValueTask<AssertionResult> GetResult(T? actualValue, Exceptio
$"'{actualValue}' was expected {expectationVerb} {_methodName}()");
}

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
var expectationVerb = _negated ? "not to satisfy" : "to satisfy";
return $"{expectationVerb} {_methodName}()";
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions/AssertConditions/ValueAssertCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ AssertionMetadata assertionMetadata

protected abstract string GetFailureMessage(TActual? actualValue);

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
return GetFailureMessage(ActualValue);
}
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions/AssertionBuilders/AssertionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal AssertionBuilder AppendConnector(ChainType chainType)
return (AssertionBuilder) ((ISource) this).AppendExpression(chainType.ToString());
}

internal protected void AppendCallerMethod(string?[] expressions, [CallerMemberName] string methodName = "")
protected internal void AppendCallerMethod(string?[] expressions, [CallerMemberName] string methodName = "")
{
if (string.IsNullOrEmpty(methodName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ string IInvokableAssertionBuilder.GetExpression()
return $"{expression[..100]}...";
}

internal protected Stack<BaseAssertCondition> Assertions => Source.Assertions;
protected internal Stack<BaseAssertCondition> Assertions => Source.Assertions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class DateOnlyEqualsExpectedValueAssertCondition(DateOnly expected) : Exp
{
private int? _tolerance;

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
if (_tolerance is null or 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class DateTimeEqualsExpectedValueAssertCondition(DateTime expected) : Exp
{
private TimeSpan? _tolerance;

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
if (_tolerance == null || _tolerance == TimeSpan.Zero)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class DateTimeOffsetEqualsExpectedValueAssertCondition(DateTimeOffset exp
{
private TimeSpan? _tolerance;

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
if (_tolerance == null || _tolerance == TimeSpan.Zero)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class TimeOnlyEqualsExpectedValueAssertCondition(TimeOnly expected) : Exp
{
private TimeSpan? _tolerance;

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
if (_tolerance == null || _tolerance == TimeSpan.Zero)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class TimeSpanEqualsExpectedValueAssertCondition(TimeSpan expected) : Exp
{
private TimeSpan? _tolerance;

internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
if (_tolerance == null || _tolerance == TimeSpan.Zero)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ namespace TUnit.Assertions.AssertConditions.ClassMember;
public class PropertyEqualsExpectedValueAssertCondition<TRootObjectType, TPropertyType>(Expression<Func<TRootObjectType, TPropertyType>> propertySelector, TPropertyType expected, bool isEqual)
: ExpectedValueAssertCondition<TRootObjectType, TPropertyType>(expected)
{
internal protected override string GetExpectation()
protected internal override string GetExpectation()
{
return $"{typeof(TRootObjectType).Name}.{ExpressionHelpers.GetName(propertySelector)} to be equal to {ExpectedValue}";
}

[RequiresUnreferencedCode("Expression compilation requires unreferenced code")]
[RequiresDynamicCode("Expression compilation requires dynamic code generation")]
protected override ValueTask<AssertionResult> GetResult(TRootObjectType? actualValue, TPropertyType? expectedValue)
{
var propertyValue = GetPropertyValue(actualValue);
Expand All @@ -24,11 +22,7 @@ protected override ValueTask<AssertionResult> GetResult(TRootObjectType? actualV
$"received {GetPropertyValue(actualValue)?.ToString()}"
);
}
#pragma warning restore IL3051
#pragma warning restore IL2046

[RequiresUnreferencedCode("Expression compilation requires unreferenced code")]
[RequiresDynamicCode("Expression compilation requires dynamic code generation")]
private object? GetPropertyValue(TRootObjectType? actualValue)
{
if (actualValue is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class EnumerableAllExpectedFuncAssertCondition<TActual, TInner>(
: BaseAssertCondition<TActual>
where TActual : IEnumerable<TInner>
{
internal protected override string GetExpectation() => $"to contain only entries matching {matcherString ?? "null"}";
protected internal override string GetExpectation() => $"to contain only entries matching {matcherString ?? "null"}";

protected override ValueTask<AssertionResult> GetResult(
TActual? actualValue, Exception? exception,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class EnumerableContainsExpectedFuncAssertCondition<TActual, TInner>(
where TActual : IEnumerable<TInner>
{
private bool _wasFound;
internal protected override string GetExpectation() => $"to contain an entry matching {matcherString ?? "null"}";
protected internal override string GetExpectation() => $"to contain an entry matching {matcherString ?? "null"}";

protected override ValueTask<AssertionResult> GetResult(
TActual? actualValue, Exception? exception,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class EnumerableContainsExpectedValueAssertCondition<TActual, TInner>(
: ExpectedValueAssertCondition<TActual, TInner>(expected)
where TActual : IEnumerable<TInner>
{
internal protected override string GetExpectation() => $"to contain {ExpectedValue}";
protected internal override string GetExpectation() => $"to contain {ExpectedValue}";

protected override ValueTask<AssertionResult> GetResult(TActual? actualValue, TInner? inner)
=> AssertionResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TUnit.Assertions.AssertConditions.Collections;
public class EnumerableCountEqualToExpectedValueAssertCondition<TActual, TInner>(int expected)
: ExpectedValueAssertCondition<TActual, int>(expected) where TActual : IEnumerable<TInner>
{
internal protected override string GetExpectation() => $"to have a count of {ExpectedValue}";
protected internal override string GetExpectation() => $"to have a count of {ExpectedValue}";

protected override ValueTask<AssertionResult> GetResult(TActual? actualValue, int count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TUnit.Assertions.AssertConditions.Collections;
public class EnumerableCountNotEqualToExpectedValueAssertCondition<TActual, TInner>(int expected)
: ExpectedValueAssertCondition<TActual, int>(expected) where TActual : IEnumerable<TInner>
{
internal protected override string GetExpectation() => $"to have a count different to {ExpectedValue}";
protected internal override string GetExpectation() => $"to have a count different to {ExpectedValue}";

protected override ValueTask<AssertionResult> GetResult(TActual? actualValue, int count)
{
Expand Down
Loading
Loading