-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ManagedNameHelper to support namespaceless methods. (#4003)
- Loading branch information
Showing
5 changed files
with
249 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...TestPlatform.AdapterUtilities.UnitTests/ManagedNameUtilities/ManagedNameGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.UnitTests; | ||
|
||
[TestClass] | ||
public class ManagedNameGeneratorTests | ||
{ | ||
[TestMethod] | ||
public void Namespaceless_ClassMembers_ShouldNotReportANamespace() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessClass).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessClass", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_RecordMembers_ShouldNotReportANamespace() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessRecord).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessRecord", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_InnerClassMembers_ShouldNotReportANamespace() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessClass.Inner).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessClass+Inner", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_InnerRecordMembers_ShouldNotReportANamespace() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessRecord.Inner).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessRecord+Inner", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_ClassMembers_ShouldNotReportANamespace_InHierarchy() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessClass).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName, out var hierarchyValues); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessClass", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
Assert.IsNull(hierarchyValues[HierarchyConstants.Levels.NamespaceIndex]); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_RecordMembers_ShouldNotReportANamespace_InHierarch() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessRecord).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName, out var hierarchyValues); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessRecord", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
Assert.IsNull(hierarchyValues[HierarchyConstants.Levels.NamespaceIndex]); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_InnerClassMembers_ShouldNotReportANamespace_InHierarchy() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessClass.Inner).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName, out var hierarchyValues); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessClass+Inner", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
Assert.IsNull(hierarchyValues[HierarchyConstants.Levels.NamespaceIndex]); | ||
} | ||
|
||
[TestMethod] | ||
public void Namespaceless_InnerRecordMembers_ShouldNotReportANamespace_InHierarchy() | ||
{ | ||
// Arrange | ||
var methodBase = typeof(global::NamespacelessRecord.Inner).GetMethod("Method0")!; | ||
|
||
// Act | ||
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName, out var hierarchyValues); | ||
|
||
// Assert | ||
Assert.AreEqual("NamespacelessRecord+Inner", managedTypeName); | ||
Assert.AreEqual("Method0", managedMethodName); | ||
Assert.IsNull(hierarchyValues[HierarchyConstants.Levels.NamespaceIndex]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.