Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetCustomAttributes cant return null #4046

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,6 @@ private static void SetCustomProperties(TestMethodInfo testMethodInfo, ITestCont
DebugEx.Assert(testMethodInfo.TestMethod != null, "testMethodInfo.TestMethod is Null");

object[] attributes = testMethodInfo.TestMethod.GetCustomAttributes(typeof(TestPropertyAttribute), false);
DebugEx.Assert(attributes != null, "attributes is null");

foreach (TestPropertyAttribute attribute in attributes.Cast<TestPropertyAttribute>())
{
Expand Down
14 changes: 5 additions & 9 deletions src/Adapter/MSTest.TestAdapter/Helpers/ReflectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ static Attribute[] GetAttributes(ICustomAttributeProvider attributeProvider, boo
// Populate the cache
try
{
object[]? attributes = NotCachedReflectionAccessor.GetCustomAttributesNotCached(attributeProvider, inherit);
return attributes is null ? [] : attributes as Attribute[] ?? attributes.Cast<Attribute>().ToArray();
object[] attributes = NotCachedReflectionAccessor.GetCustomAttributesNotCached(attributeProvider, inherit);
return attributes as Attribute[] ?? attributes.Cast<Attribute>().ToArray();
}
catch (Exception ex)
{
Expand All @@ -469,7 +469,7 @@ static Attribute[] GetAttributes(ICustomAttributeProvider attributeProvider, boo
}
catch (Exception ex2)
{
description = string.Format(CultureInfo.CurrentCulture, Resource.ExceptionOccuredWhileGettingTheExceptionDescription, ex.GetType().FullName, ex2.GetType().FullName); // ex.GetType().FullName +
description = string.Format(CultureInfo.CurrentCulture, Resource.ExceptionOccuredWhileGettingTheExceptionDescription, ex.GetType().FullName, ex2.GetType().FullName); // ex.GetType().FullName +
}

PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning(Resource.FailedToGetCustomAttribute, attributeProvider.GetType().FullName!, description);
Expand All @@ -490,14 +490,10 @@ internal static class NotCachedReflectionAccessor
/// <param name="attributeProvider">Member for which attributes needs to be retrieved.</param>
/// <param name="inherit">If inherited type of attribute.</param>
/// <returns>All attributes of give type on member.</returns>
public static object[]? GetCustomAttributesNotCached(ICustomAttributeProvider attributeProvider, bool inherit)
{
object[] attributesArray = attributeProvider is MemberInfo memberInfo
public static object[] GetCustomAttributesNotCached(ICustomAttributeProvider attributeProvider, bool inherit) =>
attributeProvider is MemberInfo memberInfo
? PlatformServiceProvider.Instance.ReflectionOperations.GetCustomAttributes(memberInfo, inherit)
: PlatformServiceProvider.Instance.ReflectionOperations.GetCustomAttributes((Assembly)attributeProvider, typeof(Attribute));

return attributesArray; // TODO: Investigate if we rely on NRE
}
}

internal /* for tests */ void ClearCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ internal sealed class SourceGeneratedReflectionOperations : IReflectionOperation
public SourceGeneratedReflectionDataProvider ReflectionDataProvider { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.

[return: NotNullIfNotNull(nameof(memberInfo))]
public object[]? GetCustomAttributes(MemberInfo memberInfo, bool inherit)
public object[] GetCustomAttributes(MemberInfo memberInfo, bool inherit)
{
if (memberInfo is Type type)
{
Expand All @@ -33,8 +32,7 @@ internal sealed class SourceGeneratedReflectionOperations : IReflectionOperation
}
}

[return: NotNullIfNotNull(nameof(memberInfo))]
public object[]? GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) => throw new NotImplementedException();
public object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) => throw new NotImplementedException();

public object[] GetCustomAttributes(Assembly assembly, Type /* the attribute type to find */ type)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
Expand All @@ -17,8 +16,7 @@
/// <param name="memberInfo"> The member. </param>
/// <param name="inherit"> True to inspect the ancestors of element; otherwise, false. </param>
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
[return: NotNullIfNotNull(nameof(memberInfo))]
object[]? GetCustomAttributes(MemberInfo memberInfo, bool inherit);
object[] GetCustomAttributes(MemberInfo memberInfo, bool inherit);

Check failure on line 19 in src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

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

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs(19,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 19 in src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

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

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs(19,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 19 in src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs(19,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Gets all the custom attributes of a given type adorned on a member.
Expand All @@ -27,8 +25,7 @@
/// <param name="type"> The attribute type. </param>
/// <param name="inherit"> True to inspect the ancestors of element; otherwise, false. </param>
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
[return: NotNullIfNotNull(nameof(memberInfo))]
object[]? GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit);
object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit);

Check failure on line 28 in src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

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

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs(28,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 28 in src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IReflectionOperations.cs(28,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Gets all the custom attributes of a given type on an assembly.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.IReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
Expand All @@ -22,8 +21,7 @@
/// <param name="memberInfo"> The member. </param>
/// <param name="inherit"> True to inspect the ancestors of element; otherwise, false. </param>
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
[return: NotNullIfNotNull(nameof(memberInfo))]
public object[]? GetCustomAttributes(MemberInfo memberInfo, bool inherit) =>
public object[] GetCustomAttributes(MemberInfo memberInfo, bool inherit) =>

Check failure on line 24 in src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

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

src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs(24,21): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 24 in src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs(24,21): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
#if NETFRAMEWORK
ReflectionUtility.GetCustomAttributes(memberInfo, inherit).ToArray();
#else
Expand All @@ -37,8 +35,7 @@
/// <param name="type"> The attribute type. </param>
/// <param name="inherit"> True to inspect the ancestors of element; otherwise, false. </param>
/// <returns> The list of attributes on the member. Empty list if none found. </returns>
[return: NotNullIfNotNull(nameof(memberInfo))]
public object[]? GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) =>
public object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) =>

Check failure on line 38 in src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

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

src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs(38,21): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 38 in src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs(38,21): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ReflectionOperations.GetCustomAttributes(System.Reflection.MemberInfo! memberInfo, System.Type! type, bool inherit) -> object![]!' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
#if NETFRAMEWORK
ReflectionUtility.GetCustomAttributes(memberInfo, type, inherit).ToArray();
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void GetCustomAttributesShouldReturnAllAttributes()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : base", "Owner : base"];
Expand All @@ -58,7 +57,6 @@ public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance(

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : derived", "Owner : derived"];
Expand All @@ -71,7 +69,6 @@ public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(3);

// Notice that the Owner on the base method does not show up since it can only be defined once.
Expand All @@ -85,7 +82,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributes()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(type, false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : ba"];
Expand All @@ -98,7 +94,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheri

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(type, false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : a"];
Expand All @@ -111,7 +106,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritanc

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(method, true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : a", "TestCategory : ba"];
Expand All @@ -124,7 +118,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributes()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : base"];
Expand All @@ -137,7 +130,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInhe

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : derived"];
Expand All @@ -151,7 +143,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInherita

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : derived", "TestCategory : base"];
Expand All @@ -164,7 +155,6 @@ public void GetCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttr

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, null, true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(3);

string[] expectedAttributes = ["Duration : superfast", "TestCategory : base", "Owner : base"];
Expand All @@ -177,7 +167,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesIncludingUserDef

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestPropertyAttribute), true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["Duration : superfast"];
Expand All @@ -190,7 +179,6 @@ public void GetSpecificCustomAttributesShouldReturnArrayAttributesAsWell()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(CategoryArrayAttribute), true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["CategoryAttribute : foo,foo2"];
Expand All @@ -203,7 +191,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(type, typeof(TestCategoryAttribute), false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : ba"];
Expand All @@ -216,7 +203,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBa

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(type, typeof(TestCategoryAttribute), false);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(1);

string[] expectedAttributes = ["TestCategory : a"];
Expand All @@ -229,7 +215,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseIn

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(method, typeof(TestCategoryAttribute), true);

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : a", "TestCategory : ba"];
Expand All @@ -242,7 +227,6 @@ public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()

List<Attribute> attributes = ReflectionUtility.GetCustomAttributes(asm, typeof(TestCategoryAttribute));

attributes.Should().NotBeNull();
attributes.Should().HaveCount(2);

string[] expectedAttributes = ["TestCategory : a1", "TestCategory : a2"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void GetCustomAttributesShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : base", "DummySingleA : base"];
Expand All @@ -38,7 +37,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(type, false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : ba"];
Expand All @@ -51,7 +49,6 @@ public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(asm, typeof(ReflectionUtilityTests.DummyAAttribute));

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : a1", "DummyA : a2"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void GetCustomAttributesShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : base", "DummySingleA : base"];
Expand All @@ -34,7 +33,6 @@ public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance(

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : derived", "DummySingleA : derived"];
Expand All @@ -47,7 +45,6 @@ public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, true);

Verify(attributes is not null);
Verify(attributes.Length == 3);

// Notice that the DummySingleA on the base method does not show up since it can only be defined once.
Expand All @@ -61,7 +58,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(type, false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : ba"];
Expand All @@ -74,7 +70,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheri

object[] attributes = _reflectionOperations.GetCustomAttributes(type, false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : a"];
Expand All @@ -87,7 +82,6 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritanc

object[] attributes = _reflectionOperations.GetCustomAttributes(method, true);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : a", "DummyA : ba"];
Expand All @@ -100,7 +94,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : base"];
Expand All @@ -113,7 +106,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInhe

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : derived"];
Expand All @@ -126,7 +118,6 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInherita

object[] attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), true);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : derived", "DummyA : base"];
Expand All @@ -139,7 +130,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(type, typeof(DummyAAttribute), false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : ba"];
Expand All @@ -152,7 +142,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBa

object[] attributes = _reflectionOperations.GetCustomAttributes(type, typeof(DummyAAttribute), false);

Verify(attributes is not null);
Verify(attributes.Length == 1);

string[] expectedAttributes = ["DummyA : a"];
Expand All @@ -165,7 +154,6 @@ public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseIn

object[] attributes = _reflectionOperations.GetCustomAttributes(method, typeof(DummyAAttribute), true);

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : a", "DummyA : ba"];
Expand All @@ -178,7 +166,6 @@ public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()

object[] attributes = _reflectionOperations.GetCustomAttributes(asm, typeof(DummyAAttribute));

Verify(attributes is not null);
Verify(attributes.Length == 2);

string[] expectedAttributes = ["DummyA : a1", "DummyA : a2"];
Expand Down
Loading
Loading