Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to xUnit v3 #24

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NetCoreServer" Version="8.0.7" />
<PackageVersion Include="xunit" Version="2.9.2"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="xunit.v3" Version="1.0.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0"/>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion RyuSocks.Test.Integration/RyuSocks.Test.Integration.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand All @@ -11,7 +12,7 @@
<PackageReference Include="Docker.DotNet" />
<PackageReference Include="FluentFTP" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
3 changes: 2 additions & 1 deletion RyuSocks.Test/RyuSocks.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand All @@ -17,7 +18,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
16 changes: 13 additions & 3 deletions RyuSocks.Test/Utils/EnumDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;

namespace RyuSocks.Test.Utils
{
public class EnumDataAttribute<T> : DataAttribute
where T : struct, Enum
{
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
public override bool SupportsDiscoveryEnumeration() => true;

public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
{
foreach (T value in Enum.GetValues<T>())
T[] values = Enum.GetValues<T>();
TheoryDataRow<T>[] rows = new TheoryDataRow<T>[values.Length];

for (int i = 0; i < values.Length; i++)
{
yield return [value];
rows[i] = new TheoryDataRow<T>(values[i]);
}

return ValueTask.FromResult<IReadOnlyCollection<ITheoryDataRow>>(rows);
}
}
}
15 changes: 10 additions & 5 deletions RyuSocks.Test/Utils/RangeDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
using System.Collections.Generic;
using System.Numerics;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;

namespace RyuSocks.Test.Utils
{
Expand All @@ -26,28 +29,30 @@ public class RangeDataAttribute<T> : DataAttribute
private readonly T _max;
private readonly T[] _extraElements;

public override bool SupportsDiscoveryEnumeration() => true;

public RangeDataAttribute(T min, T max, params T[] extraElements)
{
_min = min;
_max = max;
_extraElements = extraElements;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
{
List<object> data = [];
List<TheoryDataRow<T[]>> data = [];

for (T i = _min; i < _max; i++)
{
data.Add(i);
data.Add(new TheoryDataRow<T[]>([i]));
}

foreach (T element in _extraElements)
{
data.Add(element);
data.Add(new TheoryDataRow<T[]>([element]));
}

return [[data.ToArray()]];
return ValueTask.FromResult<IReadOnlyCollection<ITheoryDataRow>>(data);
}
}
}
20 changes: 13 additions & 7 deletions RyuSocks.Test/Utils/StringDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;

namespace RyuSocks.Test.Utils
{
public class StringDataAttribute : DataAttribute
{
private const char Char = 'a';
private readonly int _min;
private readonly int _max;
private int _count;

public override bool SupportsDiscoveryEnumeration() => true;

public StringDataAttribute(int min, int max, int count)
{
_min = min;
Expand All @@ -41,9 +47,9 @@ public StringDataAttribute(int firstLength, int secondLength)
_count = 2;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
{
List<object[]> data = [];
List<TheoryDataRow<string>> data = [];
StringBuilder builder = new();
int currentMin = _min;
int currentMax = _max;
Expand All @@ -60,8 +66,8 @@ public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
isMin = false;

builder.Append('a', currentMin);
data.Add([builder.ToString()]);
builder.Append(Char, currentMin);
data.Add(new TheoryDataRow<string>(builder.ToString()));

if (!isMinReverse)
{
Expand Down Expand Up @@ -90,8 +96,8 @@ public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
isMin = true;

builder.Append('a', currentMax);
data.Add([builder.ToString()]);
builder.Append(Char, currentMax);
data.Add(new TheoryDataRow<string>(builder.ToString()));

if (!isMaxReverse)
{
Expand All @@ -118,7 +124,7 @@ public override IEnumerable<object[]> GetData(MethodInfo testMethod)
}
}

return [.. data];
return ValueTask.FromResult<IReadOnlyCollection<ITheoryDataRow>>(data);
}
}
}
Loading