Skip to content

Commit a02044d

Browse files
authored
Cleanup unused method in ReflectionOperations (#7354)
1 parent 803367e commit a02044d

File tree

5 files changed

+0
-97
lines changed

5 files changed

+0
-97
lines changed

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ internal interface IReflectionOperations
1616
[return: NotNullIfNotNull(nameof(memberInfo))]
1717
object[]? GetCustomAttributes(MemberInfo memberInfo);
1818

19-
/// <summary>
20-
/// Gets all the custom attributes of a given type adorned on a member.
21-
/// </summary>
22-
/// <param name="memberInfo"> The member info. </param>
23-
/// <param name="type"> The attribute type. </param>
24-
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
25-
[return: NotNullIfNotNull(nameof(memberInfo))]
26-
object[]? GetCustomAttributes(MemberInfo memberInfo, Type type);
27-
2819
/// <summary>
2920
/// Gets all the custom attributes of a given type on an assembly.
3021
/// </summary>

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ internal sealed class ReflectionOperations : IReflectionOperations
3838
}
3939
#endif
4040

41-
/// <summary>
42-
/// Gets all the custom attributes of a given type adorned on a member.
43-
/// </summary>
44-
/// <param name="memberInfo"> The member info. </param>
45-
/// <param name="type"> The attribute type. </param>
46-
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
47-
[return: NotNullIfNotNull(nameof(memberInfo))]
48-
public object[]? GetCustomAttributes(MemberInfo memberInfo, Type type) =>
49-
#if NETFRAMEWORK
50-
[.. ReflectionUtility.GetCustomAttributesCore(memberInfo, type)];
51-
#else
52-
memberInfo.GetCustomAttributes(type, inherit: true);
53-
#endif
54-
5541
/// <summary>
5642
/// Gets all the custom attributes of a given type on an assembly.
5743
/// </summary>

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodRunnerTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,6 @@ public async Task RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDa
244244
var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
245245
var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
246246

247-
int dummyIntData = 2;
248-
string dummyStringData = "DummyString";
249-
DataRowAttribute dataRowAttribute = new(
250-
dummyIntData,
251-
dummyStringData);
252-
253-
var attributes = new Attribute[] { dataRowAttribute };
254-
255-
// Setup mocks
256-
_testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(_methodInfo, It.IsAny<Type>())).Returns(attributes);
257-
258247
TestResult[] results = await testMethodRunner.RunTestMethodAsync();
259248
results[0].Outcome.Should().Be(UTF.UnitTestOutcome.Inconclusive);
260249
}

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Helpers/ReflectHelperTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ public void IsAttributeDefinedShouldReturnFromCache()
187187
// Validate that reflection APIs are not called again.
188188
rh.IsAttributeDefined<TestMethodAttribute>(memberInfo).Should().BeTrue();
189189
_testablePlatformServiceProvider.MockReflectionOperations.Verify(ro => ro.GetCustomAttributes(memberInfo), Times.Once);
190-
191-
// Also validate that reflection APIs for an individual type is not called since the cache gives us what we need already.
192-
_testablePlatformServiceProvider.MockReflectionOperations.Verify(ro => ro.GetCustomAttributes(It.IsAny<MemberInfo>(), It.IsAny<Type>()), Times.Never);
193190
}
194191

195192
public void HasAttributeDerivedFromShouldReturnTrueIfSpecifiedAttributeIsDefinedOnAMember()
@@ -237,25 +234,17 @@ public void HasAttributeDerivedFromShouldReturnFromCache()
237234
// Validate that reflection APIs are not called again.
238235
rh.IsAttributeDefined<TestMethodAttribute>(memberInfo).Should().BeTrue();
239236
_testablePlatformServiceProvider.MockReflectionOperations.Verify(ro => ro.GetCustomAttributes(memberInfo), Times.Once);
240-
241-
// Also validate that reflection APIs for an individual type is not called since the cache gives us what we need already.
242-
_testablePlatformServiceProvider.MockReflectionOperations.Verify(ro => ro.GetCustomAttributes(It.IsAny<MemberInfo>(), It.IsAny<Type>()), Times.Never);
243237
}
244238

245239
public void HasAttributeDerivedFromShouldReturnFalseQueryingProvidedAttributesExistenceIfGettingAllAttributesFail()
246240
{
247241
var rh = new ReflectHelper();
248242
var mockMemberInfo = new Mock<MemberInfo>();
249-
var attributes = new Attribute[] { new TestableExtendedTestMethod() };
250243

251244
_testablePlatformServiceProvider.MockReflectionOperations.
252245
Setup(ro => ro.GetCustomAttributes(mockMemberInfo.Object)).
253246
Returns((object[])null!);
254247

255-
_testablePlatformServiceProvider.MockReflectionOperations.
256-
Setup(ro => ro.GetCustomAttributes(mockMemberInfo.Object, typeof(TestMethodAttribute))).
257-
Returns(attributes);
258-
259248
rh.IsAttributeDefined<TestMethodAttribute>(mockMemberInfo.Object).Should().BeFalse();
260249
}
261250

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

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -71,58 +71,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritanc
7171
GetAttributeValuePairs(attributes).SequenceEqual(expectedAttributes).Should().BeTrue();
7272
}
7373

74-
public void GetSpecificCustomAttributesShouldReturnAllAttributes()
75-
{
76-
MethodInfo methodInfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1")!;
77-
78-
object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute));
79-
80-
attributes.Should().NotBeNull();
81-
attributes.Length.Should().Be(1);
82-
83-
string[] expectedAttributes = ["DummyA : base"];
84-
GetAttributeValuePairs(attributes).SequenceEqual(expectedAttributes).Should().BeTrue();
85-
}
86-
87-
public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
88-
{
89-
MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1")!;
90-
91-
object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute));
92-
93-
attributes.Should().NotBeNull();
94-
attributes.Length.Should().Be(2);
95-
96-
string[] expectedAttributes = ["DummyA : derived", "DummyA : base"];
97-
GetAttributeValuePairs(attributes).SequenceEqual(expectedAttributes).Should().BeTrue();
98-
}
99-
100-
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()
101-
{
102-
Type type = typeof(DummyBaseTestClass);
103-
104-
object[] attributes = _reflectionOperations.GetCustomAttributes(type, typeof(DummyAAttribute));
105-
106-
attributes.Should().NotBeNull();
107-
attributes.Length.Should().Be(1);
108-
109-
string[] expectedAttributes = ["DummyA : ba"];
110-
GetAttributeValuePairs(attributes).SequenceEqual(expectedAttributes).Should().BeTrue();
111-
}
112-
113-
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
114-
{
115-
Type type = typeof(DummyTestClass);
116-
117-
object[] attributes = _reflectionOperations.GetCustomAttributes(type, typeof(DummyAAttribute));
118-
119-
attributes.Should().NotBeNull();
120-
attributes.Length.Should().Be(2);
121-
122-
string[] expectedAttributes = ["DummyA : a", "DummyA : ba"];
123-
GetAttributeValuePairs(attributes).SequenceEqual(expectedAttributes).Should().BeTrue();
124-
}
125-
12674
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
12775
{
12876
Assembly asm = typeof(DummyTestClass).Assembly;

0 commit comments

Comments
 (0)