Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper to handle successful and failed states #5266

Open
nohwnd opened this issue Mar 19, 2025 · 0 comments
Open

Add helper to handle successful and failed states #5266

nohwnd opened this issue Mar 19, 2025 · 0 comments
Labels
Area: MTP Belongs to the Microsoft.Testing.Platform core library

Comments

@nohwnd
Copy link
Member

nohwnd commented Mar 19, 2025

Summary

Provide common way to act on test node state, even though they are not connected by inheritance.

Background and Motivation

The code below extracts test node state property and handles all failed states, these states don't define a common interface that would allow accessing the Explanation and Exception on them. Provide a common way of handling them. Ideally one that replaces TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeFailedProperties which is an array of the states mentioned below. To avoid the two of them running out of sync.

TestNodeStateProperty nodeState = nodeUpdateMessage.TestNode.Properties.Single<TestNodeStateProperty>();

switch (nodeState)
{
    case FailedTestNodeStateProperty failed:
        await WriteExceptionAsync(failed.Explanation, failed.Exception);
        break;
    case ErrorTestNodeStateProperty error:
        await WriteExceptionAsync(error.Explanation, error.Exception);
        break;
    case CancelledTestNodeStateProperty cancelled:
        await WriteExceptionAsync(cancelled.Explanation, cancelled.Exception);
        break;
    case TimeoutTestNodeStateProperty timeout:
        await WriteExceptionAsync(timeout.Explanation, timeout.Exception);
        break;
}

Proposed Feature

Alternative Designs

@nohwnd nohwnd added the Area: MTP Belongs to the Microsoft.Testing.Platform core library label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: MTP Belongs to the Microsoft.Testing.Platform core library
Projects
None yet
Development

No branches or pull requests

1 participant