File tree 2 files changed +35
-1
lines changed
src/TestFramework/TestFramework/Attributes/TestMethod
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
7
7
/// WorkItem attribute; used to specify a work item associated with this test.
8
8
/// </summary>
9
9
[ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
10
- public sealed class WorkItemAttribute : Attribute
10
+ public class WorkItemAttribute : Attribute
11
11
{
12
12
/// <summary>
13
13
/// Initializes a new instance of the <see cref="WorkItemAttribute"/> class for the WorkItem Attribute.
You can’t perform that action at this time.
0 commit comments