Skip to content

Commit

Permalink
Add .NET Standard 2.0 target
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Dec 20, 2024
1 parent 8664f80 commit ba75168
Show file tree
Hide file tree
Showing 70 changed files with 681 additions and 160 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--suppress MsbuildTargetFrameworkTagInspection -->
<TargetFrameworks Condition="'$(SDK_VERSION)' == 'net8'">net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(SDK_VERSION)' == 'net9'">net8.0;net9.0</TargetFrameworks>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -84,5 +84,5 @@
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="\" />
<None Include="$(MSBuildThisFileDirectory)assets/logo.png" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>

</Project>
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageVersion Include="AutoFixture" Version="4.18.1" />
<PackageVersion Include="Backport.System.Threading.Lock" Version="3.1.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="C5" Version="3.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="CliWrap" Version="3.7.0" />
<PackageVersion Include="EnumerableAsyncProcessor" Version="1.4.0" />
Expand Down Expand Up @@ -50,6 +51,7 @@
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.1.0" />
<PackageVersion Include="trxparser" Version="0.5.0" />
<PackageVersion Include="TUnit" Version="0.5.15" />
Expand Down
14 changes: 14 additions & 0 deletions Polyfill.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0</TargetFrameworks>
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" />
<PackageReference Include="PolySharp" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'!='.NETCoreApp'">
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions TUnit.Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static async Task<Exception> ThrowsAsync(Type type, Func<Task> @delegate,
{
await @delegate();
}
catch (Exception e) when (e.GetType().IsAssignableTo(type))
catch (Exception e) when (type.IsAssignableFrom(e.GetType()))
{
return e;
}
Expand All @@ -121,7 +121,7 @@ public static Exception Throws(Type type, Action @delegate, [CallerArgumentExpre
{
@delegate();
}
catch (Exception e) when (e.GetType().IsAssignableTo(type))
catch (Exception e) when (type.IsAssignableFrom(e.GetType()))
{
return e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal class AndAssertCondition<TActual> : BaseAssertCondition<TActual>

public AndAssertCondition(BaseAssertCondition<TActual> condition1, BaseAssertCondition<TActual> condition2)
{
ArgumentNullException.ThrowIfNull(condition1);
ArgumentNullException.ThrowIfNull(condition2);
Verify.ArgNotNull(condition1);
Verify.ArgNotNull(condition2);

_condition1 = condition1;
_condition2 = condition2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal class OrAssertCondition<TActual> : BaseAssertCondition<TActual>

public OrAssertCondition(BaseAssertCondition<TActual> condition1, BaseAssertCondition<TActual> condition2)
{
ArgumentNullException.ThrowIfNull(condition1);
ArgumentNullException.ThrowIfNull(condition2);
Verify.ArgNotNull(condition1);
Verify.ArgNotNull(condition2);

_condition1 = condition1;
_condition2 = condition2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
#if NET

using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions.Chronology;

namespace TUnit.Assertions.AssertionBuilders.Wrappers;
Expand All @@ -19,4 +21,6 @@ public DateOnlyEqualToAssertionBuilderWrapper WithinDays(int days, [CallerArgume

return this;
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
#if NET

using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions.Chronology;

namespace TUnit.Assertions.AssertionBuilders.Wrappers;
Expand All @@ -19,4 +21,6 @@ public TimeOnlyEqualToAssertionBuilderWrapper Within(TimeSpan tolerance, [Caller

return this;
}
}
}

#endif
2 changes: 1 addition & 1 deletion TUnit.Assertions/AssertionScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Dispose()
// In which case it should just throw itself, so we don't need to do that
if (_exceptions.Count == 1)
{
ExceptionDispatchInfo.Throw(_exceptions[0]);
ExceptionDispatchInfo.Capture(_exceptions[0]).Throw();
}

if (_exceptions.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TUnit.Assertions.AssertConditions.Chronology;
#if NET

namespace TUnit.Assertions.AssertConditions.Chronology;

public class DateOnlyEqualsExpectedValueAssertCondition(DateOnly expected) : ExpectedValueAssertCondition<DateOnly, DateOnly>(expected)
{
Expand Down Expand Up @@ -37,4 +39,6 @@ public void SetTolerance(int toleranceDays)
{
_tolerance = toleranceDays;
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TUnit.Assertions.AssertConditions.Chronology;
#if NET

namespace TUnit.Assertions.AssertConditions.Chronology;

public class TimeOnlyEqualsExpectedValueAssertCondition(TimeOnly expected) : ExpectedValueAssertCondition<TimeOnly, TimeOnly>(expected)
{
Expand Down Expand Up @@ -37,4 +39,6 @@ public void SetTolerance(TimeSpan tolerance)
{
_tolerance = tolerance;
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable disable

#if NET

using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Chronology;
Expand Down Expand Up @@ -49,4 +51,6 @@ public static InvokableValueAssertionBuilder<DateOnly> IsBeforeOrEqualTo(this IV
$"to be before or equal to {expected}")
, [doNotPopulateThisValue]);
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable disable

#if NET

using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Chronology;
Expand Down Expand Up @@ -63,4 +65,6 @@ public static InvokableValueAssertionBuilder<TimeOnly> IsBeforeOrEqualTo(this IV
$"be before or equal to {expected}")
, [doNotPopulateThisValue]);
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EnumerableEquivalentToExpectedValueAssertCondition<TActual, TInner>
: ExpectedValueAssertCondition<TActual, IEnumerable<TInner>>(expected)
where TActual : IEnumerable<TInner>?
{
protected override string GetExpectation() => $"to be equivalent to {(expected != null ? string.Join(',', expected) : null)}";
protected override string GetExpectation() => $"to be equivalent to {(expected != null ? string.Join(",", expected) : null)}";

protected override AssertionResult GetResult(TActual? actualValue, IEnumerable<TInner>? expectedValue)
{
Expand Down Expand Up @@ -38,7 +38,7 @@ protected override AssertionResult GetResult(TActual? actualValue, IEnumerable<T
() => "it is not null")
.OrFailIf(
() => !orderedActual!.SequenceEqual(expectedValue!, equalityComparer),
() => $"it is {string.Join(',', orderedActual!)}"
() => $"it is {string.Join(",", orderedActual!)}"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class EnumerableNotEquivalentToExpectedValueAssertCondition<TActual, TInn
: ExpectedValueAssertCondition<TActual, IEnumerable<TInner>>(expected)
where TActual : IEnumerable<TInner>?
{
protected override string GetExpectation() => $" to be not equivalent to {(expected != null ? string.Join(',', expected) : null)}";
protected override string GetExpectation() => $" to be not equivalent to {(expected != null ? string.Join(",", expected) : null)}";

protected override AssertionResult GetResult(TActual? actualValue, IEnumerable<TInner>? expectedValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static InvokableValueAssertionBuilder<TDictionary> ContainsKey<TDictionar
return valueSource.RegisterAssertion(new FuncValueAssertCondition<TDictionary, TKey>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return actual.Keys.Cast<TKey>().Contains(expected, equalityComparer);
},
(_, _, _) => $"The key \"{expected}\" was not found in the dictionary",
Expand All @@ -30,7 +30,7 @@ public static InvokableValueAssertionBuilder<TDictionary> ContainsValue<TDiction
return valueSource.RegisterAssertion(new FuncValueAssertCondition<TDictionary, TValue>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return actual.Values.Cast<TValue>().Contains(expected, equalityComparer);
},
(_, _, _) => $"The value \"{expected}\" was not found in the dictionary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static InvokableValueAssertionBuilder<TDictionary> DoesNotContainKey<TDic
return valueSource.RegisterAssertion(new FuncValueAssertCondition<TDictionary, TKey>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return !actual.Keys.Cast<TKey>().Contains(expected, equalityComparer);
},
(_, _, _) => $"The key \"{expected}\" was found in the dictionary",
Expand All @@ -30,7 +30,7 @@ public static InvokableValueAssertionBuilder<TDictionary> DoesNotContainValue<TD
return valueSource.RegisterAssertion(new FuncValueAssertCondition<TDictionary, TValue>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return !actual.Values.Cast<TValue>().Contains(expected, equalityComparer);
},
(_, _, _) => $"The value \"{expected}\" was found in the dictionary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ protected override Task<AssertionResult> GetResult(TActual? actualValue, Excepti
.FailIf(() => actualValue is null,
() => "actual is null")
.OrFailIf(
() => !actualValue!.GetType().IsAssignableTo(expectedType),
() => !expectedType.IsAssignableFrom(actualValue!.GetType()),
() => $"it is {ActualValue?.GetType().Name ?? "null"}");
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using TUnit.Assertions.AssertConditions;
#if !NET
#pragma warning disable CS8604 // Possible null reference argument.
#endif
using TUnit.Assertions.AssertConditions;

namespace TUnit.Assertions.Assertions.Generics.Conditions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
{
MembersToIgnore = [.._ignoredMembers]
})),
() => $"it is {string.Join(',', actualEnumerable)}");
() => $"it is {string.Join(",", actualEnumerable)}");
}

bool? isEqual = null;
Expand Down Expand Up @@ -78,7 +78,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
}

return FailWithMessage($"""
{firstFailure.Type} {string.Join('.', firstFailure.NestedMemberNames)} did not match
{firstFailure.Type} {string.Join(".", firstFailure.NestedMemberNames)} did not match
Expected: {Formatter.Format(firstFailure.Expected)}
Received: {Formatter.Format(firstFailure.Actual)}
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ protected override Task<AssertionResult> GetResult(TActual? actualValue, Excepti
.FailIf(() => actualValue is null,
() => "actual is null")
.OrFailIf(
() => actualValue!.GetType().IsAssignableTo(expectedType),
() => expectedType.IsAssignableFrom(actualValue!.GetType()),
() => $"it is {ActualValue?.GetType().Name ?? "null"}");
}
6 changes: 5 additions & 1 deletion TUnit.Assertions/Assertions/Numbers/NumberIsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable disable

#if NET

using System.Numerics;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
Expand Down Expand Up @@ -134,4 +136,6 @@ public static InvokableValueAssertionBuilder<TActual> IsPositive<TActual>(
$"to be positive")
, []);
}
}
}

#endif
6 changes: 5 additions & 1 deletion TUnit.Assertions/Assertions/Numbers/NumberIsNotExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable disable

#if NET

using System.Numerics;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
Expand Down Expand Up @@ -201,4 +203,6 @@ public static InvokableValueAssertionBuilder<TActual> IsNotPositive<TActual>(thi
$"to not be positive")
, []);
}
}
}

#endif
4 changes: 2 additions & 2 deletions TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static InvokableValueAssertionBuilder<string> EndsWith(this IValueSource<
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, string>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return actual.EndsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does not end with \"{expected}\"",
Expand All @@ -77,7 +77,7 @@ public static InvokableValueAssertionBuilder<string> Matches(this IValueSource<s
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, Regex>(regex,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return regex.IsMatch(actual);
},
(actual, _, _) => $"The regex \"{regex}\" does not match with \"{actual}\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static InvokableValueAssertionBuilder<string> DoesNotStartWith(this IValu
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, string>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return !actual.StartsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does start with \"{expected}\"",
Expand All @@ -50,7 +50,7 @@ public static InvokableValueAssertionBuilder<string> DoesNotEndWith(this IValueS
return valueSource.RegisterAssertion(new FuncValueAssertCondition<string, string>(expected,
(actual, _, _) =>
{
ArgumentNullException.ThrowIfNull(actual);
Verify.ArgNotNull(actual);
return !actual.EndsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does end with \"{expected}\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override Task<AssertionResult> GetResult(TActual? actualValue, Excepti
() => exception is null,
() => "none was thrown")
.OrFailIf(
() => !exception!.GetType().IsAssignableTo(typeof(TExpectedException)),
() => !typeof(TExpectedException).IsAssignableFrom(exception!.GetType()),
() => $"{exception?.GetType().Name.PrependAOrAn()} was thrown"
);
}
Loading

0 comments on commit ba75168

Please sign in to comment.