GraphQL.AspNet.TestFramework 2.0.0-beta1

This is a prerelease version of GraphQL.AspNet.TestFramework.
dotnet add package GraphQL.AspNet.TestFramework --version 2.0.0-beta1                
NuGet\Install-Package GraphQL.AspNet.TestFramework -Version 2.0.0-beta1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GraphQL.AspNet.TestFramework" Version="2.0.0-beta1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GraphQL.AspNet.TestFramework --version 2.0.0-beta1                
#r "nuget: GraphQL.AspNet.TestFramework, 2.0.0-beta1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GraphQL.AspNet.TestFramework as a Cake Addin
#addin nuget:?package=GraphQL.AspNet.TestFramework&version=2.0.0-beta1&prerelease

// Install GraphQL.AspNet.TestFramework as a Cake Tool
#tool nuget:?package=GraphQL.AspNet.TestFramework&version=2.0.0-beta1&prerelease                

GraphQL ASP.NET Test Framework

General Documentation

Test Framework Documentation

GraphQL ASP.NET is a fully featured graphql library that utilizes a controller/action programming model similar to ASP.NET. This library is a 1st party test framework to allow you quickly spin up a test server and test your controller methods in an isolated manner.

// Excute a simple Test against a controller method
public async Task WhenGivenTwoNumbers_TheSumIsReturned()
{
    // **Arrange**
    var expectedOutput = @"{ 
        ""data"" : {
            ""addTwoNumbers"": 13
        }
    }"

    // generate a 'server' of a schema with one controller
    var server = new TestServerBuilder()
                    .AddController<CalculatorController>()
                    .Build();

    // build a request to send to the server
    var queryBuilder = server.CreateQueryContextBuilder();
    queryBuilder.AddQueryText("query { addTwoNumbers(num1: 5, num2: 8) }");

    // **Act**
    var jsonResult = await server.RenderResult(queryBuilder);

    // **Assert**
    CommonAssertions.AreEqualJsonStrings(expectedOutput, jsonResult);    
}

Supported Features

  • Setup specific authentication and authorization scenarios to test security.
  • Mock and inject any dependencies for your controllers.
  • Interrogate the IQueryExecutionResult object for specific data, messages, metrics or thrown exceptions.
  • Render the resultant json document that would be sent to the requestor.

Read the documentation for full details

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0-beta1 224 11/26/2023
1.4.2 424 10/21/2024
1.4.1 2,061 7/9/2024
1.4.0 97 7/7/2024
1.3.2 3,601 3/10/2024
1.3.1 3,459 12/20/2023
1.3.0 342 11/24/2023
1.2.7 1,592 10/8/2023
1.2.6 394 9/10/2023
1.2.5 213 8/27/2023
1.2.4 1,983 7/30/2023
1.2.3 666 6/10/2023