Skip to content

Commit 4948362

Browse files
committed
Fix: Auto code cleanup
1 parent 2a2be5e commit 4948362

23 files changed

+182
-195
lines changed

.editorconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ dotnet_naming_symbols.private_instance_fields_symbols.resharper_applicable_kinds
7171
dotnet_naming_symbols.private_instance_fields_symbols.resharper_required_modifiers = instance
7272
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_accessibilities = private
7373
dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_kinds = field
74-
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field,readonly_field
74+
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds = field, readonly_field
7575
dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_required_modifiers = instance
7676
dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private
7777
dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field
@@ -84,11 +84,11 @@ dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = reado
8484
dotnet_naming_symbols.private_static_readonly_symbols.resharper_applicable_kinds = readonly_field
8585
dotnet_naming_symbols.private_static_readonly_symbols.resharper_required_modifiers = static
8686
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
87-
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
87+
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
8888
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
8989
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
9090
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = *
91-
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
91+
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
9292
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
9393
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
9494
dotnet_sort_system_directives_first = false
@@ -143,7 +143,7 @@ resharper_formatter_tags_enabled = true
143143
resharper_indent_preprocessor_if = usual_indent
144144
resharper_indent_preprocessor_other = do_not_change
145145
resharper_indent_raw_literal_string = indent
146-
resharper_instance_members_qualify_declared_in =
146+
resharper_instance_members_qualify_declared_in =
147147
resharper_keep_existing_attribute_arrangement = true
148148
resharper_keep_existing_declaration_block_arrangement = true
149149
resharper_keep_existing_embedded_block_arrangement = true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# CodeOfChaos.Testing.TUnit
2+
23
Some extension methods on the TUnit testing framework.

src/CodeOfChaos.Testing.TUnit/CodeOfChaos.Testing.TUnit.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
27-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
28-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
26+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
27+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
28+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
2929
</ItemGroup>
30-
30+
3131
<ItemGroup>
32-
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
33-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
34-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
35-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
36-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
37-
<PackageReference Include="TUnit.Assertions" Version="0.10.19" />
38-
<PackageReference Include="TUnit.Core" Version="0.10.19" />
32+
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
33+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0"/>
34+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0"/>
35+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
36+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0"/>
37+
<PackageReference Include="TUnit.Assertions" Version="0.10.19"/>
38+
<PackageReference Include="TUnit.Core" Version="0.10.19"/>
3939
</ItemGroup>
4040

4141
</Project>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
1+
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
2+
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xml:space="preserve">
24
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/CodeOfChaos.Testing.TUnit/Conditions/GeneratorDriverRunResultHasSourceTextEqualToCondition.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using TUnit.Assertions.AssertConditions.String;
77

88
namespace CodeOfChaos.Testing.TUnit.Conditions;
9-
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------
@@ -18,23 +17,24 @@ public class GeneratorDriverRunResultHasSourceTextEqualToCondition(string filena
1817
// Methods
1918
// -----------------------------------------------------------------------------------------------------------------
2019
protected override string GetExpectation() => throw new NotImplementedException();
21-
protected async override Task<AssertionResult> GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
20+
protected override async Task<AssertionResult> GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
2221
if (runResult is null) return AssertionResult.Fail("Compilation is null");
2322
if (expectedValue is null) return AssertionResult.Fail("Expected string is null");
24-
23+
2524
GeneratedSourceResult? generatedSource = runResult.Results
2625
.SelectMany(result => result.GeneratedSources)
2726
.SingleOrDefault(result => result.HintName == filename);
28-
27+
2928
if (generatedSource is null) return AssertionResult.Fail($"Could not find source with name '{filename}'");
30-
29+
3130
if (generatedSource.Value.SourceText is not {} sourceText) return AssertionResult.Fail("Source text is null");
31+
3232
string sourceTextString = sourceText.ToString();
33-
33+
3434
// Use the TUnit Equals String so it follows the same structure
3535
var stringEqualsAssertCondition = new StringEqualsExpectedValueAssertCondition(_expected, stringComparison);
36-
if(withTrimming) stringEqualsAssertCondition.WithTrimming();
37-
if(ignoreWhiteSpace) stringEqualsAssertCondition.IgnoringWhitespace();
36+
if (withTrimming) stringEqualsAssertCondition.WithTrimming();
37+
if (ignoreWhiteSpace) stringEqualsAssertCondition.IgnoringWhitespace();
3838

3939
return await stringEqualsAssertCondition.GetAssertionResult(sourceTextString, null);
4040
}

src/CodeOfChaos.Testing.TUnit/Conditions/Library/ContainsDiagnosticAssertCondition.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
using TUnit.Assertions.AssertConditions;
77

