Skip to content

Commit 24f2b9d

Browse files
committed
First step removing ReflectionUtility
1 parent a2c4911 commit 24f2b9d

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/Adapter/MSTestAdapter.PlatformServices/Services/TestDeployment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if !WINDOWS_UWP && !WIN_UI
55

66
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
910
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
@@ -34,7 +35,7 @@ internal sealed class TestDeployment : ITestDeployment
3435
/// Initializes a new instance of the <see cref="TestDeployment"/> class.
3536
/// </summary>
3637
public TestDeployment()
37-
: this(new DeploymentItemUtility(new ReflectionUtility()), new DeploymentUtility(), new FileUtility())
38+
: this(new DeploymentItemUtility(ReflectHelper.Instance), new DeploymentUtility(), new FileUtility())
3839
{
3940
}
4041

src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentItemUtility.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if !WINDOWS_UWP && !WIN_UI
55

6+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
67
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
78
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -14,8 +15,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti
1415
/// </summary>
1516
internal sealed class DeploymentItemUtility
1617
{
17-
// REVIEW: it would be better if this was a ReflectionHelper, because helper is able to cache. But we don't have reflection helper here, because this is platform services dll.
18-
private readonly ReflectionUtility _reflectionUtility;
18+
private readonly ReflectHelper _reflectHelper;
1919

2020
/// <summary>
2121
/// A cache for class level deployment items.
@@ -25,10 +25,10 @@ internal sealed class DeploymentItemUtility
2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="DeploymentItemUtility"/> class.
2727
/// </summary>
28-
/// <param name="reflectionUtility"> The reflect helper. </param>
29-
internal DeploymentItemUtility(ReflectionUtility reflectionUtility)
28+
/// <param name="reflectHelper"> The reflect helper. </param>
29+
internal DeploymentItemUtility(ReflectHelper reflectHelper)
3030
{
31-
_reflectionUtility = reflectionUtility;
31+
_reflectHelper = reflectHelper;
3232
_classLevelDeploymentItems = [];
3333
}
3434

@@ -42,9 +42,7 @@ internal IList<DeploymentItem> GetClassLevelDeploymentItems(Type type, ICollecti
4242
{
4343
if (!_classLevelDeploymentItems.TryGetValue(type, out IList<DeploymentItem>? value))
4444
{
45-
IReadOnlyList<object> deploymentItemAttributes = _reflectionUtility.GetCustomAttributes(
46-
type,
47-
typeof(DeploymentItemAttribute));
45+
IEnumerable<DeploymentItemAttribute> deploymentItemAttributes = _reflectHelper.GetAttributes<DeploymentItemAttribute>(type);
4846
value = GetDeploymentItems(deploymentItemAttributes, warnings);
4947
_classLevelDeploymentItems[type] = value;
5048
}
@@ -61,7 +59,7 @@ internal IList<DeploymentItem> GetClassLevelDeploymentItems(Type type, ICollecti
6159
internal KeyValuePair<string, string>[]? GetDeploymentItems(MethodInfo method, IEnumerable<DeploymentItem> classLevelDeploymentItems,
6260
ICollection<string> warnings)
6361
{
64-
List<DeploymentItem> testLevelDeploymentItems = GetDeploymentItems(_reflectionUtility.GetCustomAttributes(method, typeof(DeploymentItemAttribute)), warnings);
62+
List<DeploymentItem> testLevelDeploymentItems = GetDeploymentItems(_reflectHelper.GetAttributes<DeploymentItemAttribute>(method), warnings);
6563

6664
return ToKeyValuePairs(Concat(testLevelDeploymentItems, classLevelDeploymentItems));
6765
}
@@ -174,11 +172,11 @@ private static bool IsInvalidPath(string path)
174172
return false;
175173
}
176174

177-
private static List<DeploymentItem> GetDeploymentItems(IEnumerable deploymentItemAttributes, ICollection<string> warnings)
175+
private static List<DeploymentItem> GetDeploymentItems(IEnumerable<DeploymentItemAttribute> deploymentItemAttributes, ICollection<string> warnings)
178176
{
179177
var deploymentItems = new List<DeploymentItem>();
180178

181-
foreach (DeploymentItemAttribute deploymentItemAttribute in deploymentItemAttributes.Cast<DeploymentItemAttribute>())
179+
foreach (DeploymentItemAttribute deploymentItemAttribute in deploymentItemAttributes)
182180
{
183181
if (IsValidDeploymentItem(deploymentItemAttribute.Path, deploymentItemAttribute.OutputDirectory, out string? warning))
184182
{

src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtilityBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if !WINDOWS_UWP && !WIN_UI
55

66
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
910

@@ -25,7 +26,7 @@ internal abstract class DeploymentUtilityBase
2526
protected const string DeploymentFolderPrefix = "Deploy";
2627

2728
public DeploymentUtilityBase()
28-
: this(new DeploymentItemUtility(new ReflectionUtility()), new AssemblyUtility(), new FileUtility())
29+
: this(new DeploymentItemUtility(ReflectHelper.Instance), new AssemblyUtility(), new FileUtility())
2930
{
3031
}
3132

0 commit comments

Comments
 (0)