Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b9dd82d
+semver:minor - refactor(assertions): enhance collection assertion ty…
thomhurst Oct 16, 2025
605c4e6
Merge branch 'main' into bug/3401
thomhurst Oct 16, 2025
4618371
refactor(assertions): implement ComparerBasedAssertion and ToleranceB…
thomhurst Oct 16, 2025
2913390
refactor(assertions): simplify assertion linking and enhance type saf…
thomhurst Oct 16, 2025
47d3282
refactor(assertions): introduce ICollectionAssertionSource for enhanc…
thomhurst Oct 16, 2025
d1bf905
refactor(assertions): introduce ContinuationBase for common logic in …
thomhurst Oct 17, 2025
6a791d9
Merge branch 'main' into bug/3401
thomhurst Oct 17, 2025
0c30e20
feat(assertions): introduce dictionary assertions with And/Or chainin…
thomhurst Oct 17, 2025
a6cb4b3
Merge branch 'main' into bug/3401
thomhurst Oct 17, 2025
ca06375
refactor(assertions): enhance collection assertion classes for better…
thomhurst Oct 17, 2025
698e264
Merge branch 'main' into bug/3401
thomhurst Oct 17, 2025
24c081c
feat(assertions): add collection assertion methods for improved type …
thomhurst Oct 17, 2025
0653ee6
Merge branch 'main' into bug/3401
thomhurst Oct 18, 2025
5ed43c1
fix(assertions): update assertions to use IsNotEmpty and HasCount for…
thomhurst Oct 18, 2025
0f7c3a5
fix(assertions): streamline HasCount assertions for clarity and consi…
thomhurst Oct 18, 2025
6dce633
fix(tests): improve assertions in DictionaryCollectionTests for clari…
thomhurst Oct 18, 2025
24b4f52
fix(tests): add assertions for CustomCollection and enhance collectio…
thomhurst Oct 18, 2025
43986aa
fix(assertions): simplify collection assertions to single type parame…
thomhurst Oct 20, 2025
cfd219a
feat(assertions): add HasCount method for fluent count assertions on …
thomhurst Oct 20, 2025
4452dbb
feat(assertions): add MapAsync method for asynchronous value transfor…
thomhurst Oct 20, 2025
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
4 changes: 2 additions & 2 deletions SourceGenerationDebug.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<!-- <PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>SourceGeneratedViewer</CompilerGeneratedFilesOutputPath>
</PropertyGroup> -->
</PropertyGroup>

