Skip to content

Commit bdb17b5

Browse files
committed
[rel/4.0]: Unify TestSessionContext
1 parent e8faa6a commit bdb17b5

13 files changed

+47
-35
lines changed

src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override async Task<int> InternalRunAsync(CancellationToken cancellati
5252
ITestFrameworkInvoker testAdapterInvoker = ServiceProvider.GetService<ITestFrameworkInvoker>()
5353
?? new TestHostTestFrameworkInvoker(ServiceProvider);
5454

55-
ServiceProvider.TryAddService(new Services.TestSessionContext(cancellationToken));
55+
ServiceProvider.TryAddService(new TestSessionContext(new SessionUid(Guid.NewGuid().ToString()), cancellationToken));
5656
ITestFramework testFramework = await _buildTestFrameworkAsync(new(
5757
ServiceProvider,
5858
new ConsoleTestExecutionRequestFactory(ServiceProvider.GetCommandLineOptions(), testExecutionFilterFactory),

src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionRequestFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.Testing.Platform.CommandLine;
55
using Microsoft.Testing.Platform.Helpers;
66
using Microsoft.Testing.Platform.Resources;
7-
using Microsoft.Testing.Platform.TestHost;
7+
using Microsoft.Testing.Platform.Services;
88

99
namespace Microsoft.Testing.Platform.Requests;
1010

src/Platform/Microsoft.Testing.Platform/Requests/DiscoverTestExecutionRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Testing.Platform.TestHost;
4+
using Microsoft.Testing.Platform.Services;
55

66
namespace Microsoft.Testing.Platform.Requests;
77

src/Platform/Microsoft.Testing.Platform/Requests/IRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Testing.Platform.TestHost;
4+
using Microsoft.Testing.Platform.Services;
55

66
namespace Microsoft.Testing.Platform.Requests;
77

src/Platform/Microsoft.Testing.Platform/Requests/ITestExecutionRequestFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Testing.Platform.TestHost;
4+
using Microsoft.Testing.Platform.Services;
55

66
namespace Microsoft.Testing.Platform.Requests;
77

src/Platform/Microsoft.Testing.Platform/Requests/RunTestExecutionRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using Microsoft.Testing.Platform.Services;
45
using Microsoft.Testing.Platform.TestHost;
56

67
namespace Microsoft.Testing.Platform.Requests;

src/Platform/Microsoft.Testing.Platform/Requests/ServerTestExecutionRequestFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Testing.Platform.TestHost;
4+
using Microsoft.Testing.Platform.Services;
55

66
namespace Microsoft.Testing.Platform.Requests;
77

src/Platform/Microsoft.Testing.Platform/Requests/TestExecutionRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Testing.Platform.TestHost;
4+
using Microsoft.Testing.Platform.Services;
55

66
namespace Microsoft.Testing.Platform.Requests;
77

src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task ExecuteAsync(ITestFramework testFramework, ClientInfo client,
5454
await HandleTestSessionResultAsync(createTestSessionResult.IsSuccess, createTestSessionResult.WarningMessage, createTestSessionResult.ErrorMessage, cancellationToken).ConfigureAwait(false);
5555

5656
ITestExecutionRequestFactory testExecutionRequestFactory = ServiceProvider.GetTestExecutionRequestFactory();
57-
TestExecutionRequest request = await testExecutionRequestFactory.CreateRequestAsync(new(sessionId)).ConfigureAwait(false);
57+
TestExecutionRequest request = await testExecutionRequestFactory.CreateRequestAsync(new(sessionId, cancellationToken)).ConfigureAwait(false);
5858
IMessageBus messageBus = ServiceProvider.GetMessageBus();
5959

6060
// Execute the test request

src/Platform/Microsoft.Testing.Platform/Services/TestSessionContext.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55

66
namespace Microsoft.Testing.Platform.Services;
77

8-
internal sealed class TestSessionContext(CancellationToken cancellationToken) : ITestSessionContext
8+
/// <summary>
9+
/// Represents the context of a test session.
10+
/// </summary>
11+
public sealed class TestSessionContext : ITestSessionContext
912
{
10-
public SessionUid SessionUid { get; } = new(Guid.NewGuid().ToString());
13+
internal TestSessionContext(SessionUid sessionUid, CancellationToken cancellationToken)
14+
{
15+
SessionUid = sessionUid;
16+
CancellationToken = cancellationToken;
17+
}
1118

12-
public CancellationToken CancellationToken { get; } = cancellationToken;
19+
/// <summary>
20+
/// Gets the unique identifier of the test session.
21+
/// </summary>
22+
public SessionUid SessionUid { get; }
23+
24+
/// <summary>
25+
/// Gets the cancellation token associated with the test session.
26+
/// </summary>
27+
public CancellationToken CancellationToken { get; }
1328
}

0 commit comments

Comments
 (0)