MetalamaAPI documentationAdvanced APIMetalama.​Testing.​Unit­TestingTest­Context
Open sandboxFocus

TestContext Class

A context in which a Metalama unit test can run, configured with most required Metalama services and optionally some mocks.

Inheritance
System.Object
TestContext
Implements
System.IDisposable
Metalama.Backstage.Maintenance.ITempFileManager
Metalama.Backstage.Extensibility.IBackstageService
Metalama.Backstage.Application.IApplicationInfoProvider
Metalama.Backstage.Infrastructure.IDateTimeProvider
Namespace: Metalama.Testing.UnitTesting
Assembly: Metalama.Testing.UnitTesting.dll
Syntax
public class TestContext : Object

Constructors

Name Description
TestContext(TestContextOptions)

Initializes a new instance of the TestContext class. Tests typically do not call this constructor directly, but instead the CreateTestContext(IAdditionalServiceCollection) method.

TestContext(TestContextOptions, IAdditionalServiceCollection)

Initializes a new instance of the TestContext class and specify an optional IAdditionalServiceCollection. Tests typically do not call this constructor directly, but instead the CreateTestContext(IAdditionalServiceCollection) method.

TestContext(TestContextOptions, IAdditionalServiceCollection, String)

Properties

Name Description
BaseDirectory

Gets the directory that was specifically created for the current test and where all specific files should be stored.

CancellationToken

Gets a CancellationToken used to cancel the test in case of timeout. The timeout period is defined by the Timeout option.

ServiceProvider

Gets the ProjectServiceProvider for the current context.

Methods

Name Description
CreateCompilation(Compilation)
CreateCompilation(IReadOnlyDictionary<String, String>, String, Boolean, IEnumerable<MetadataReference>, String, Boolean)
CreateCompilation(String, String, Boolean, IEnumerable<MetadataReference>, String, Boolean)
Dispose()
Dispose(Boolean)
Finalize()
WithReferences(IEnumerable<PortableExecutableReference>)