-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e18a57
commit 353998e
Showing
7 changed files
with
233 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameTestObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.Extensions.BlameDataCollector | ||
{ | ||
using System; | ||
using System.IO; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; | ||
|
||
public class BlameTestObject | ||
{ | ||
private Guid id; | ||
private string fullyQualifiedName; | ||
private string source; | ||
private bool isCompleted; | ||
private string displayName; | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
public BlameTestObject() | ||
{ | ||
// Default constructor | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
/// <param name="fullyQualifiedName"> | ||
/// Fully qualified name of the test case. | ||
/// </param> | ||
/// <param name="executorUri"> | ||
/// The Uri of the executor to use for running this test. | ||
/// </param> | ||
/// <param name="source"> | ||
/// Test container source from which the test is discovered. | ||
/// </param> | ||
public BlameTestObject(string fullyQualifiedName, Uri executorUri, string source) | ||
{ | ||
ValidateArg.NotNullOrEmpty(fullyQualifiedName, "fullyQualifiedName"); | ||
ValidateArg.NotNull(executorUri, "executorUri"); | ||
ValidateArg.NotNullOrEmpty(source, "source"); | ||
|
||
this.Id = Guid.Empty; | ||
this.FullyQualifiedName = fullyQualifiedName; | ||
this.ExecutorUri = executorUri; | ||
this.Source = source; | ||
this.IsCompleted = false; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
/// <param name="testCase"> | ||
/// The test case | ||
/// </param> | ||
public BlameTestObject(TestCase testCase) | ||
{ | ||
this.Id = testCase.Id; | ||
this.FullyQualifiedName = testCase.FullyQualifiedName; | ||
this.ExecutorUri = testCase.ExecutorUri; | ||
this.Source = testCase.Source; | ||
this.DisplayName = testCase.DisplayName; | ||
this.IsCompleted = false; | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets or sets the id of the test case. | ||
/// </summary> | ||
public Guid Id | ||
{ | ||
get | ||
{ | ||
if (this.id == Guid.Empty) | ||
{ | ||
this.id = this.GetTestId(); | ||
} | ||
|
||
return this.id; | ||
} | ||
|
||
set | ||
{ | ||
this.id = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the fully qualified name of the test case. | ||
/// </summary> | ||
public string FullyQualifiedName | ||
{ | ||
get | ||
{ | ||
return this.fullyQualifiedName; | ||
} | ||
|
||
set | ||
{ | ||
this.fullyQualifiedName = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the Uri of the Executor to use for running this test. | ||
/// </summary> | ||
public Uri ExecutorUri | ||
{ | ||
get; set; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the test container source from which the test is discovered. | ||
/// </summary> | ||
public string Source | ||
{ | ||
get | ||
{ | ||
return this.source; | ||
} | ||
|
||
set | ||
{ | ||
this.source = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether test case is completed or not. | ||
/// </summary> | ||
public bool IsCompleted | ||
{ | ||
get | ||
{ | ||
return this.isCompleted; | ||
} | ||
|
||
set | ||
{ | ||
this.isCompleted = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the display name of the test case | ||
/// </summary> | ||
public string DisplayName | ||
{ | ||
get | ||
{ | ||
return this.displayName; | ||
} | ||
|
||
set | ||
{ | ||
this.displayName = value; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
/// <summary> | ||
/// Creates a Id of TestCase | ||
/// </summary> | ||
/// <returns>Guid test id</returns> | ||
private Guid GetTestId() | ||
{ | ||
// To generate id hash "ExecutorUri + source + Name"; | ||
string source = this.Source; | ||
try | ||
{ | ||
// If source name is malformed, GetFileName API will throw exception, so use same input malformed string to generate ID | ||
source = Path.GetFileName(source); | ||
} | ||
catch | ||
{ | ||
// do nothing | ||
} | ||
|
||
string testcaseFullName = this.ExecutorUri + source + this.FullyQualifiedName; | ||
return EqtHash.GuidFromString(testcaseFullName); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters