Skip to content

Commit 5b4966c

Browse files
committed
docs: XML Summaries for TUnit.Core/Interfaces
1 parent 9a6991c commit 5b4966c

15 files changed

+551
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines a contract for types that require asynchronous initialization before they can be used.
5+
/// </summary>
6+
/// <remarks>
7+
/// Implementations of this interface are automatically initialized by the TUnit framework when
8+
/// they are injected into test classes or used as data sources. The initialization occurs before
9+
/// any test execution that depends on the instance.
10+
/// </remarks>
311
public interface IAsyncInitializer
412
{
13+
/// <summary>
14+
/// Asynchronously initializes the instance.
15+
/// </summary>
16+
/// <returns>
17+
/// A <see cref="Task"/> representing the asynchronous initialization operation.
18+
/// </returns>
19+
/// <remarks>
20+
/// <para>
21+
/// This method is called by the TUnit framework to initialize the instance before it is used
22+
/// in test execution. The framework guarantees that this method will be called exactly once
23+
/// per instance lifecycle.
24+
/// </para>
25+
/// <para>
26+
/// Use this method to perform setup operations such as:
27+
/// <list type="bullet">
28+
/// <item><description>Connecting to databases or external services</description></item>
29+
/// <item><description>Starting in-memory servers or test containers</description></item>
30+
/// <item><description>Loading test data</description></item>
31+
/// <item><description>Preparing the object's internal state</description></item>
32+
/// </list>
33+
/// </para>
34+
/// <para>
35+
/// For cleanup operations, consider implementing <see cref="IAsyncDisposable"/> alongside this interface.
36+
/// </para>
37+
/// </remarks>
538
Task InitializeAsync();
639
}

TUnit.Core/Interfaces/IClassConstructor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22

33
namespace TUnit.Core.Interfaces;
44

