Skip to content

Commit bb0f857

Browse files
committed
More test progress
1 parent 2cf62e2 commit bb0f857

4 files changed

Lines changed: 26 additions & 30 deletions

File tree

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/DesktopTestDeploymentTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if NETFRAMEWORK
55
using AwesomeAssertions;
66

7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
910
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
@@ -23,7 +24,6 @@ public class DesktopTestDeploymentTests : TestContainer
2324
private const string DefaultDeploymentItemPath = @"c:\temp";
2425
private const string DefaultDeploymentItemOutputDirectory = "out";
2526

26-
private readonly Mock<ReflectionUtility> _mockReflectionUtility;
2727
private readonly Mock<FileUtility> _mockFileUtility;
2828

2929
#pragma warning disable IDE0052 // Remove unread private members
@@ -32,7 +32,6 @@ public class DesktopTestDeploymentTests : TestContainer
3232

3333
public DesktopTestDeploymentTests()
3434
{
35-
_mockReflectionUtility = new Mock<ReflectionUtility>();
3635
_mockFileUtility = new Mock<FileUtility>();
3736
_warnings = [];
3837

@@ -149,7 +148,7 @@ private TestDeployment CreateAndSetupDeploymentRelatedUtilities(out TestRunDirec
149148
_mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.IsAny<string>(), It.IsAny<string>()))
150149
.Returns(testRunDirectories.RootDeploymentDirectory);
151150

152-
var deploymentItemUtility = new DeploymentItemUtility(_mockReflectionUtility.Object);
151+
var deploymentItemUtility = new DeploymentItemUtility(new ReflectHelper());
153152

154153
return new TestDeployment(
155154
deploymentItemUtility,

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/TestDeploymentTests.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if !WINDOWS_UWP && !WIN_UI
55
using AwesomeAssertions;
66

7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
910
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
@@ -24,7 +25,7 @@ public class TestDeploymentTests : TestContainer
2425
private const string DefaultDeploymentItemPath = @"c:\temp";
2526
private const string DefaultDeploymentItemOutputDirectory = "out";
2627

27-
private readonly Mock<ReflectionUtility> _mockReflectionUtility;
28+
private readonly Mock<ReflectHelper> _mockReflectHelper;
2829
private readonly Mock<FileUtility> _mockFileUtility;
2930

3031
#pragma warning disable IDE0044 // Add readonly modifier
@@ -33,7 +34,7 @@ public class TestDeploymentTests : TestContainer
3334

3435
public TestDeploymentTests()
3536
{
36-
_mockReflectionUtility = new Mock<ReflectionUtility>();
37+
_mockReflectHelper = new Mock<ReflectHelper>();
3738
_mockFileUtility = new Mock<FileUtility>();
3839
_warnings = [];
3940

@@ -52,7 +53,7 @@ public void GetDeploymentItemsReturnsNullWhenNoDeploymentItems()
5253
public void GetDeploymentItemsReturnsDeploymentItems()
5354
{
5455
// Arrange.
55-
var testDeployment = new TestDeployment(new DeploymentItemUtility(_mockReflectionUtility.Object), null!, null!);
56+
var testDeployment = new TestDeployment(new DeploymentItemUtility(_mockReflectHelper.Object), null!, null!);
5657

5758
// setup mocks
5859
KeyValuePair<string, string>[] methodLevelDeploymentItems =
@@ -181,7 +182,7 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeployme
181182
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray);
182183

183184
var testDeployment = new TestDeployment(
184-
new DeploymentItemUtility(_mockReflectionUtility.Object),
185+
new DeploymentItemUtility(_mockReflectHelper.Object),
185186
new DeploymentUtility(),
186187
_mockFileUtility.Object);
187188

@@ -204,7 +205,7 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseAndHasNoDeploy
204205
var testCase = new TestCase("A.C.M", new Uri("executor://testExecutor"), "path/to/asm.dll");
205206
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null);
206207
var testDeployment = new TestDeployment(
207-
new DeploymentItemUtility(_mockReflectionUtility.Object),
208+
new DeploymentItemUtility(_mockReflectHelper.Object),
208209
new DeploymentUtility(),
209210
_mockFileUtility.Object);
210211

@@ -227,7 +228,7 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploym
227228
var testCase = new TestCase("A.C.M", new Uri("executor://testExecutor"), "path/to/asm.dll");
228229
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null);
229230
var testDeployment = new TestDeployment(
230-
new DeploymentItemUtility(_mockReflectionUtility.Object),
231+
new DeploymentItemUtility(_mockReflectHelper.Object),
231232
new DeploymentUtility(),
232233
_mockFileUtility.Object);
233234

@@ -257,7 +258,7 @@ internal void DeployShouldReturnTrueWhenDeploymentEnabledSetToTrueAndHasDeployme
257258
];
258259
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray);
259260
var testDeployment = new TestDeployment(
260-
new DeploymentItemUtility(_mockReflectionUtility.Object),
261+
new DeploymentItemUtility(_mockReflectHelper.Object),
261262
new DeploymentUtility(),
262263
_mockFileUtility.Object);
263264

@@ -370,11 +371,9 @@ private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair<string, st
370371
deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
371372
}
372373

373-
_mockReflectionUtility.Setup(
374-
ru =>
375-
ru.GetCustomAttributes(
376-
memberInfo,
377-
typeof(DeploymentItemAttribute))).Returns(deploymentItemAttributes.ToArray());
374+
_mockReflectHelper
375+
.Setup(ru => ru.GetAttributes<DeploymentItemAttribute>(memberInfo))
376+
.Returns(deploymentItemAttributes.ToArray());
378377
}
379378

