Skip to content

Commit

Permalink
VersionBump : v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaSasDev committed Feb 4, 2025
1 parent 90e343e commit 5e5e530
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CodeOfChaos.Testing.TUnit
Some extension methods on the TUnit testing framework.
35 changes: 28 additions & 7 deletions src/CodeOfChaos.Testing.TUnit/CodeOfChaos.Testing.TUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,37 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Main package name -->
<PackageId>CodeOfChaos.Testing.TUnit</PackageId>
<Version>0.1.0</Version>
<Authors>Anna Sas</Authors>
<Description>A small library housing extensions to the TUnit framework</Description>
<PackageProjectUrl>https://github.com/code-of-chaos/cs_code-of_chaos-testing-tunit</PackageProjectUrl>
<PackageTags>extensions tunit testing</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0"/>
<PackageReference Include="TUnit.Assertions" Version="0.8.8" />
<PackageReference Include="TUnit.Core" Version="0.8.8" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageReference Include="TUnit.Assertions" Version="0.10.19" />
<PackageReference Include="TUnit.Core" Version="0.10.19" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CompilationContainsDiagnosticAssertCondition(string expectedId)

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CompilationContainsDiagnosticsExclusivelyAssertCondition(string[] e

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CompilationDoesNotContainDiagnosticAssertCondition(string expectedI

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ---------------------------------------------------------------------------------------------------------------------
using Microsoft.CodeAnalysis;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.String;

namespace CodeOfChaos.Testing.TUnit.Conditions;

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

// -----------------------------------------------------------------------------------------------------------------
// Methods
// -----------------------------------------------------------------------------------------------------------------
protected override string GetExpectation() => throw new NotImplementedException();
protected override AssertionResult GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
protected async override Task<AssertionResult> GetResult(GeneratorDriverRunResult? runResult, string? expectedValue) {
if (runResult is null) return AssertionResult.Fail("Compilation is null");
if (expectedValue is null) return AssertionResult.Fail("Expected string is null");

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

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

return AssertionResult
.FailIf(!string.Equals(sourceTextString, expectedValue, stringComparison), "Source text does not match");
return await stringEqualsAssertCondition.GetAssertionResult(sourceTextString, null);

// if (ignoreWhiteSpace) sourceTextString = string.Join(string.Empty, sourceTextString.Where(c => !char.IsWhiteSpace(c)));
// if (withTrimming) sourceTextString = sourceTextString.Trim();
//
// return AssertionResult
// .FailIf(!string.Equals(sourceTextString, expectedValue, stringComparison), "Source text does not match");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using CodeOfChaos.Testing.TUnit.Conditions;
using Microsoft.CodeAnalysis;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Interfaces;
using TUnit.Assertions.AssertionBuilders;
using TUnit.Assertions.AssertionBuilders.Wrappers;

namespace CodeOfChaos.Testing.TUnit;

Expand Down
2 changes: 1 addition & 1 deletion src/Tools.CodeOfChaos.Testing.TUnit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static async Task Main(string[] args) {
// Sometimes CLI params is not the answer.
// Code is the true saviour
string projects = string.Join(";",
"TEMPLATE"
"CodeOfChaos.Testing.TUnit"
);
string oneLineArgs = InputHelper.ToOneLine(args).Replace("%PROJECTS%", projects);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.4.0" />
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.5.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions tests/Tests.CodeOfChaos.Testing.TUnit/TUnitExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// ---------------------------------------------------------------------------------------------------------------------
using CodeOfChaos.Testing.TUnit;
using Microsoft.CodeAnalysis;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Interfaces;
using TUnit.Assertions.AssertionBuilders;

namespace Tests.CodeOfChaos.Testing.TUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
<PackageReference Include="Moq" Version="4.20.72"/>
<PackageReference Include="TUnit" Version="0.8.8" />
<PackageReference Include="TUnit" Version="0.10.19" />
<PackageReference Include="Bogus" Version="35.6.1"/>
</ItemGroup>

Expand Down

0 comments on commit 5e5e530

Please sign in to comment.