88
namespace CodeOfChaos.Testing.TUnit.Conditions.Library;
9-
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------
13-
public class ContainsDiagnosticAssertCondition<T>(Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction, string expectedId): ExpectedValueAssertCondition<T, string>(expectedId) {
12+
public class ContainsDiagnosticAssertCondition<T>(Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction, string expectedId) : ExpectedValueAssertCondition<T, string>(expectedId) {
1413
// -----------------------------------------------------------------------------------------------------------------
1514
// Methods
1615
// -----------------------------------------------------------------------------------------------------------------
1716
protected override string GetExpectation() => $"to have a diagnostic with Id \"{ExpectedValue}\"";
1817
protected override async Task<AssertionResult> GetResult(T? actualValue, string? expectedValue) {
1918
if (actualValue is null) return AssertionResult.Fail($"{nameof(T)} is null");
2019
if (expectedValue is null) return AssertionResult.Fail("Expected value is null");
21-
20+
2221
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
2322
if (!diagnostics.Any()) return FailWithMessage("No diagnostics");
2423
if (diagnostics.Any(d => d.Id == expectedValue)) return AssertionResult.Passed;
24+
2525
return FailWithMessage("No diagnostic with Id");
2626
}
27-
}
27+
}

src/CodeOfChaos.Testing.TUnit/Conditions/Library/ContainsDiagnosticsExclusivelyAssertCondition.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using TUnit.Assertions.AssertConditions;
77