<ItemGroup>
<Compile Remove="SourceGeneratedViewer\**" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ public static partial class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{
private static ReferenceAssemblies GetReferenceAssemblies()
{
#if NET472
return ReferenceAssemblies.NetFramework.Net472.Default;
#elif NET8_0
return ReferenceAssemblies.Net.Net80;
#elif NET9_0 || NET10_0_OR_GREATER
return ReferenceAssemblies.Net.Net90;
#else
return ReferenceAssemblies.Net.Net80; // Default fallback
#endif
}
/// <inheritdoc cref="Microsoft.CodeAnalysis.Diagnostic"/>
public static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();
Expand All @@ -33,7 +45,7 @@ params DiagnosticResult[] expected
{
TestCode = source.NormalizeLineEndings(),
CodeActionValidationMode = CodeActionValidationMode.SemanticStructure,
ReferenceAssemblies = ReferenceAssemblies.Net.Net90
ReferenceAssemblies = GetReferenceAssemblies()
.AddPackages([new PackageIdentity("xunit.v3.assert", "2.0.0")]),
TestState =
{
Expand Down Expand Up @@ -68,7 +80,7 @@ public static async Task VerifyCodeFixAsync(
{
TestCode = source.NormalizeLineEndings(),
FixedCode = fixedSource.NormalizeLineEndings(),
ReferenceAssemblies = ReferenceAssemblies.Net.Net90
ReferenceAssemblies = GetReferenceAssemblies()
.AddPackages([new PackageIdentity("xunit.v3.assert", "2.0.0")]),
TestState =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ namespace TUnit.Assertions.Analyzers.Tests.Verifiers;
public static partial class CSharpAnalyzerVerifier<TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
{
private static ReferenceAssemblies GetReferenceAssemblies()
{
#if NET472
return ReferenceAssemblies.NetFramework.Net472.Default;
#elif NET8_0
return ReferenceAssemblies.Net.Net80;
#elif NET9_0 || NET10_0_OR_GREATER
return ReferenceAssemblies.Net.Net90;
#else
return ReferenceAssemblies.Net.Net80; // Default fallback
#endif
}
/// <inheritdoc cref="Microsoft.CodeAnalysis.Diagnostic"/>
public static DiagnosticResult Diagnostic()
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic();
Expand All @@ -27,7 +39,7 @@ public static async Task VerifyAnalyzerAsync([StringSyntax("c#-test")] string so
var test = new Test
{
TestCode = source,
ReferenceAssemblies = ReferenceAssemblies.Net.Net90
ReferenceAssemblies = GetReferenceAssemblies()
.AddPackages([new PackageIdentity("xunit.v3.assert", "2.0.0")]),
TestState =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesArrayAssertions() => RunTest(
"ArrayAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesAssemblyAssertions() => RunTest(
"AssemblyAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Task NonGenericAssertion() => RunTest(
"NonGenericAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsEmpty"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsEmpty");
Expand All @@ -27,7 +27,7 @@ public Task SingleGenericParameter() => RunTest(
"SingleGenericParameterAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsNull"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsNull");
Expand All @@ -42,7 +42,7 @@ public Task MultipleGenericParameters() => RunTest(
"MultipleGenericParametersAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsAssignableTo"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsAssignableTo");
Expand All @@ -57,7 +57,7 @@ public Task AssertionWithOptionalParameter() => RunTest(
"OptionalParameterAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsNotEqualTo"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsNotEqualTo");
Expand All @@ -72,7 +72,7 @@ public Task AssertionWithGenericConstraints() => RunTest(
"GenericConstraintsAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsGreaterThan"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsGreaterThan");
Expand All @@ -87,7 +87,7 @@ public Task AssertionWithMultipleConstructors() => RunTest(
"MultipleConstructorsAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsEqualTo"));
await Assert.That(extensionFile).IsNotNull();
// Should generate multiple overloads
Expand All @@ -103,7 +103,7 @@ public Task AssertionWithNegatedMethod() => RunTest(
"NegatedMethodAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsTrue"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsTrue");
Expand All @@ -118,7 +118,7 @@ public Task AssertionWithDefaultValues() => RunTest(
"DefaultValuesAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("= true"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("= true");
Expand All @@ -134,7 +134,7 @@ public Task AssertionWithEnumDefault() => RunTest(
"EnumDefaultAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("StringComparison"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("StringComparison.");
Expand All @@ -148,7 +148,7 @@ public Task AssertionWithMultipleParameters() => RunTest(
"MultipleParametersAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);
var extensionFile = generatedFiles.FirstOrDefault(f => f.Contains("IsBetween"));
await Assert.That(extensionFile).IsNotNull();
await Assert.That(extensionFile!).Contains("IsBetween");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesBooleanAssertions() => RunTest(
"BooleanAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesCancellationTokenAssertions() => RunTest(
"CancellationTokenAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesCharAssertions() => RunTest(
"CharAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesCultureInfoAssertions() => RunTest(
"CultureInfoAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesDateOnlyAssertions() => RunTest(
"DateOnlyAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(0);
await Assert.That(generatedFiles).HasCount(0);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesDateTimeAssertions() => RunTest(
"DateTimeAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesDateTimeOffsetAssertions() => RunTest(
"DateTimeOffsetAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesDayOfWeekAssertions() => RunTest(
"DayOfWeekAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesDirectoryInfoAssertions() => RunTest(
"DirectoryInfoAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesEncodingAssertions() => RunTest(
"EncodingAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesExceptionAssertions() => RunTest(
"ExceptionAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesFileInfoAssertions() => RunTest(
"FileInfoAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesGuidAssertions() => RunTest(
"GuidAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesHttpStatusCodeAssertions() => RunTest(
"HttpStatusCodeAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public Task GeneratesLazyAssertions() => RunTest(
"LazyAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Task BoolMethod() => RunTest(
"BoolMethodAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.FirstOrDefault(f => f.Contains("IsPositive_Assertion"));
await Assert.That(mainFile).IsNotNull();
Expand All @@ -30,7 +30,7 @@ public Task AssertionResultMethod() => RunTest(
"AssertionResultMethodAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.FirstOrDefault(f => f.Contains("IsEven_Assertion"));
await Assert.That(mainFile).IsNotNull();
Expand All @@ -47,7 +47,7 @@ public Task AsyncBoolMethod() => RunTest(
"AsyncBoolAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.FirstOrDefault(f => f.Contains("IsPositiveAsync_Assertion"));
await Assert.That(mainFile).IsNotNull();
Expand All @@ -63,7 +63,7 @@ public Task AsyncAssertionResultMethod() => RunTest(
"AsyncAssertionResultAssertion.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.FirstOrDefault(f => f.Contains("IsEvenAsync_Assertion"));
await Assert.That(mainFile).IsNotNull();
Expand All @@ -79,7 +79,7 @@ public Task GenericMethodWithNonInferableTypeParameter() => RunTest(
"GenericMethodWithNonInferableTypeParameter.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.FirstOrDefault(f => f.Contains("IsErrorOfType"));
await Assert.That(mainFile).IsNotNull();
Expand All @@ -99,7 +99,7 @@ public Task MethodWithComparableConstraint() => RunTest(
"MethodWithComparableConstraint.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.First();
await Assert.That(mainFile).IsNotNull();
Expand All @@ -122,7 +122,7 @@ public Task MethodWithMultipleConstraints() => RunTest(
"MethodWithMultipleConstraints.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.First();
await Assert.That(mainFile).IsNotNull();
Expand All @@ -141,7 +141,7 @@ public Task MethodWithReferenceTypeConstraint() => RunTest(
"MethodWithReferenceTypeConstraint.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.First();
await Assert.That(mainFile).IsNotNull();
Expand All @@ -160,7 +160,7 @@ public Task MethodWithValueTypeConstraint() => RunTest(
"MethodWithValueTypeConstraint.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.First();
await Assert.That(mainFile).IsNotNull();
Expand All @@ -179,7 +179,7 @@ public Task MethodWithNotNullConstraint() => RunTest(
"MethodWithNotNullConstraint.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().EqualTo(1);
await Assert.That(generatedFiles).HasCount(1);

var mainFile = generatedFiles.First();
await Assert.That(mainFile).IsNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Task GeneratesProcessAssertions() => RunTest(
"ProcessAssertionExtensions.cs"),
async generatedFiles =>
{
await Assert.That(generatedFiles).HasCount().GreaterThanOrEqualTo(1);
await Assert.That(generatedFiles).IsNotEmpty();
});
}
Loading
Loading