Drn testing

From duranserkan/DRN-Project · View interactive version

Drn testing is an AI agent skill from the GitHub repository duranserkan/DRN-Project. Choose DRN unit and integration data attributes, test contexts, fixtures, and MTP entry points.

How to use this skill

Skill file

DRN.Framework.Testing

Use the installed DRN.Framework.Testing package README for provider APIs and project setup. Locate the package

DTT Attribute/Context Matrix

| Data source | Unit | Integration |

|---|---|---|

| Inline rows or generated parameters | [DataInlineUnit] | [DataInline] |

| Static member | [DataMemberUnit] | [DataMember] |

| Custom attribute class | DataSelfUnitAttribute | DataSelfAttribute |

Use [Theory] with these attributes. Use [Fact] when no data, generation or context is needed.

Regression fixtures

For an HTTP integration test, substitute the application's own host entry point and route:

[Theory]
[DataInline("/health")]
public async Task Health_endpoint_succeeds(DrnTestContext context, string route)
{
    using var client = await context.ApplicationContext.CreateClientAsync<AppProgram>();
    using var response = await client.GetAsync(route);
    response.EnsureSuccessStatusCode();
}

Compiler Test Performance

Cache materialized immutable metadata references for fixed assembly inputs. Lazily emit invariant dependency fixtures once with thread-safe initialization. Preserve reference paths, assembly identity and provenance records. Keep consumer compilations, analyzer state and generator drivers isolated where a test requires a fresh run. Do not reuse a fixture whose source or options vary, or replace emitted references in tests covering metadata behavior. Preserve coverage while removing repeated setup. For compiler cache and incremental-output rules, see Roslyn guidance.

Context Capabilities

Use SettingsProvider.Development() for AppId 0 or Development<TApp>() for the declared AppId. Both default AppInstanceId to 0 and return disposable settings. Optional objects override defaults. AppId must match the selected partition.

| Context | Use for | Notable members |

|---|---|---|

| DrnTestContextUnit | unit tests without containers or full app startup | ServiceCollection, GetRequiredService<T>(), BuildConfigurationRoot(), GetData(), MethodContext.GetTempPath(), GetTempPath(), ValidateServicesAsync() |

| DrnTestContext | integration tests | all unit capabilities plus ContainerContext, ApplicationContext, FlurlHttpTest |

| ContainerContext | real dependencies | Postgres.ApplyMigrationsAsync(), Postgres.Isolated, RabbitMq, BindExternalDependenciesAsync() |

| ApplicationContext | API/E2E tests | CreateClientAsync<T>(), CreateClientForServiceAsync<T>(), CreateApplicationAndBindDependenciesAsync<T>(), MapAddress<T>(), in-memory routing via ApplicationContextRouterHandler, automatic debugger-gated logging through Xunit.TestContext.Current.TestOutputHelper |

| FlurlHttpTest | outbound HTTP mocks | ForCallsTo(...).RespondWithJson(...), ShouldHaveCalled(...) |

DrnTestContext owns its providers. ApplicationContext owns one active factory per application type and routes service calls in memory. Re-creating a type replaces only its instance and routes, using current configuration. Failed factory shutdown can be retried during disposal.

ApplicationContext.CreateClientAsync<TProgram> has one signature with the optional first parameter bool https = false. https: true defaults to https://localhost. Omitted or false defaults to HTTP. Explicit clientOptions take precedence over the flag and remain unchanged. Supply outputHelper, clientOptions, and additionalAddresses by name when omitting the flag.

Consolidation Rule

Prefer one readable test that exercises a coherent flow over many duplicate tests with the same setup. Parameterize identical bodies with multiple data rows. In integration tests, continue the same flow when assertions share container setup, migrations, or service registration. Do not combine structurally different behaviors only to reduce count.

Composed Decision Coverage

Use Modified Condition/Decision Coverage (MC/DC) for authorization, tenant isolation, soft-delete, repository filters, validation chains and feature gates. Assert exact result membership. Add interaction cases only when independent pairs cannot cover the behavior.

WebApplicationFactory Entry Points

WebApplicationFactory<TProgram> should point at a real hosted program type from the application or a non-test support assembly. Keep reusable disposable integration-test host programs in an SDK Web support project with IsTestProject=false. Discover its path from the repository profile or project references, and keep the integration-test project focused on assertions. Do not define custom hosted Program entry points inside the MTP test executable. DrnWebApplicationFactory<TProgram> automatically resolves and binds secondary IDrnProgram entry points in multi-program support assemblies, allowing any program in the assembly to be hosted in-memory via ApplicationContext.CreateClientAsync<TProgram>().

Razor Rendering

For Razor rendering helpers, cover _ViewStart, layouts and standalone pages. Verify scope disposal on successful and failing renders.

MTP commands and setup

Find the test project and target framework in the application's project files, profile or CI. Follow its command approval rules. Run MTP projects individually. Unit tests precede integration tests, which need explicit permission. Benchmarks and load tests need an explicit request.

Use an executable non-packable test project with IsTestProject and UseMicrosoftTestingPlatformRunner enabled. Copy fixture Settings and Data to the output when used. The Testing README owns the sample project and imports.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.