Skip to content

Commit 75f35d0

Browse files
authored
feat: Switched to TUnit (#126)
* feat: Switch to `TUnit` prepared * chore(sdk): Removed support for `.NET 6` and `.NET 7` * chore: Extended tests and constraints * fix(style): Reformatted code * fix: Added Pragma TUnit0046 * chore: Removed Architecture tests * chore: Removed pragma, we are waiting for a new TUnit version * fix(deps): Updated testframeworks * fix: Added `#pragma warning disable TUnit0046 // TUnit0046: Return a `Func<T>` rather than a `<T>`` for the moment * fix(deps): Added missing `Microsoft.Testing.Extensions.CodeCoverage` * chore: Removed xunit * chore: removed xunit from `Directory.Packages.props` * chore: Switched to old codecov action * revert(ci): Reverted pipeline back to versioned * fix: Removed coverlet.msbuild * fix: Try fix for repaired coverage reports * revert: Switched back to versioned pipeline * fix: Try revert/codecov-to-v3 * fix: Extended tests * fix: Possbile null reference
1 parent a408572 commit 75f35d0

21 files changed

+411
-270
lines changed

.github/workflows/cicd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
all:
2323
if: github.run_id != 1
2424
name: Build & Tests
25-
uses: dailydevops/pipelines/.github/workflows/[email protected].82
25+
uses: dailydevops/pipelines/.github/workflows/[email protected].86
2626
with:
2727
enableSonarQube: true
28-
dotnet-logging: ${{ inputs.dotnet-logging }}
28+
dotnet-logging: ${{ inputs.dotnet-logging || 'minimal' }}
2929
dotnet-version: ${{ vars.NE_DOTNET_TARGETFRAMEWORKS }}
3030
solution: ./FluentValue.sln
3131
secrets: inherit

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<CopyrightYearStart>2024</CopyrightYearStart>
1010
</PropertyGroup>
1111
<PropertyGroup>
12-
<NetEvolve_ProjectTargetFrameworks>net6.0;net8.0;net9.0</NetEvolve_ProjectTargetFrameworks>
13-
<NetEvolve_TestTargetFrameworks>net6.0;net7.0;net8.0;net9.0</NetEvolve_TestTargetFrameworks>
12+
<NetEvolve_ProjectTargetFrameworks>net8.0;net9.0</NetEvolve_ProjectTargetFrameworks>
13+
<NetEvolve_TestTargetFrameworks>net8.0;net9.0</NetEvolve_TestTargetFrameworks>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<!-- Workaround, until https://github.com/GitTools/GitVersion/pull/4206 is released -->

Directory.Packages.props

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<GlobalPackageReference Include="CSharpier.MSBuild" Version="1.0.1" />
8-
<GlobalPackageReference Include="GitVersion.MsBuild" Version="6.1.0" />
8+
<GlobalPackageReference Include="GitVersion.MsBuild" Version="6.3.0" />
99
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
1010
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
1111
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
1212
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61" />
1313
<GlobalPackageReference Include="NetEvolve.Defaults" Version="1.3.80" />
1414
<GlobalPackageReference
1515
Include="SonarAnalyzer.CSharp"
16-
Version="10.6.0.109712"
16+
Version="10.9.0.115408"
1717
Condition=" '$(BuildingInsideVisualStudio)' == 'true' "
1818
/>
1919
</ItemGroup>
2020
<ItemGroup>
2121
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
22-
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
2322
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2423
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />
2524
<PackageVersion Include="NetEvolve.Arguments" Version="1.3.84" />
26-
<PackageVersion Include="NetEvolve.Extensions.XUnit" Version="2.6.9" />
27-
<PackageVersion Include="xunit" Version="2.9.3" />
28-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
25+
<PackageVersion Include="NetEvolve.Extensions.TUnit" Version="2.6.9" />
26+
<PackageVersion Include="TUnit" Version="0.19.143" />
2927
</ItemGroup>
3028
</Project>

FluentValue.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AE6A68C3
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.FluentValue.Tests.Unit", "tests\NetEvolve.FluentValue.Tests.Unit\NetEvolve.FluentValue.Tests.Unit.csproj", "{93D85E57-7EB9-4CDD-836E-301A58BF3312}"
1313
EndProject
14-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.FluentValue.Tests.Architecture", "tests\NetEvolve.FluentValue.Tests.Architecture\NetEvolve.FluentValue.Tests.Architecture.csproj", "{6C599754-9C81-494C-9136-98259711B6C8}"
15-
EndProject
1614
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FF9F0BF-A46C-4C74-BD17-25B38E8D85EE}"
1715
ProjectSection(SolutionItems) = preProject
1816
.commitlintrc = .commitlintrc
@@ -46,17 +44,12 @@ Global
4644
{93D85E57-7EB9-4CDD-836E-301A58BF3312}.Debug|Any CPU.Build.0 = Debug|Any CPU
4745
{93D85E57-7EB9-4CDD-836E-301A58BF3312}.Release|Any CPU.ActiveCfg = Release|Any CPU
4846
{93D85E57-7EB9-4CDD-836E-301A58BF3312}.Release|Any CPU.Build.0 = Release|Any CPU
49-
{6C599754-9C81-494C-9136-98259711B6C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50-
{6C599754-9C81-494C-9136-98259711B6C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
51-
{6C599754-9C81-494C-9136-98259711B6C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
52-
{6C599754-9C81-494C-9136-98259711B6C8}.Release|Any CPU.Build.0 = Release|Any CPU
5347
EndGlobalSection
5448
GlobalSection(SolutionProperties) = preSolution
5549
HideSolutionNode = FALSE
5650
EndGlobalSection
5751
GlobalSection(NestedProjects) = preSolution
5852
{7B62BC70-8970-4D45-A86C-CB6C7E64A5D9} = {BB2B11D1-1E37-4333-9E07-E6709C1796F5}
5953
{93D85E57-7EB9-4CDD-836E-301A58BF3312} = {AE6A68C3-E24A-45BC-B7A6-4D527AF3BF99}
60-
{6C599754-9C81-494C-9136-98259711B6C8} = {AE6A68C3-E24A-45BC-B7A6-4D527AF3BF99}
6154
EndGlobalSection
6255
EndGlobal

src/NetEvolve.FluentValue/Constraints/ConstraintBase.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
namespace NetEvolve.FluentValue.Constraints;
22

33
using System;
4+
using System.Collections;
5+
using System.ComponentModel;
6+
using System.Diagnostics;
7+
using System.Diagnostics.CodeAnalysis;
48
using System.Text;
59
using NetEvolve.FluentValue;
610

11+
[SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "As designed.")]
12+
[SuppressMessage(
13+
"Blocker Code Smell",
14+
"S3877:Exceptions should not be thrown from unexpected methods",
15+
Justification = "As designed."
16+
)]
717
internal abstract class ConstraintBase : IConstraint
818
{
919
[ThreadStatic]
1020
private static StringBuilder? _builder;
1121

1222
private const int DefaultCapacity = 1024;
1323

24+
/// <inheritdoc />
1425
public abstract bool IsSatisfiedBy(object? value);
1526

27+
/// <inheritdoc />
1628
public abstract void SetDescription(StringBuilder builder);
1729

30+
/// <inhertdoc />
31+
[Obsolete("This is base `object` method that should not be called.", true)]
32+
[EditorBrowsable(EditorBrowsableState.Never)]
33+
[DebuggerHidden]
34+
public new bool Equals(object? obj) =>
35+
throw new NotSupportedException("This is base `object` method that should not be called.");
36+
37+
/// <inheritdoc/>
38+
[Obsolete("This is base `object` method that should not be called.", true)]
39+
[EditorBrowsable(EditorBrowsableState.Never)]
40+
[DebuggerHidden]
41+
public new int GetHashCode() =>
42+
throw new NotSupportedException("This is base `object` method that should not be called.");
43+
1844
public override string ToString()
1945
{
2046
var builder = _builder ?? new StringBuilder(capacity: DefaultCapacity);

src/NetEvolve.FluentValue/Constraints/DefaultConstraint.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22

33
using System;
44
using System.Text;
5+
using NetEvolve.FluentValue;
56

67
internal sealed class DefaultConstraint : ConstraintBase
78
{
89
public override bool IsSatisfiedBy(object? value) =>
910
value?.GetType() switch
1011
{
11-
{ IsValueType: true } valueType => GetDefault(valueType).Equals(value),
12+
{ IsValueType: true } valueType => TypeExtensions.GetDefault(valueType)?.Equals(value) ?? false,
1213
_ => false,
1314
};
1415

1516
public override void SetDescription(StringBuilder builder) => builder.Append(" is <default>");
16-
17-
private static object GetDefault(Type value)
18-
{
19-
var underlying = Nullable.GetUnderlyingType(value);
20-
if (underlying is not null)
21-
{
22-
return Activator.CreateInstance(underlying)!;
23-
}
24-
return Activator.CreateInstance(value)!;
25-
}
2617
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NetEvolve.FluentValue.Constraints;
2+
3+
using System.Text;
4+
using NetEvolve.FluentValue;
5+
6+
internal sealed class NotDefaultConstraint : ConstraintBase
7+
{
8+
public override bool IsSatisfiedBy(object? value) =>
9+
value?.GetType() switch
10+
{
11+
{ IsValueType: true } valueType => !TypeExtensions.GetDefault(valueType)?.Equals(value) ?? false,
12+
_ => true,
13+
};
14+
15+
public override void SetDescription(StringBuilder builder) => builder.Append(" is not <default>");
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace NetEvolve.FluentValue.Constraints;
2+
3+
using System;
4+
using System.Collections;
5+
using System.Text;
6+
7+
internal sealed class NotEmptyConstraint : ConstraintBase
8+
{
9+
public override bool IsSatisfiedBy(object? value) =>
10+
value switch
11+
{
12+
string stringValue => stringValue.Length > 0,
13+
Guid guidValue => guidValue != Guid.Empty,
14+
ICollection collection => collection.Count > 0,
15+
IEnumerable enumerable => enumerable.GetEnumerator().MoveNext(),
16+
_ => false,
17+
};
18+
19+
public override void SetDescription(StringBuilder builder) => builder.Append(" is not <empty>");
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace NetEvolve.FluentValue.Constraints;
2+
3+
using System.Text;
4+
5+
internal sealed class NotNullConstraint : ConstraintBase
6+
{
7+
public override bool IsSatisfiedBy(object? value) => value is not null;
8+
9+
public override void SetDescription(StringBuilder builder) => builder.Append(" is not <null>");
10+
}

src/NetEvolve.FluentValue/IOperator.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ IConstraint EqualTo(string compareValue, StringComparison comparison = default)
138138
/// <returns>
139139
/// The current instance.
140140
/// </returns>
141-
IConstraint Matches(
142-
#if NET7_0_OR_GREATER
143-
[StringSyntax(StringSyntaxAttribute.Regex)]
144-
#endif
145-
string pattern, RegexOptions? options = null) => SetConstraint(new MatchesConstraint(pattern, options));
141+
IConstraint Matches([StringSyntax(StringSyntaxAttribute.Regex)] string pattern, RegexOptions? options = null) =>
142+
SetConstraint(new MatchesConstraint(pattern, options));
146143

147144
/// <summary>
148145
/// Appends a negation operator.
@@ -165,6 +162,21 @@ IOperator Not
165162
}
166163
}
167164

165+
/// <summary>
166+
/// Appends a constraint that the value is <see langword="not"/> the <see langword="default"/> value.
167+
/// </summary>
168+
IConstraint NotDefault => SetConstraint(new NotDefaultConstraint());
169+
170+
/// <summary>
171+
/// Appends a constraint that the value is <see langword="not"/> empty.
172+
/// </summary>
173+
IConstraint NotEmpty => SetConstraint(new NotEmptyConstraint());
174+
175+
/// <summary>
176+
/// Appends a constraint that the value is <see langword="not"/> <see langword="null"/>.
177+
/// </summary>
178+
IConstraint NotNull => SetConstraint(new NotNullConstraint());
179+
168180
/// <summary>
169181
/// Appends a constraint that the value is <see langword="null"/>.
170182
/// </summary>

0 commit comments

Comments
 (0)