88
namespace CodeOfChaos.Testing.TUnit.Conditions.Library;
9-
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------
@@ -20,31 +19,31 @@ public class ContainsDiagnosticsExclusivelyAssertCondition<T>(Func<T, ValueTask<
2019
protected override async Task<AssertionResult> GetResult(T? actualValue, string[]? expectedValues) {
2120
if (actualValue is null) return AssertionResult.Fail($"{nameof(T)} is null");
2221
if (expectedValues is null) return AssertionResult.Fail("Expected value is null");
23-
22+
2423
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
2524
if (!diagnostics.Any() && expectedValues.Length == 0) return AssertionResult.Passed;
2625
if (!diagnostics.Any()) return FailWithMessage("No diagnostics");
2726
if (expectedValues.Length != diagnostics.Length) return FailWithMessage("Wrong number of diagnostics");
28-
27+
2928
HashSet<string> diagnosticsHashSet = diagnostics.Select(d => d.Id).ToHashSet();
3029
HashSet<string> expectedValuesHashSet = expectedValues.ToHashSet();
31-
30+
3231
if (diagnosticsHashSet.SetEquals(expectedValuesHashSet)) return AssertionResult.Passed;
3332

3433
// Find which diagnostics are missing or unexpected
3534
string[] missingDiagnostics = expectedValuesHashSet.Except(diagnosticsHashSet).ToArray();
3635
string[] unexpectedDiagnostics = diagnosticsHashSet.Except(expectedValuesHashSet).ToArray();
37-
36+
3837
string errorMessage = "Diagnostics do not match:";
39-
38+
4039
if (missingDiagnostics.Length != 0) {
4140
errorMessage += $"\n - Missing diagnostics: {string.Join(", ", missingDiagnostics)}";
4241
}
43-
42+
4443
if (unexpectedDiagnostics.Length != 0) {
4544
errorMessage += $"\n - Unexpected diagnostics: {string.Join(", ", unexpectedDiagnostics)}";
4645
}
47-
46+
4847
return AssertionResult.Fail(errorMessage);
4948

5049
}

src/CodeOfChaos.Testing.TUnit/Conditions/Library/DoesNotContainDiagnosticAssertCondition.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using TUnit.Assertions.AssertConditions;
77

88
namespace CodeOfChaos.Testing.TUnit.Conditions.Library;
9-
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------
@@ -21,12 +20,11 @@ public class DoesNotContainDiagnosticAssertCondition<T>(Func<T, ValueTask<Immuta
2120
protected override async Task<AssertionResult> GetResult(T? actualValue, string? expectedValue) {
2221
if (actualValue is null) return AssertionResult.Fail($"{nameof(T)} is null");
2322
if (expectedValue is null) return AssertionResult.Fail("Expected value is null");
24-
23+
2524
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
2625

2726
if (diagnostics.Any(d => d.Id == expectedValue)) return FailWithMessage("Diagnostic with Id");
2827

2928
return AssertionResult.Passed;
3029
}
31-
3230
}
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.Testing.TUnit.Conditions;
54
using CodeOfChaos.Testing.TUnit.Conditions.Library;
65
using Microsoft.CodeAnalysis;
76
using System.Runtime.CompilerServices;
8-
using TUnit.Assertions.AssertConditions;
97
using TUnit.Assertions.AssertConditions.Interfaces;
108
using TUnit.Assertions.AssertionBuilders;
119

1210
namespace CodeOfChaos.Testing.TUnit;
13-
1411
// ---------------------------------------------------------------------------------------------------------------------
1512
// Code
1613
// ---------------------------------------------------------------------------------------------------------------------
1714
// ReSharper disable once InconsistentNaming
1815
public static class TUnitExtensionsCompilation {
1916
public static InvokableValueAssertionBuilder<Compilation> ContainsDiagnostic(this IValueSource<Compilation> valueSource, string expectedId, [CallerArgumentExpression(nameof(expectedId))] string doNotPopulateThisValue1 = "") {
2017
return valueSource.RegisterAssertion(
21-
assertCondition: new ContainsDiagnosticAssertCondition<Compilation>(
22-
static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
18+
new ContainsDiagnosticAssertCondition<Compilation>(
19+
getDiagnosticsAction: static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
2320
expectedId
2421
),
25-
argumentExpressions: [doNotPopulateThisValue1]
22+
[doNotPopulateThisValue1]
2623
);
2724
}
28-
25+
2926
public static InvokableValueAssertionBuilder<Compilation> DoesNotContainDiagnostic(this IValueSource<Compilation> valueSource, string expectedId, [CallerArgumentExpression(nameof(expectedId))] string doNotPopulateThisValue1 = "") {
3027
return valueSource.RegisterAssertion(
31-
assertCondition: new DoesNotContainDiagnosticAssertCondition<Compilation>(
32-
static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
28+
new DoesNotContainDiagnosticAssertCondition<Compilation>(
29+
getDiagnosticsAction: static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
3330
expectedId
3431
),
35-
argumentExpressions: [doNotPopulateThisValue1]
32+
[doNotPopulateThisValue1]
3633
);
3734
}
3835

3936
public static InvokableValueAssertionBuilder<Compilation> ContainsDiagnosticsExclusively(this IValueSource<Compilation> valueSource, string[] expectedIds, [CallerArgumentExpression(nameof(expectedIds))] string doNotPopulateThisValue1 = "") {
4037
return valueSource.RegisterAssertion(
41-
assertCondition: new ContainsDiagnosticsExclusivelyAssertCondition<Compilation>(
42-
static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
38+
new ContainsDiagnosticsExclusivelyAssertCondition<Compilation>(
39+
getDiagnosticsAction: static compilation => ValueTask.FromResult(compilation.GetDiagnostics()),
4340
expectedIds
4441
),
45-
argumentExpressions: [doNotPopulateThisValue1]
42+
[doNotPopulateThisValue1]
4643
);
4744
}
4845
}

src/CodeOfChaos.Testing.TUnit/Extensions/TUnitExtensionsCompilationWithAnalyzers.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,38 @@
88
using TUnit.Assertions.AssertionBuilders;
99

1010
namespace CodeOfChaos.Testing.TUnit;
11-
1211
// ---------------------------------------------------------------------------------------------------------------------
1312
// Code
1413
// ---------------------------------------------------------------------------------------------------------------------
1514
// ReSharper disable once InconsistentNaming
1615
public static class TUnitExtensionsCompilationWithAnalyzers {
1716
public static InvokableValueAssertionBuilder<CompilationWithAnalyzers> ContainsDiagnostic(this IValueSource<CompilationWithAnalyzers> valueSource, string expectedId, [CallerArgumentExpression(nameof(expectedId))] string doNotPopulateThisValue1 = "") {
1817
return valueSource.RegisterAssertion(
19-
assertCondition: new ContainsDiagnosticAssertCondition<CompilationWithAnalyzers>(
20-
async static compilation => await compilation.GetAllDiagnosticsAsync(),
18+
new ContainsDiagnosticAssertCondition<CompilationWithAnalyzers>(
19+
getDiagnosticsAction: async static compilation => await compilation.GetAllDiagnosticsAsync(),
2120
expectedId
2221
),
23-
argumentExpressions: [doNotPopulateThisValue1]
22+
[doNotPopulateThisValue1]
2423
);
2524
}
26-
25+
2726
public static InvokableValueAssertionBuilder<CompilationWithAnalyzers> DoesNotContainDiagnostic(this IValueSource<CompilationWithAnalyzers> valueSource, string expectedId, [CallerArgumentExpression(nameof(expectedId))] string doNotPopulateThisValue1 = "") {
2827
return valueSource.RegisterAssertion(
29-
assertCondition: new DoesNotContainDiagnosticAssertCondition<CompilationWithAnalyzers>(
30-
async static compilation => await compilation.GetAllDiagnosticsAsync(),
28+
new DoesNotContainDiagnosticAssertCondition<CompilationWithAnalyzers>(
29+
getDiagnosticsAction: async static compilation => await compilation.GetAllDiagnosticsAsync(),
3130
expectedId
3231
),
33-
argumentExpressions: [doNotPopulateThisValue1]
32+
[doNotPopulateThisValue1]
3433
);
3534
}
3635

3736
public static InvokableValueAssertionBuilder<CompilationWithAnalyzers> ContainsDiagnosticsExclusively(this IValueSource<CompilationWithAnalyzers> valueSource, string[] expectedIds, [CallerArgumentExpression(nameof(expectedIds))] string doNotPopulateThisValue1 = "") {
3837
return valueSource.RegisterAssertion(
39-
assertCondition: new ContainsDiagnosticsExclusivelyAssertCondition<CompilationWithAnalyzers>(
40-
async static compilation => await compilation.GetAllDiagnosticsAsync(),
38+
new ContainsDiagnosticsExclusivelyAssertCondition<CompilationWithAnalyzers>(
39+
getDiagnosticsAction: async static compilation => await compilation.GetAllDiagnosticsAsync(),
4140
expectedIds
4241
),
43-
argumentExpressions: [doNotPopulateThisValue1]
42+
[doNotPopulateThisValue1]
4443
);
4544
}
46-
4745
}

0 commit comments

Comments
 (0)