orchardcore-unit-test

Writes and runs OrchardCore xUnit, SiteContext integration, Moq, and Playwright tests.

8.2k|2.6k|Updated Nov 19, 2014
One-click install
npx skills add https://github.com/OrchardCMS/OrchardCore --skill orchardcore-unit-test
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: orchardcore-unit-test
Source: https://github.com/OrchardCMS/OrchardCore/tree/main/.agents/skills/orchardcore-unit-test
Command: npx skills add https://github.com/OrchardCMS/OrchardCore --skill orchardcore-unit-test

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing tests for OrchardCore requires knowing its specific conventions: xUnit v3 with the Microsoft Testing Platform, the SiteContext tenant harness for integration tests, Moq for mocking services, and Playwright for browser tests. This Skill guides you through choosing the right test type and writing it correctly the first time.

Core Features & Use Cases

  • Unit Tests: Create xUnit test classes with proper naming conventions, [Fact]/[Theory] attributes, and Moq-based mocking of OrchardCore services like IClock and IShellHost.
  • Integration Tests: Spin up real tenants with SiteContext, run recipes, call content APIs over HttpClient, and resolve tenant services inside UsingTenantScopeAsync.
  • Functional Tests: Drive a headless Chromium browser against a running CMS instance using OrchardTestFixture and Playwright, with optional trace capture.
  • Use Case: You added a new content API endpoint and need an integration test. The Skill shows you how to initialize a SiteContext with the Blog recipe, post a draft content item, and assert on the response.

Quick Start

Write an integration test using SiteContext that creates a draft content item through the content API and verifies it is not published.

Frequently Asked Questions about orchardcore-unit-test

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write an integration test for OrchardCore?

Use the SiteContext class to spin up a real tenant backed by SQLite, call InitializeAsync, then use its HttpClient to hit APIs or UsingTenantScopeAsync to resolve tenant services like ISession. Always dispose the context with using var.

How do I mock OrchardCore services in unit tests?

Use Moq: Mock.Of<IClock> for quick property stubs, or new Mock<IShellHost>() with Setup and Verify for method behavior. Inject mocks by building a ServiceCollection and calling BuildServiceProvider.

What test framework does OrchardCore use?

OrchardCore uses xUnit v3 via the Microsoft Testing Platform, so test projects have OutputType set to Exe. Assertions use standard xUnit Assert methods; Shouldly is not used in this repository.

How do I run only specific OrchardCore tests?

Run dotnet test against the project file with a filter, for example dotnet test test/OrchardCore.Tests/OrchardCore.Tests.csproj --filter "FullyQualifiedName~BlogPost". This works with the xUnit Microsoft Testing Platform runner.

Why must tenant services be resolved inside UsingTenantScopeAsync?

The outer test scope is not the tenant's DI scope, so resolving ISession or IContentManager outside it returns wrong or missing services. UsingTenantScopeAsync acquires the tenant's ShellScope and sets the HttpContext before running your code.

Does OrchardCore support browser-based functional testing?

Yes, OrchardCore.Tests.Functional uses Playwright with the OrchardTestFixture, which starts an in-process CMS server and a headless Chromium browser. Set the PLAYWRIGHT_TRACING environment variable to capture screenshots and snapshots into a traces folder.