forked from microsoft/vstest
/
TestExtensionPluginInformation.cs
90 lines (79 loc) · 2.84 KB
/
TestExtensionPluginInformation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
/// <summary>
/// The test extension plugin information.
/// </summary>
internal abstract class TestExtensionPluginInformation : TestPluginInformation
{
/// <summary>
/// Default constructor
/// </summary>
/// <param name="type"> The test Logger Type. </param>
public TestExtensionPluginInformation(Type type)
: base(type)
{
if (type != null)
{
this.ExtensionUri = GetExtensionUri(type);
}
}
/// <summary>
/// Gets data value identifying the test plugin
/// </summary>
public override string IdentifierData
{
get
{
return this.ExtensionUri;
}
}
/// <summary>
/// Metadata for the test plugin
/// </summary>
public override ICollection<object> Metadata
{
get
{
return new object[] { this.ExtensionUri };
}
}
/// <summary>
/// Gets the Uri identifying the test extension.
/// </summary>
public string ExtensionUri
{
get;
private set;
}
/// <summary>
/// Helper to get the Uri from the ExtensionUriAttribute on logger plugin.
/// </summary>
/// <param name="testLoggerType">Data type of the test logger</param>
/// <returns>Uri identifying the test logger</returns>
private static string GetExtensionUri(Type testLoggerType)
{
string extensionUri = string.Empty;
object[] attributes = testLoggerType.GetTypeInfo().GetCustomAttributes(typeof(ExtensionUriAttribute), false).ToArray();
if (attributes != null && attributes.Length > 0)
{
ExtensionUriAttribute extensionUriAttribute = (ExtensionUriAttribute)attributes[0];
if (!string.IsNullOrEmpty(extensionUriAttribute.ExtensionUri))
{
extensionUri = extensionUriAttribute.ExtensionUri;
}
}
if (EqtTrace.IsErrorEnabled && string.IsNullOrEmpty(extensionUri))
{
EqtTrace.Error("The type \"{0}\" defined in \"{1}\" does not have ExtensionUri attribute.", testLoggerType.ToString(), testLoggerType.GetTypeInfo().Module.Name);
}
return extensionUri;
}
}
}