380379
private static TestCase GetTestCase(string source)
@@ -418,7 +417,7 @@ private TestDeployment CreateAndSetupDeploymentRelatedUtilities(out TestRunDirec
418417
_mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.IsAny<string>(), It.IsAny<string>()))
419418
.Returns(testRunDirectories.RootDeploymentDirectory);
420419

421-
var deploymentItemUtility = new DeploymentItemUtility(_mockReflectionUtility.Object);
420+
var deploymentItemUtility = new DeploymentItemUtility(_mockReflectHelper.Object);
422421

423422
return new TestDeployment(
424423
deploymentItemUtility,

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Utilities/DeploymentItemUtilityTests.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if !WINDOWS_UWP && !WIN_UI
55
using AwesomeAssertions;
66

7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources;
910
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
@@ -24,7 +25,7 @@ public class DeploymentItemUtilityTests : TestContainer
2425
TestPropertyAttributes.Hidden,
2526
typeof(TestCase));
2627

27-
private readonly Mock<ReflectionUtility> _mockReflectionUtility;
28+
private readonly Mock<ReflectHelper> _mockReflectHelper;
2829
private readonly DeploymentItemUtility _deploymentItemUtility;
2930
private readonly ICollection<string> _warnings;
3031

@@ -33,16 +34,16 @@ public class DeploymentItemUtilityTests : TestContainer
3334

3435
public DeploymentItemUtilityTests()
3536
{
36-
_mockReflectionUtility = new Mock<ReflectionUtility>();
37-
_deploymentItemUtility = new DeploymentItemUtility(_mockReflectionUtility.Object);
37+
_mockReflectHelper = new Mock<ReflectHelper>();
38+
_deploymentItemUtility = new DeploymentItemUtility(_mockReflectHelper.Object);
3839
_warnings = [];
3940
}
4041

4142
#region GetClassLevelDeploymentItems tests
4243

4344
public void GetClassLevelDeploymentItemsShouldReturnEmptyListWhenNoDeploymentItems()
4445
{
45-
_mockReflectionUtility.Setup(x => x.GetCustomAttributes(typeof(DeploymentItemUtilityTests), typeof(DeploymentItemAttribute)))
46+
_mockReflectHelper.Setup(x => x.GetAttributes<DeploymentItemAttribute>(typeof(DeploymentItemUtilityTests)))
4647
.Returns([]);
4748
IList<DeploymentItem> deploymentItems = _deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), _warnings);
4849

@@ -163,7 +164,7 @@ public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeployment
163164
public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems()
164165
{
165166
MethodInfo method = typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems")!;
166-
_mockReflectionUtility.Setup(x => x.GetCustomAttributes(method, typeof(DeploymentItemAttribute)))
167+
_mockReflectHelper.Setup(x => x.GetAttributes<DeploymentItemAttribute>(method))
167168
.Returns([]);
168169

169170
_deploymentItemUtility.GetDeploymentItems(method, null!, _warnings).Should().BeNull();
@@ -208,7 +209,7 @@ public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly()
208209
};
209210

210211
MethodInfo method = typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems")!;
211-
_mockReflectionUtility.Setup(x => x.GetCustomAttributes(method, typeof(DeploymentItemAttribute)))
212+
_mockReflectHelper.Setup(x => x.GetAttributes<DeploymentItemAttribute>(method))
212213
.Returns([]);
213214

214215
// Act.
@@ -422,11 +423,9 @@ private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair<string, st
422423
deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
423424
}
424425

425-
_mockReflectionUtility.Setup(
426-
ru =>
427-
ru.GetCustomAttributes(
428-
memberInfo,
429-
typeof(DeploymentItemAttribute))).Returns(deploymentItemAttributes.ToArray());
426+
_mockReflectHelper
427+
.Setup(ru => ru.GetAttributes<DeploymentItemAttribute>(memberInfo))
428+
.Returns(deploymentItemAttributes.ToArray());
430429
}
431430

432431
#endregion

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Utilities/DeploymentUtilityTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if !WINDOWS_UWP && !WIN_UI
55
using AwesomeAssertions;
66

7+
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
78
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
89
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources;
910
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
@@ -24,7 +25,6 @@ public class DeploymentUtilityTests : TestContainer
2425
private const string DefaultDeploymentItemPath = @"c:\temp";
2526
private const string DefaultDeploymentItemOutputDirectory = "out";
2627

27-
private readonly Mock<ReflectionUtility> _mockReflectionUtility;
2828
private readonly Mock<FileUtility> _mockFileUtility;
2929
private readonly Mock<AssemblyUtility> _mockAssemblyUtility;
3030
private readonly Mock<IRunContext> _mockRunContext;
@@ -40,13 +40,12 @@ public class DeploymentUtilityTests : TestContainer
4040

4141
public DeploymentUtilityTests()
4242
{
43-
_mockReflectionUtility = new Mock<ReflectionUtility>();
4443
_mockFileUtility = new Mock<FileUtility>();
4544
_mockAssemblyUtility = new Mock<AssemblyUtility>();
4645
_warnings = [];
4746

4847
_deploymentUtility = new DeploymentUtility(
49-
new DeploymentItemUtility(_mockReflectionUtility.Object),
48+
new DeploymentItemUtility(new ReflectHelper()),
5049
_mockAssemblyUtility.Object,
5150
_mockFileUtility.Object);
5251

0 commit comments

Comments
 (0)