Skip to content

Commit

Permalink
Update tests to xUnit.net v3
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Nov 2, 2024
1 parent f3e9383 commit 29cc2e5
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 353 deletions.
10 changes: 5 additions & 5 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Universal properties and items -->

<PropertyGroup>
<AnnotatedReferenceAssemblyVersion>8.0.6</AnnotatedReferenceAssemblyVersion>
<AnnotatedReferenceAssemblyVersion>8.0.10</AnnotatedReferenceAssemblyVersion>
<ContinuousIntegrationBuild Condition=" '$(GITHUB_ACTIONS)' == 'true' ">true</ContinuousIntegrationBuild>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down Expand Up @@ -75,11 +75,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.assert.source" Version="2.9.2" />
<PackageReference Include="xunit.core" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.43" />
<PackageReference Include="xunit.v3.assert.source" Version="0.5.0-pre.34" />
<PackageReference Include="xunit.v3.core" Version="0.5.0-pre.34" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.48" />
</ItemGroup>

</When>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>xunit.analyzers.latest.tests.$(TargetFramework)</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>xunit.analyzers.latest.tests</PackageId>
<RootNamespace>Xunit.Analyzers</RootNamespace>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void VariableArgumentsTest(double d, params int[] sq) { }

public class NumericParameter : X1010_IncompatibleValueType
{
public static readonly TheoryData<string> NumericTypes =
public static readonly IEnumerable<TheoryDataRow<string>> NumericTypes =
[
"int",
"uint",
Expand All @@ -428,10 +428,10 @@ public class NumericParameter : X1010_IncompatibleValueType
];

public static MatrixTheoryData<string, string> NumericValuesAndNumericTypes =
new(NumericValues, NumericTypes);
new(NumericValues.Select(d => d.Data), NumericTypes.Select(d => d.Data));

public static MatrixTheoryData<string, string> BoolValuesAndNumericTypes =
new(BoolValues, NumericTypes);
new(BoolValues.Select(d => d.Data), NumericTypes.Select(d => d.Data));

[Theory]
[MemberData(nameof(NumericValuesAndNumericTypes))]
Expand Down Expand Up @@ -1041,7 +1041,7 @@ public void TestMethod<T>(T[] a) { }

public class DateTimeLikeParameter : X1010_IncompatibleValueType
{
public static readonly TheoryData<string> ValidDateTimeStrings =
public static readonly IEnumerable<TheoryDataRow<string>> ValidDateTimeStrings =
[
"\"\"",
"\"2018-01-02\"",
Expand All @@ -1051,7 +1051,7 @@ public class DateTimeLikeParameter : X1010_IncompatibleValueType
];

public static MatrixTheoryData<string, string> ValueTypedArgumentsCombinedWithDateTimeLikeTypes =
new(ValueTypedValues, ["System.DateTime", "System.DateTimeOffset"]);
new(ValueTypedValues.Select(d => d.Data), ["System.DateTime", "System.DateTimeOffset"]);

[Theory]
[MemberData(nameof(ValueTypedArgumentsCombinedWithDateTimeLikeTypes))]
Expand Down Expand Up @@ -1118,7 +1118,7 @@ public void TestMethod({1} parameter) {{ }}

public class GuidParameter : X1010_IncompatibleValueType
{
public static TheoryData<string> ValidGuidStrings =
public static IEnumerable<TheoryDataRow<string>> ValidGuidStrings =
[
"\"\"",
"\"{5B21E154-15EB-4B1E-BC30-127E8A41ECA1}\"",
Expand Down Expand Up @@ -1223,19 +1223,19 @@ public class Explicit {

// Note: decimal literal 42M is not valid as an attribute argument

public static TheoryData<string> BoolValues =
public static IEnumerable<TheoryDataRow<string>> BoolValues =
[
"true",
"false"
];

public static TheoryData<string> FloatingPointValues =
public static IEnumerable<TheoryDataRow<string>> FloatingPointValues =
[
"42f",
"42d"
];

public static TheoryData<string> IntegerValues =
public static IEnumerable<TheoryDataRow<string>> IntegerValues =
[
"42",
"42L",
Expand All @@ -1247,11 +1247,11 @@ public class Explicit {
"(sbyte)42"
];

public static TheoryData<string> NumericValues =
new(((IEnumerable<string>)IntegerValues).Concat(FloatingPointValues));
public static IEnumerable<TheoryDataRow<string>> NumericValues =
IntegerValues.Concat(FloatingPointValues);

public static TheoryData<string> ValueTypedValues =
new(((IEnumerable<string>)IntegerValues).Concat(FloatingPointValues).Concat(BoolValues).Append("typeof(int)"));
public static IEnumerable<TheoryDataRow<string>> ValueTypedValues =
IntegerValues.Concat(FloatingPointValues).Concat(BoolValues).Append(new("typeof(int)"));
}

public class X1011_ExtraValue
Expand Down Expand Up @@ -1459,7 +1459,7 @@ public void TestMethod(int a, params {1}[] b) {{ }}
await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source, expected);
}

public static TheoryData<string> ValueTypes =
public static IEnumerable<TheoryDataRow<string>> ValueTypes =
[
"bool",
"int",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task IntrinsicallySerializableValue_DoesNotTrigger(
using Xunit;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var value = {0};
var defaultValue = default({1});
var nullValue = default({1}?);
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task IXunitSerializableValue_DoesNotTrigger(string type)
using Xunit.Sdk;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var value = new {0}();
var defaultValue = default({0});
var nullValue = default({0}?);
Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task IXunitSerializerValue_DoesNotTrigger(string type)
[assembly: RegisterXunitSerializer(typeof(CustomSerializer), typeof(ICustomSerialized))]
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var value = new {0}();
var defaultValue = default({0});
var nullValue = default({0}?);
Expand Down Expand Up @@ -185,7 +185,7 @@ public async Task KnownNonSerializableValue_Triggers1046(
using Xunit;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var defaultValue = default({0});
var nullValue = default({0}?);
var arrayValue = new {0}[0];
Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task KnownNonSerializableValue_Constructable_Triggers1046(string ty
using Xunit;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var value = new {0}();
yield return new TheoryDataRow({{|#0:value|}});
Expand Down Expand Up @@ -267,7 +267,7 @@ public async Task MaybeNonSerializableValue_Triggers1047(string type)
using Xunit;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var defaultValue = default({0});
var nullValue = default({0}?);
var arrayValue = new {0}[0];
Expand Down Expand Up @@ -306,7 +306,7 @@ public async Task MaybeNonSerializableValue_Constructable_Triggers1047(string ty
using Xunit;
public class MyClass {{
public IEnumerable<TheoryDataRow> MyMethod() {{
public IEnumerable<TheoryDataRowBase> MyMethod() {{
var value = new {0}();
yield return new TheoryDataRow({{|#0:value|}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public static TheoryData<string, string> InterfacesWithBaseClasses

foreach (var @interface in Interfaces)
{
result.Add(@interface, "MyLLMBRO");
result.Add(@interface, "Xunit.LongLivedMarshalByRefObject");
result.Add(@interface.Data, "MyLLMBRO");
result.Add(@interface.Data, "Xunit.LongLivedMarshalByRefObject");
}

return result;
Expand Down Expand Up @@ -173,8 +173,8 @@ public static TheoryData<string, string> InterfacesWithBaseClasses

foreach (var @interface in Interfaces)
{
result.Add(@interface, "MyLLMBRO");
result.Add(@interface, "Xunit.Sdk.LongLivedMarshalByRefObject");
result.Add(@interface.Data, "MyLLMBRO");
result.Add(@interface.Data, "Xunit.Sdk.LongLivedMarshalByRefObject");
}

return result;
Expand Down
22 changes: 11 additions & 11 deletions src/xunit.analyzers.tests/Utility/CodeAnalyzerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ static CodeAnalyzerHelper()
#if NET472
var defaultAssemblies = ReferenceAssemblies.NetFramework.Net472.Default;
#else
// Can't use ReferenceAssemblies.Net.Net80 because it's too new for Microsoft.CodeAnalysis 4.2.0
// Can't use ReferenceAssemblies.Net.Net80 because it's too new for Microsoft.CodeAnalysis 3.11.0
var defaultAssemblies =
new ReferenceAssemblies(
"net8.0",
new PackageIdentity("Microsoft.NETCore.App.Ref", "8.0.0"),
new PackageIdentity("Microsoft.NETCore.App.Ref", "8.0.10"),
Path.Combine("ref", "net8.0")
);
#endif
Expand All @@ -39,8 +39,8 @@ static CodeAnalyzerHelper()
new PackageIdentity("System.Collections.Immutable", "1.6.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("xunit.abstractions", "2.0.3"),
new PackageIdentity("xunit.assert", "2.9.2"),
new PackageIdentity("xunit.core", "2.9.2")
new PackageIdentity("xunit.assert", "2.9.3-pre.4"),
new PackageIdentity("xunit.core", "2.9.3-pre.4")
)
);

Expand All @@ -51,7 +51,7 @@ static CodeAnalyzerHelper()
new PackageIdentity("System.Collections.Immutable", "1.6.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("xunit.abstractions", "2.0.3"),
new PackageIdentity("xunit.runner.utility", "2.9.2")
new PackageIdentity("xunit.runner.utility", "2.9.3-pre.4")
)
);

Expand All @@ -61,10 +61,10 @@ static CodeAnalyzerHelper()
new PackageIdentity("Microsoft.Extensions.Primitives", "8.0.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("System.Text.Json", "8.0.0"),
new PackageIdentity("xunit.v3.assert", "0.5.0-pre.28"),
new PackageIdentity("xunit.v3.common", "0.5.0-pre.28"),
new PackageIdentity("xunit.v3.extensibility.core", "0.5.0-pre.28"),
new PackageIdentity("xunit.v3.runner.common", "0.5.0-pre.28")
new PackageIdentity("xunit.v3.assert", "0.5.0-pre.34"),
new PackageIdentity("xunit.v3.common", "0.5.0-pre.34"),
new PackageIdentity("xunit.v3.extensibility.core", "0.5.0-pre.34"),
new PackageIdentity("xunit.v3.runner.common", "0.5.0-pre.34")
)
);

Expand All @@ -74,8 +74,8 @@ static CodeAnalyzerHelper()
new PackageIdentity("Microsoft.Extensions.Primitives", "8.0.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("System.Text.Json", "8.0.0"),
new PackageIdentity("xunit.v3.common", "0.5.0-pre.28"),
new PackageIdentity("xunit.v3.runner.utility", "0.5.0-pre.28")
new PackageIdentity("xunit.v3.common", "0.5.0-pre.34"),
new PackageIdentity("xunit.v3.runner.utility", "0.5.0-pre.34")
)
);
}
Expand Down
Loading

0 comments on commit 29cc2e5

Please sign in to comment.