5+
/// <summary>
6+
/// Defines a constructor for test classes, allowing custom instantiation strategies.
7+
/// </summary>
58
public interface IClassConstructor
69
{
10+
/// <summary>
11+
/// Creates an instance of the specified type using custom instantiation logic.
12+
/// </summary>
13+
/// <param name="type">The type to instantiate. Must have accessible public constructors.</param>
14+
/// <param name="classConstructorMetadata">Metadata containing the test session ID and builder context for the test being executed.</param>
15+
/// <returns>
16+
/// A new instance of the specified type. The implementation is responsible for resolving constructor
17+
/// parameters and dependencies.
18+
/// </returns>
19+
/// <remarks>
20+
/// This method is called by the test framework to create instances of test classes.
21+
/// It allows for custom dependency injection or specialized test class instantiation.
22+
/// Implementations can use the provided <see cref="TestBuilderContext"/> from the <paramref name="classConstructorMetadata"/>
23+
/// to access shared data and event subscriptions for the current test execution.
24+
/// </remarks>
725
object Create([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, ClassConstructorMetadata classConstructorMetadata);
826
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,68 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines an interface for accessing configuration values within the TUnit testing framework.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// The configuration system provides a way to influence test execution through external settings.
9+
/// </para>
10+
/// <para>
11+
/// Configuration values can come from various sources, including:
12+
/// <list type="bullet">
13+
/// <item><description>Command-line arguments passed to the test runner</description></item>
14+
/// <item><description>Environment variables</description></item>
15+
/// <item><description>Configuration files (like appsettings.json)</description></item>
16+
/// </list>
17+
/// </para>
18+
/// <para>
19+
/// This interface is primarily accessed through the static <see cref="TestContext.Configuration"/> property,
20+
/// making configuration values available to tests without requiring dependency injection.
21+
/// </para>
22+
/// <para>
23+
/// Configuration keys can include nested paths using a colon separator (e.g., "Section:Key").
24+
/// </para>
25+
/// </remarks>
26+
/// <example>
27+
/// <code>
28+
/// [Test]
29+
/// public async Task ConfigurationExample()
30+
/// {
31+
/// // Access a configuration value
32+
/// string? logLevel = TestContext.Configuration.Get("LogLevel");
33+
///
34+
/// // Use a nested configuration path
35+
/// string? apiUrl = TestContext.Configuration.Get("Services:ApiService:Url");
36+
///
37+
/// // Check if a feature flag is enabled
38+
/// bool isFeatureEnabled = TestContext.Configuration.Get("FeatureFlags:NewFeature") == "true";
39+
/// }
40+
/// </code>
41+
/// </example>
342
public interface IConfiguration
443
{
44+
/// <summary>
45+
/// Retrieves a configuration value from the test execution environment by key.
46+
/// </summary>
47+
/// <param name="key">The configuration key to look up.</param>
48+
/// <returns>
49+
/// The configuration value associated with the specified key, or <c>null</c> if the key is not found.
50+
/// </returns>
51+
/// <remarks>
52+
/// This method provides access to configuration values that can be set via command-line arguments,
53+
/// environment variables, or configuration files used in the test execution context.
54+
/// The configuration system is used by the TUnit testing framework to provide runtime
55+
/// configuration to tests and test infrastructure components.
56+
/// </remarks>
57+
/// <example>
58+
/// <code>
59+
/// // Accessing a configuration value in a test
60+
/// string? logLevel = TestContext.Configuration.Get("LogLevel");
61+
/// if (logLevel == "Verbose")
62+
/// {
63+
/// // Enable verbose logging for this test
64+
/// }
65+
/// </code>
66+
/// </example>
567
string? Get(string key);
668
}

TUnit.Core/Interfaces/IContext.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,45 @@
22

33
namespace TUnit.Core.Interfaces;
44

5+
/// <summary>
6+
/// Defines the core contextual capabilities for the TUnit testing framework.
7+
/// </summary>
8+
/// <remarks>
9+
/// The <see cref="IContext"/> interface provides access to output writers and logging mechanisms used
10+
/// throughout the TUnit testing pipeline. Implementations of this interface serve as a foundation
11+
/// for various context types in the testing framework, including test contexts, hook contexts,
12+
/// and discovery contexts.
13+
/// </remarks>
514
public interface IContext
615
{
16+
/// <summary>
17+
/// Gets the standard output writer for the context.
18+
/// </summary>
19+
/// <remarks>
20+
/// The output writer captures standard output messages during test execution.
21+
/// These messages can be retrieved later for verification or reporting purposes.
22+
/// </remarks>
23+
/// <value>A <see cref="TextWriter"/> instance for writing standard output.</value>
724
TextWriter OutputWriter { get; }
25+
26+
/// <summary>
27+
/// Gets the error output writer for the context.
28+
/// </summary>
29+
/// <remarks>
30+
/// The error output writer captures error messages during test execution.
31+
/// These messages can be retrieved later for verification or reporting purposes.
32+
/// </remarks>
33+
/// <value>A <see cref="TextWriter"/> instance for writing error output.</value>
834
TextWriter ErrorOutputWriter { get; }
35+
36+
/// <summary>
37+
/// Gets the default logger for the context.
38+
/// </summary>
39+
/// <remarks>
40+
/// The default logger provides a unified logging mechanism for the test execution environment.
41+
/// It uses the context's output writers to record messages at various log levels, and supports
42+
/// structured logging with properties.
43+
/// </remarks>
44+
/// <returns>A <see cref="DefaultLogger"/> instance configured for this context.</returns>
945
DefaultLogger GetDefaultLogger();
1046
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines an event receiver interface that is triggered when the first test in an assembly is about to execute.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// Implement this interface to perform assembly-level setup operations that should occur once before
9+
/// any tests in the assembly are executed. This event receiver is useful for initializing resources
10+
/// or configuring state that should be shared across all tests in the assembly.
11+
/// </para>
12+
/// <para>
13+
/// The order of execution for assembly-level events is:
14+
/// <list type="number">
15+
/// <item><see cref="IFirstTestInAssemblyEventReceiver"/> - before any tests in the assembly run</item>
16+
/// <item>Tests execute within the assembly</item>
17+
/// <item><see cref="ILastTestInAssemblyEventReceiver"/> - after all tests in the assembly have completed</item>
18+
/// </list>
19+
/// </para>
20+
/// <para>
21+
/// The <see cref="IEventReceiver.Order"/> property can be used to control the execution order
22+
/// when multiple implementations of this interface exist.
23+
/// </para>
24+
/// </remarks>
325
public interface IFirstTestInAssemblyEventReceiver : IEventReceiver
426
{
27+
/// <summary>
28+
/// Called when the first test in an assembly is about to be executed.
29+
/// </summary>
30+
/// <remarks>
31+
/// This event is triggered once per assembly before any test within that assembly starts execution.
32+
/// It can be used to perform assembly-level setup tasks such as initializing resources that should be
33+
/// available for all tests in the assembly.
34+
/// </remarks>
35+
/// <param name="context">The assembly hook context containing information about the assembly and its test classes.</param>
36+
/// <param name="testContext">The context of the first test that triggered this event.</param>
37+
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
538
ValueTask OnFirstTestInAssembly(AssemblyHookContext context, TestContext testContext);
639
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines an event receiver interface that is triggered when the first test in a class is about to execute.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// Implement this interface to perform class-level setup operations that should occur once before
9+
/// any tests in the class are executed. This event receiver is useful for initializing resources
10+
/// or configuring state that should be shared across all tests in the class.
11+
/// </para>
12+
/// <para>
13+
/// The order of execution for class-level events is:
14+
/// <list type="number">
15+
/// <item><see cref="IFirstTestInClassEventReceiver"/> - before any tests in the class run</item>
16+
/// <item>Tests execute within the class</item>
17+
/// <item><see cref="ILastTestInClassEventReceiver"/> - after all tests in the class have completed</item>
18+
/// </list>
19+
/// </para>
20+
/// <para>
21+
/// The <see cref="IEventReceiver.Order"/> property can be used to control the execution order
22+
/// when multiple implementations of this interface exist.
23+
/// </para>
24+
/// </remarks>
325
public interface IFirstTestInClassEventReceiver : IEventReceiver
426
{
27+
/// <summary>
28+
/// Called when the first test in a class is about to be executed.
29+
/// </summary>
30+
/// <remarks>
31+
/// This event is triggered once per class before any test within that class starts execution.
32+
/// It can be used to perform class-level setup tasks such as initializing resources that should be
33+
/// available for all tests in the class.
34+
/// </remarks>
35+
/// <param name="context">The class hook context containing information about the class and its test methods.</param>
36+
/// <param name="testContext">The context of the first test that triggered this event.</param>
37+
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
538
ValueTask OnFirstTestInClass(ClassHookContext context, TestContext testContext);
639
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines an event receiver interface that is triggered when the first test in a test session is about to execute.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// Implement this interface to perform test session-level setup operations that should occur once before
9+
/// any tests in the session are executed. This event receiver is useful for initializing resources
10+
/// or configuring state that should be shared across all tests in the test session.
11+
/// </para>
12+
/// <para>
13+
/// The order of execution for test session-level events is:
14+
/// <list type="number">
15+
/// <item><see cref="IFirstTestInTestSessionEventReceiver"/> - before any tests in the session run</item>
16+
/// <item>Tests execute within the test session</item>
17+
/// <item><see cref="ILastTestInTestSessionEventReceiver"/> - after all tests in the session have completed</item>
18+
/// </list>
19+
/// </para>
20+
/// <para>
21+
/// The <see cref="IEventReceiver.Order"/> property can be used to control the execution order
22+
/// when multiple implementations of this interface exist.
23+
/// </para>
24+
/// </remarks>
325
public interface IFirstTestInTestSessionEventReceiver : IEventReceiver
426
{
27+
/// <summary>
28+
/// Called when the first test in a test session is about to be executed.
29+
/// </summary>
30+
/// <remarks>
31+
/// This event is triggered once per test session before any test within that session starts execution.
32+
/// It can be used to perform test session-level setup tasks such as initializing resources that should be
33+
/// available for all tests in the session.
34+
/// </remarks>
35+
/// <param name="current">The current test session context containing information about the session and its tests.</param>
36+
/// <param name="testContext">The context of the first test that triggered this event.</param>
37+
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
538
ValueTask OnFirstTestInTestSession(TestSessionContext current, TestContext testContext);
639
}

TUnit.Core/Interfaces/IHasLoggers.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

33
namespace TUnit.Core.Interfaces;
44

5+
/// <summary>
6+
/// Defines a contract for components that maintain a collection of loggers.
7+
/// </summary>
58
public interface IHasLoggers
69
{
10+
/// <summary>
11+
/// Gets the collection of loggers available for logging operations.
12+
/// </summary>
13+
/// <remarks>
14+
/// The collection contains <see cref="TUnitLogger"/> instances that can be used
15+
/// to record messages at various log levels throughout the testing pipeline. These loggers
16+
/// provide both synchronous and asynchronous logging capabilities.
17+
/// </remarks>
18+
/// <value>
19+
/// A <see cref="List{T}"/> of <see cref="TUnitLogger"/>
20+
/// instances configured for the component.
21+
/// </value>
722
public List<TUnitLogger> Loggers { get; }
823
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
namespace TUnit.Core.Interfaces;
22

3+
/// <summary>
4+
/// Defines an event receiver interface that is triggered when the last test in an assembly has completed execution.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// Implement this interface to perform assembly-level cleanup operations that should occur once after
9+
/// all tests in the assembly have executed. This event receiver is useful for cleaning up resources
10+
/// or finalizing state that was shared across all tests in the assembly.
11+
/// </para>
12+
/// <para>
13+
/// The order of execution for assembly-level events is:
14+
/// <list type="number">
15+
/// <item><see cref="IFirstTestInAssemblyEventReceiver"/> - before any tests in the assembly run</item>
16+
/// <item>Tests execute within the assembly</item>
17+
/// <item><see cref="ILastTestInAssemblyEventReceiver"/> - after all tests in the assembly have completed</item>
18+
/// </list>
19+
/// </para>
20+
/// <para>
21+
/// The <see cref="IEventReceiver.Order"/> property can be used to control the execution order
22+
/// when multiple implementations of this interface exist.
23+
/// </para>
24+
/// </remarks>
325
public interface ILastTestInAssemblyEventReceiver : IEventReceiver
426
{
27+
/// <summary>
28+
/// Called when the last test in an assembly has completed execution.
29+
/// </summary>
30+
/// <remarks>
31+
/// This event is triggered once per assembly after all tests within that assembly have completed execution.
32+
/// It can be used to perform assembly-level cleanup tasks such as releasing resources that were
33+
/// initialized for the tests in the assembly or generating assembly-level test reports.
34+
/// </remarks>
35+
/// <param name="context">The assembly hook context containing information about the assembly and its test classes.</param>
36+
/// <param name="testContext">The context of the last test that triggered this event.</param>
37+
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
538
ValueTask OnLastTestInAssembly(AssemblyHookContext context, TestContext testContext);
639
}

0 commit comments

Comments
 (0)