Skip to content

Commit

Permalink
Updated Fusion-vnext test projects to use xUnit v3 instead of TUnit (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Dec 18, 2024
1 parent 91b8977 commit 61f1f59
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 434 deletions.
18 changes: 12 additions & 6 deletions src/HotChocolate/Fusion-vnext/test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>$(OutputPath)coverage.cobertura.xml</CoverletOutput>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<CollectCoverage>true</CollectCoverage>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
<CoverletOutput>$(OutputPath)coverage.cobertura.xml</CoverletOutput>
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
</PropertyGroup>

<ItemGroup>
<Using Include="CookieCrumble" />
<Using Include="CookieCrumble.TUnit" />
<Using Include="CookieCrumble.Xunit3" />
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\CookieCrumble\src\CookieCrumble.TUnit\CookieCrumble.TUnit.csproj" />
<ProjectReference Include="..\..\..\..\CookieCrumble\src\CookieCrumble.Xunit3\CookieCrumble.Xunit3.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TUnit" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace HotChocolate.Composition.PreMergeValidation.Rules;

public sealed class DisallowedInaccessibleElementsRuleTests
{
[Test]
[MethodDataSource(nameof(ValidExamplesData))]
public async Task Examples_Valid(string[] sdl)
[Theory]
[MemberData(nameof(ValidExamplesData))]
public void Examples_Valid(string[] sdl)
{
// arrange
var log = new CompositionLog();
Expand All @@ -21,13 +21,13 @@ public async Task Examples_Valid(string[] sdl)
var result = preMergeValidator.Validate(context);

// assert
await Assert.That(result.IsSuccess).IsTrue();
await Assert.That(log.IsEmpty).IsTrue();
Assert.True(result.IsSuccess);
Assert.True(log.IsEmpty);
}

[Test]
[MethodDataSource(nameof(InvalidExamplesData))]
public async Task Examples_Invalid(string[] sdl)
[Theory]
[MemberData(nameof(InvalidExamplesData))]
public void Examples_Invalid(string[] sdl)
{
// arrange
var log = new CompositionLog();
Expand All @@ -38,89 +38,95 @@ public async Task Examples_Invalid(string[] sdl)
var result = preMergeValidator.Validate(context);

// assert
await Assert.That(result.IsFailure).IsTrue();
await Assert.That(log.Count()).IsEqualTo(1);
await Assert.That(log.First().Code).IsEqualTo("DISALLOWED_INACCESSIBLE");
await Assert.That(log.First().Severity).IsEqualTo(LogSeverity.Error);
Assert.True(result.IsFailure);
Assert.Single(log);
Assert.Equal("DISALLOWED_INACCESSIBLE", log.First().Code);
Assert.Equal(LogSeverity.Error, log.First().Severity);
}

public static IEnumerable<Func<string[]>> ValidExamplesData()
public static TheoryData<string[]> ValidExamplesData()
{
return
[
return new TheoryData<string[]>
{
// Here, the String type is not marked as @inaccessible, which adheres to the rule.
() =>
[
"""
type Product {
price: Float
name: String
}
"""
]
];
{
[
"""
type Product {
price: Float
name: String
}
"""
]
}
};
}

public static IEnumerable<Func<string[]>> InvalidExamplesData()
public static TheoryData<string[]> InvalidExamplesData()
{
return
[
return new TheoryData<string[]>
{
// In this example, the String scalar is marked as @inaccessible. This violates the rule
// because String is a required built-in type that cannot be inaccessible.
() =>
[
"""
scalar String @inaccessible
{
[
"""
scalar String @inaccessible
type Product {
price: Float
name: String
}
"""
],
type Product {
price: Float
name: String
}
"""
]
},
// In this example, the introspection type __Type is marked as @inaccessible. This
// violates the rule because introspection types must remain accessible for GraphQL
// introspection queries to work.
() =>
[
"""
type __Type @inaccessible {
kind: __TypeKind!
name: String
fields(includeDeprecated: Boolean = false): [__Field!]
}
"""
],
{
[
"""
type __Type @inaccessible {
kind: __TypeKind!
name: String
fields(includeDeprecated: Boolean = false): [__Field!]
}
"""
]
},
// Inaccessible introspection field.
() =>
[
"""
type __Type {
kind: __TypeKind! @inaccessible
name: String
fields(includeDeprecated: Boolean = false): [__Field!]
}
"""
],
{
[
"""
type __Type {
kind: __TypeKind! @inaccessible
name: String
fields(includeDeprecated: Boolean = false): [__Field!]
}
"""
]
},
// Inaccessible introspection argument.
() =>
[
"""
type __Type {
kind: __TypeKind!
name: String
fields(includeDeprecated: Boolean = false @inaccessible): [__Field!]
}
"""
],
{
[
"""
type __Type {
kind: __TypeKind!
name: String
fields(includeDeprecated: Boolean = false @inaccessible): [__Field!]
}
"""
]
},
// Inaccessible built-in directive argument.
() =>
[
"""
directive @skip(if: Boolean! @inaccessible)
on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"""
]
];
{
[
"""
directive @skip(if: Boolean! @inaccessible)
on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"""
]
}
};
}
}
Loading

0 comments on commit 61f1f59

Please sign in to comment.