Skip to content

Commit 915ecee

Browse files
committed
Add GitHubWorkItem
1 parent ee172c3 commit 915ecee

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
/// <summary>
7+
/// GitHubWorkItem attribute; used to specify a GitHub issue associated with this test.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
10+
public sealed class GitHubWorkItemAttribute : WorkItemAttribute
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="GitHubWorkItemAttribute"/> class for the GitHub WorkItem Attribute.
14+
/// </summary>
15+
/// <param name="url">The URL to a GitHub issue.</param>
16+
public GitHubWorkItemAttribute(string url)
17+
: base(ExtractId(url))
18+
=> Url = url;
19+
20+
/// <summary>
21+
/// Gets the URL to the GitHub issue associated.
22+
/// </summary>
23+
public string Url { get; }
24+
25+
/// <summary>
26+
/// Extracts the ID from the GitHub issue/pull/discussion URL.
27+
/// </summary>
28+
/// <param name="url">The URL to a GitHub ticket.</param>
29+
/// <returns>The ticket ID.</returns>
30+
private static int ExtractId(string url)
31+
=> int.TryParse(url.Substring(url.LastIndexOf('/') + 1), out int id)
32+
? id
33+
: throw new ArgumentException("The URL provided is not a valid GitHub ticket URL.", nameof(url));
34+
}

src/TestFramework/TestFramework/Attributes/TestMethod/WorkItemAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
77
/// WorkItem attribute; used to specify a work item associated with this test.
88
/// </summary>
99
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
10-
public sealed class WorkItemAttribute : Attribute
10+
public class WorkItemAttribute : Attribute
1111
{
1212
/// <summary>
1313
/// Initializes a new instance of the <see cref="WorkItemAttribute"/> class for the WorkItem Attribute.

0 commit comments

Comments
 (0)