Integration Test Generators

Ninjadog generates a complete integration test scaffold for your Web API, using WebApplicationFactory to spin up a real test server with an in-memory SQLite database. Each entity gets a dedicated test class exercising all CRUD endpoints.

Generated Files

Generator Scope Output
IntegrationTestCsproj Single file {ProjectName}.IntegrationTests.csproj
CustomWebApplicationFactory Single file CustomWebApplicationFactory.cs
IntegrationTestBase Single file IntegrationTestBase.cs
EntityIntegrationTest Per entity {Entity}EndpointTests.cs

Test Project (IntegrationTestCsproj)

Generates an xUnit test project referencing the main API project with the following packages:

WebApplicationFactory (CustomWebApplicationFactory)

Creates a CustomWebApplicationFactory that:

Test Base Class (IntegrationTestBase)

Provides shared infrastructure for all test classes:

Per-Entity Tests (EntityIntegrationTest)

Each entity gets 8 test methods covering the full CRUD lifecycle:

Test HTTP Method Expected Status
Create{Entity}_WithValidRequest_ReturnsCreated POST 201 Created
GetAll{Entities}_AfterCreating_ReturnsCollection GET 200 OK
Get{Entity}_WithValidId_ReturnsEntity GET 200 OK
Get{Entity}_WithInvalidId_ReturnsNotFound GET 404 Not Found
Update{Entity}_WithValidRequest_ReturnsOk PUT 200 OK
Delete{Entity}_WithValidId_ReturnsNoContent DELETE 204 No Content
Delete{Entity}_WithInvalidId_ReturnsNotFound DELETE 404 Not Found
FullCrudLifecycle_{Entity}_WorksEndToEnd All Full lifecycle

Test data is auto-generated based on entity property types:

Example Output

For a TodoItem entity with properties Title (string), IsCompleted (bool), and DueDate (DateTime):

public class TodoItemEndpointTests : IntegrationTestBase
{
    private const string BaseUrl = "/todo-items";

    public TodoItemEndpointTests(CustomWebApplicationFactory factory)
        : base(factory) { }

    [Fact]
    public async Task CreateTodoItem_WithValidRequest_ReturnsCreated()
    {
        var request = new CreateTodoItemRequest
        {
            Title = "Test Title",
            IsCompleted = false,
            DueDate = DateTime.UtcNow.AddDays(1)
        };

        var response = await Client.PostAsJsonAsync(BaseUrl, request);

        response.StatusCode.Should().Be(HttpStatusCode.Created);
        var created = await DeserializeAsync<TodoItemResponse>(response);
        created.Should().NotBeNull();
        created!.Title.Should().Be("Test Title");
    }

    // ... 7 more tests
}