The core library for the Mach.Testing framework, providing the foundational components for scenario-based testing.
Mach.Testing.Core contains the base classes and interfaces that power both the strongly-typed and dynamic testing scenarios. This library is typically consumed through the higher-level Mach.Testing or Mach.Testing.Dynamic packages.
- ScenarioBase: The foundation class for all scenario types, providing context management and AutoFixture integration
- IContract: Marker interface for defining strongly-typed test contracts
- GivenStepCollection: Manages and executes Given steps in scenarios
- ThenAssertionCollection: Manages and executes Then assertions in scenarios
- ScenarioBaseExtensions: Extension methods for scenario workflow management
- Automatic Dependency Injection: Built-in AutoFixture container with AutoMoq support
- Async Context Management: Thread-safe scenario execution with AsyncLocal storage
- Flexible Step Management: Collections for organizing Given and Then steps
- Container Access: Static access to the current scenario's dependency container
- AutoFixture 4.18.1: For dependency injection and test data generation
- AutoFixture.AutoMoq 4.18.1: For automatic mocking support
- System.ComponentModel.TypeConverter 4.1.0: For type conversion utilities
- .NET 6.0
- .NET 8.0
This package is typically installed as a dependency when you install the main testing packages:
# Install the main testing library (includes Core as dependency)
dotnet add package Mach.Testing
# Or install the dynamic testing library (includes Core as dependency)
dotnet add package Mach.Testing.Dynamic
# Direct installation (if building custom testing extensions)
dotnet add package Mach.Testing.CoreThis is a foundational library. For complete usage examples, see:
- Mach.Testing - Strongly-typed scenarios
- Mach.Testing.Dynamic - Dynamic scenarios
Access the current scenario's AutoFixture container from anywhere:
// From within a scenario step
var myService = ScenarioBase<TContract>.Container.Create<IMyService>();
// Register custom dependencies
ScenarioBase<TContract>.Container.Register<IRepository>(() => new MockRepository());The core library follows these design principles:
- Separation of Concerns: Core abstractions separate from implementation details
- Extensibility: Base classes designed for extension by higher-level packages
- Thread Safety: AsyncLocal ensures scenario isolation across concurrent tests
- Immutable Workflows: Fluent API design prevents state corruption