How devlooped/moq works
Moq is a .NET mocking framework: test authors create mocks, configure member behavior and argument matching, exercise the mocked object, then verify recorded calls. Static source generation supplies mock implementations and typed setups; a dynamic-proxy factory is also present. The SDK runtime owns invocation state and matching behavior pipelines. The README documents typed setups, recursive and ref/out setups, events, callbacks, strict/loose behavior, and verification. Some subsystem links rely on README or SOURCE INDEX references because their implementation excerpts were not provided.
Main entry points: Syntax.cs Setup Syntax · DefaultMockRuntime.cs Default Mock Runtime · Mock.cs Mock Factories · SetupFactory.cs Setup Factory
Components 20
Mocking API
- Mock Factories
src/Moq.Package/Mock.cs - Setup Syntax
src/Moq/Syntax.cs - Setup Factory
src/Moq/SetupFactory.cs - Setup Contract
src/Moq/ISetup.cs - Argument Matchers
src/Moq.Sdk/AnyMatcher.cs - Behavior Extensions
src/Moq/ConfigurePipelineBehavior.cs - Verification
src/Moq/Verify.cs
Mock Generation
- Static Proxy Generator
src/Moq.StaticProxy/MockGenerator.cs - Proxy Emission
src/Moq.StaticProxy/CSharpMocked.cs - Typed Setup Generator
src/Moq.CodeAnalysis/MockSetupGenerator.cs - Setup Renderer
src/Moq.CodeAnalysis/MockSetupRenderer.cs - Dynamic Proxy Factory
src/Moq.DynamicProxy/DynamicMockFactory.cs
Mock Runtime
- Default Mock Runtime
src/Moq.Sdk/DefaultMockRuntime.cs - Runtime Contract
src/Moq.Sdk/IMockRuntime.cs - Setup Model
src/Moq.Sdk/MockSetup.cs - Behavior Pipeline
src/Moq.Sdk/MockBehaviorPipeline.cs - Mock State
src/Moq.Sdk/StateBag.cs
IDE Tooling
- Setup Code Fixes
src/Moq.CodeFixes/CustomDelegateCodeFix.cs
Other components
- Test Author
- Test Project
Connections 21
- Test Author → Mock Factories: creates mock
- Mock Factories → Dynamic Proxy Factory: creates dynamically
src/Moq.Package/Mock.cs - Mock Factories → Static Proxy Generator: uses generated proxy
src/Moq.Package/Mock`1.Overloads.cs - Static Proxy Generator → Proxy Emission: delegates emission
src/Moq.StaticProxy/MockGenerator.cs - Test Project → Typed Setup Generator: compiles typed setups
- Typed Setup Generator → Setup Renderer: renders setups
src/Moq.CodeAnalysis/MockSetupGenerator.cs - Test Author → Setup Syntax: configures members
- Setup Syntax → Setup Factory: captures invocation
src/Moq/Syntax.cs - Setup Factory → Setup Model: builds setup
src/Moq/SetupFactory.cs - Setup Syntax → Argument Matchers: accepts matchers
src/Moq/Syntax.cs - Test Author → Behavior Extensions: sets return behavior
- Behavior Extensions → Default Mock Runtime: configures runtime
src/Moq/ConfigurePipelineBehavior.cs - Setup Model → Behavior Pipeline: matches invocations
src/Moq.Sdk/MockBehaviorPipeline.cs - Default Mock Runtime → Behavior Pipeline: executes pipelines
src/Moq.Sdk/DefaultMockRuntime.cs - Default Mock Runtime → Mock State: maintains state
src/Moq.Sdk/DefaultMockRuntime.cs - Default Mock Runtime → Runtime Contract: implements contract
src/Moq.Sdk/DefaultMockRuntime.cs - Test Author → Verification: verifies calls
- Verification → Runtime Contract: reads invocations
src/Moq/Verify.cs - Test Author → Setup Code Fixes: requests delegate fix
- Setup Code Fixes → Setup Syntax: generates setup syntax
src/Moq.CodeFixes/CustomDelegateCodeFix.cs - Setup Syntax → Setup Contract: returns setup API
src/Moq/Syntax.cs