Skip to content

Commit 5e5e530

Browse files
committed
VersionBump : v0.1.0
1 parent 90e343e commit 5e5e530

11 files changed

+58
-19
lines changed

README.md

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

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
9+
<!-- Main package name -->
10+
<PackageId>CodeOfChaos.Testing.TUnit</PackageId>
11+
<Version>0.1.0</Version>
12+
<Authors>Anna Sas</Authors>
13+
<Description>A small library housing extensions to the TUnit framework</Description>
14+
<PackageProjectUrl>https://github.com/code-of-chaos/cs_code-of_chaos-testing-tunit</PackageProjectUrl>
15+
<PackageTags>extensions tunit testing</PackageTags>
16+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
17+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
18+
<IncludeSymbols>true</IncludeSymbols>
19+
<DebugType>embedded</DebugType>
20+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
21+
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
<PackageIcon>icon.png</PackageIcon>
823
</PropertyGroup>
24+
25+
<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" />
29+
</ItemGroup>
930

1031
<ItemGroup>
11-
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
12-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0"/>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0"/>
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
15-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0"/>
16-
<PackageReference Include="TUnit.Assertions" Version="0.8.8" />
17-
<PackageReference Include="TUnit.Core" Version="0.8.8" />
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" />
1839
</ItemGroup>
1940

2041
</Project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CompilationContainsDiagnosticAssertCondition(string expectedId)
1515

1616
protected override string GetExpectation() => $"to have a diagnostic with Id \"{ExpectedValue}\"";
1717

18-
protected override AssertionResult GetResult(Compilation? actualValue, string? expectedValue) {
18+
protected override Task<AssertionResult> GetResult(Compilation? actualValue, string? expectedValue) {
1919
if (actualValue is null) return AssertionResult.Fail("Compilation is null");
2020
if (expectedValue is null) return AssertionResult.Fail("Expected value is null");
2121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CompilationContainsDiagnosticsExclusivelyAssertCondition(string[] e
1515

1616
protected override string GetExpectation() => $"to have a compilation output with the following Ids \"{ExpectedValue}\"";
1717

18-
protected override AssertionResult GetResult(Compilation? compilation, string[]? expectedValues) {
18+
protected override Task<AssertionResult> GetResult(Compilation? compilation, string[]? expectedValues) {
1919
if (compilation is null) return AssertionResult.Fail("Compilation is null");
2020
if (expectedValues is null) return AssertionResult.Fail("Expected value is null");
2121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CompilationDoesNotContainDiagnosticAssertCondition(string expectedI
1515

1616
protected override string GetExpectation() => $"to not have a diagnostic with Id \"{ExpectedValue}\"";
1717

18-
protected override AssertionResult GetResult(Compilation? actualValue, string? expectedValue) {
18+
protected override Task<AssertionResult> GetResult(Compilation? actualValue, string? expectedValue) {
1919
if (actualValue is null) return AssertionResult.Fail("Compilation is null");
2020
if (expectedValue is null) return AssertionResult.Fail("Expected value is null");
2121

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ---------------------------------------------------------------------------------------------------------------------
44
using Microsoft.CodeAnalysis;
55
using TUnit.Assertions.AssertConditions;
6+
using TUnit.Assertions.AssertConditions.String;
67

78
namespace CodeOfChaos.Testing.TUnit.Conditions;
89

@@ -11,9 +12,13 @@ namespace CodeOfChaos.Testing.TUnit.Conditions;
1112
// ---------------------------------------------------------------------------------------------------------------------
1213
public class CompilationHasSourceTextEqualToCondition(string filename, string expected, StringComparison stringComparison, bool ignoreWhiteSpace, bool withTrimming)
1314
: ExpectedValueAssertCondition<GeneratorDriverRunResult, string>(expected) {
15+
private readonly string _expected = expected;
1416

17+
// -----------------------------------------------------------------------------------------------------------------
18+
// Methods
19+
// -----------------------------------------------------------------------------------------------------------------
1520
protected override string GetExpectation() => throw new NotImplementedException();
16-
protected override AssertionResult GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
21+
protected async override Task<AssertionResult> GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
1722
if (runResult is null) return AssertionResult.Fail("Compilation is null");
1823
if (expectedValue is null) return AssertionResult.Fail("Expected string is null");
1924

@@ -26,10 +31,17 @@ protected override AssertionResult GetResult(GeneratorDriverRunResult? runResult
2631
if (generatedSource.Value.SourceText is not {} sourceText) return AssertionResult.Fail("Source text is null");
2732
string sourceTextString = sourceText.ToString();
2833

29-
if (ignoreWhiteSpace) sourceTextString = string.Join(string.Empty, sourceTextString.Where(c => !char.IsWhiteSpace(c)));
30-
if (withTrimming) sourceTextString = sourceTextString.Trim();
34+
// Use the TUnit Equals String so it follows the same structure
35+
var stringEqualsAssertCondition = new StringEqualsExpectedValueAssertCondition(_expected, stringComparison);
36+
if(withTrimming) stringEqualsAssertCondition.WithTrimming();
37+
if(ignoreWhiteSpace) stringEqualsAssertCondition.IgnoringWhitespace();
3138

32-
return AssertionResult
33-
.FailIf(!string.Equals(sourceTextString, expectedValue, stringComparison), "Source text does not match");
39+
return await stringEqualsAssertCondition.GetAssertionResult(sourceTextString, null);
40+
41+
// if (ignoreWhiteSpace) sourceTextString = string.Join(string.Empty, sourceTextString.Where(c => !char.IsWhiteSpace(c)));
42+
// if (withTrimming) sourceTextString = sourceTextString.Trim();
43+
//
44+
// return AssertionResult
45+
// .FailIf(!string.Equals(sourceTextString, expectedValue, stringComparison), "Source text does not match");
3446
}
3547
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using CodeOfChaos.Testing.TUnit.Conditions;
55
using Microsoft.CodeAnalysis;
66
using System.Runtime.CompilerServices;
7+
using TUnit.Assertions.AssertConditions;
78
using TUnit.Assertions.AssertConditions.Interfaces;
89
using TUnit.Assertions.AssertionBuilders;
9-
using TUnit.Assertions.AssertionBuilders.Wrappers;
1010

1111
namespace CodeOfChaos.Testing.TUnit;
1212

src/Tools.CodeOfChaos.Testing.TUnit/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static async Task Main(string[] args) {
2323
// Sometimes CLI params is not the answer.
2424
// Code is the true saviour
2525
string projects = string.Join(";",
26-
"TEMPLATE"
26+
"CodeOfChaos.Testing.TUnit"
2727
);
2828
string oneLineArgs = InputHelper.ToOneLine(args).Replace("%PROJECTS%", projects);
2929

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.4.0" />
12+
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.5.0" />
1313
</ItemGroup>
1414

1515
</Project>

tests/Tests.CodeOfChaos.Testing.TUnit/TUnitExtensionTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.Testing.TUnit;
55
using Microsoft.CodeAnalysis;
6+
using System.Runtime.CompilerServices;
7+
using TUnit.Assertions.AssertConditions;
8+
using TUnit.Assertions.AssertConditions.Interfaces;
9+
using TUnit.Assertions.AssertionBuilders;
610

711
namespace Tests.CodeOfChaos.Testing.TUnit;
812

0 commit comments

Comments
 (0)