Skip to content

Latest commit

 

History

History
75 lines (50 loc) · 2.8 KB

File metadata and controls

75 lines (50 loc) · 2.8 KB

Mach.Testing.Core

The core library for the Mach.Testing framework, providing the foundational components for scenario-based testing.

Overview

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.

Key Components

  • 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

Core Features

  • 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

Dependencies

  • 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

Target Frameworks

  • .NET 6.0
  • .NET 8.0

Installation

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.Core

Usage

This is a foundational library. For complete usage examples, see:

Container Access

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());

Architecture

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