Home

Awesome

build

Ridge

Ridge is a source generator that creates strongly typed HTTP clients for integration tests. HTTP clients generated by Ridge require the WebApplicationFactory. The use of the WebApplicationFactory allows Ridge to access internal components of ASP.NET and analyze them. This significantly improves route generation and allows implicit support of areas, routing without attributes, and so on.

Ridge supports .NET 6 and newer.

Quick links

Example

// --------------------------------------------ExampleController.cs-------------------------------------------------
[GenerateClient] // Notice the attribute
public class ExamplesController : Controller
{
    [HttpGet("ReturnGivenNumber")]
    public ActionResult<int> ReturnGivenNumber(
        [FromQuery] int input)
    {
        return input;
    }
}


// ------------------------------------------Test.cs----------------------------------------------------------------
[Test]
public async Task CallControllerUsingRidge()
{
    using var webApplicationFactory = 
        new WebApplicationFactory<Program>()
            .WithRidge(); // add ridge dependencies to WebApplicationFactory
    var client = webApplicationFactory.CreateClient();
    // create instance of client generated by source generator
    var examplesControllerClient = new ExamplesControllerClient(client, webApplicationFactory.Services); 

    var response = await examplesControllerClient.ReturnGivenNumber(10);
    
    Assert.True(response.IsSuccessStatusCode);
    Assert.AreEqual(10, response.Result);
}

Setup

Hint: Use package RidgeDotNet.AspNetCore in your AspNetCore project instead of RidgeDotNet. RidgeDotNet.AspNetCore has minimal dependencies, preventing unnecessary test code in your project.

Best practices

Wiki

Full documentation can be found in the wiki.

Features that are not currently supported

Note that you can always fall back to WebApplicationFactory when you need to test something that is not supported by Ridge.

Mappings that are not supported by default

Ridge supports a wide range of parameter mappings, but some special cases are currently not supported by default. Known unsupported mappings are the following:

Example of [FromQuery] with an array of complex arguments:

public virtual ActionResult NotSupported([FromQuery] IEnumerable<ComplexArgument> complexArguments)
{
   //..
}

Example of complex types with [FromXXX] attributes on properties:

public virtual ActionResult NotSupported(Mixed mixed)
{
   //..
}


public class Mixed
{
    [FromBody]
    public string BodyName { get; set; }
    [FromHeader]
    public string HeaderName { get; set; }
}

If you need to use this feature then consider writing custom HttpRequestFactoryMiddleware or creating an issue.

Contributions

Icon made by Freepik from www.flaticon.com.