Skip to content

Commit

Permalink
Refactored FullyQualifiedNameUtilities to ManagedNameUtilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Nov 19, 2020
1 parent ceebbcc commit 45f3532
Show file tree
Hide file tree
Showing 32 changed files with 255 additions and 268 deletions.
2 changes: 1 addition & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Exte
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.collector", "test\coverlet.collector\coverlet.collector.csproj", "{074F5BD6-DC05-460B-B78F-044D125FD787}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.ObjectModel.FullyQualifiedNameUtilities.UnitTests", "test\Microsoft.TestPlatform.ObjectModel.FullyQualifiedNameUtilities.UnitTests\Microsoft.TestPlatform.ObjectModel.FullyQualifiedNameUtilities.UnitTests.csproj", "{DCD0C39E-C78C-4A44-B0BD-7325254A2E97}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.ObjectModel.ManagedNameUtilities.UnitTests", "test\Microsoft.TestPlatform.ObjectModel.ManagedNameUtilities.UnitTests\Microsoft.TestPlatform.ObjectModel.ManagedNameUtilities.UnitTests.csproj", "{DCD0C39E-C78C-4A44-B0BD-7325254A2E97}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public ITestElement ToTestElement(
return testElement;
}



/// <summary>
/// Converts the rockSteady result to unit test result
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.ObjectModel/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.ObjectModel.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("datacollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.ObjectModel.FullyQualifiedNameUtilities.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.ObjectModel.ManagedNameUtilities.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.ManagedNameUtilities
{
using System;

public class InvalidManagedNameException : Exception
{
public InvalidManagedNameException(string message) : base(message) { }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.FullyQualifiedNameUtilities
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.ManagedNameUtilities
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Resources;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Extensions;
Expand All @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.FullyQualifiedNameUtil
using System.Reflection;
using System.Text;

public static partial class FullyQualifiedNameHelper
public static partial class ManagedNameHelper
{
/// <summary>
/// Gets fully qualified type and method name from given MethodBase instance.
Expand All @@ -33,7 +33,7 @@ public static partial class FullyQualifiedNameHelper
/// <exception cref="NotImplementedException">
/// Required functionality on <paramref name="method"/> is missing on the current platform.
/// </exception>
public static void GetFullyQualifiedName(MethodBase method, out string fullTypeName, out string fullMethodName)
public static void GetManagedName(MethodBase method, out string fullTypeName, out string fullMethodName)
{
if (method == null)
{
Expand Down Expand Up @@ -116,11 +116,11 @@ public static void GetFullyQualifiedName(MethodBase method, out string fullTypeN
/// <returns>
/// A <see cref="MethodBase" /> object that represents specified parameters, throws if null.
/// </returns>
/// <exception cref="InvalidQualifiedNameException">
/// <exception cref="InvalidManagedNameException">
/// Values specified with <paramref name="fullTypeName"/> and <paramref name="fullMethodName"/>
/// does not correspond to a method in the <paramref name="assembly"/> instance, or malformed.
/// </exception>
public static MethodBase GetMethodFromFullyQualifiedName(Assembly assembly, string fullTypeName, string fullMethodName)
public static MethodBase GetManagedName(Assembly assembly, string fullTypeName, string fullMethodName)
{
Type type;

Expand All @@ -139,21 +139,21 @@ public static MethodBase GetMethodFromFullyQualifiedName(Assembly assembly, stri

if (type == null)
{
string message = String.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorTypeNotFound, fullTypeName);
throw new InvalidQualifiedNameException(message);
string message = String.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorTypeNotFound, fullTypeName);
throw new InvalidManagedNameException(message);
}

MethodInfo method = null;
FullyQualifiedNameParser.ParseMethodName(fullMethodName, out var methodName, out var methodArity, out var parameterTypes);
ManagedNameParser.ParseMethodName(fullMethodName, out var methodName, out var methodArity, out var parameterTypes);
if (!string.IsNullOrWhiteSpace(methodName))
{
method = FindMethod(type, methodName, methodArity, parameterTypes);
}

if (method == null)
{
string message = String.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorMethodNotFound, methodName, fullTypeName);
throw new InvalidQualifiedNameException(message);
string message = String.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorMethodNotFound, methodName, fullTypeName);
throw new InvalidManagedNameException(message);
}

return method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.FullyQualifiedNameUtilities
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.ManagedNameUtilities
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Resources;

Expand All @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.FullyQualifiedNameUtil
using System.Globalization;
using System.Linq;

public class FullyQualifiedNameParser
public class ManagedNameParser
{
internal static void ParseTypeName(string fullTypeName, out string namespaceName, out string typeName)
{
Expand All @@ -33,8 +33,8 @@ internal static void ParseMethodName(string fullMethodName, out string methodNam
pos = ParseParameterTypeList(fullMethodName, pos, out parameterTypes);
if (pos != fullMethodName.Length)
{
string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorUnexpectedCharactersAtEnd, pos);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorUnexpectedCharactersAtEnd, pos);
throw new InvalidManagedNameException(message);
}
}

Expand All @@ -49,8 +49,8 @@ private static int ParseMethodName(string fullMethodName, int start, out string
switch (fullMethodName[i])
{
case var w when char.IsWhiteSpace(w):
string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidManagedNameException(message);
case '`':
methodName = Capture(fullMethodName, start, i);
return ParseArity(fullMethodName, i, out arity);
Expand Down Expand Up @@ -78,8 +78,8 @@ private static int ParseArity(string fullMethodName, int start, out int arity)
}
if (!int.TryParse(Capture(fullMethodName, start + 1, i), out arity))
{
string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorMethodArityMustBeNumeric);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorMethodArityMustBeNumeric);
throw new InvalidManagedNameException(message);
}
return i;
}
Expand Down Expand Up @@ -115,8 +115,8 @@ private static int ParseParameterTypeList(string fullMethodName, int start, out
}
}

string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorIncompleteFullyQualifiedName);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorIncompleteManagedName);
throw new InvalidManagedNameException(message);
}

private static int ParseParameterType(string fullMethodName, int start, out string parameterType)
Expand All @@ -139,8 +139,8 @@ private static int ParseParameterType(string fullMethodName, int start, out stri
parameterType = Capture(fullMethodName, start, i);
return i - 1;
case var w when char.IsWhiteSpace(w):
string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidManagedNameException(message);
}
}
return i;
Expand All @@ -155,13 +155,13 @@ private static int ParseArrayBrackets(string fullMethodName, int start)
case ']':
return i;
case var w when char.IsWhiteSpace(w):
string msg = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidQualifiedNameException(msg);
string msg = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidManagedNameException(msg);
}
}

string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorIncompleteFullyQualifiedName);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorIncompleteManagedName);
throw new InvalidManagedNameException(message);
}

private static int ParseGenericBrackets(string fullMethodName, int start)
Expand All @@ -176,13 +176,13 @@ private static int ParseGenericBrackets(string fullMethodName, int start)
case '>':
return i;
case var w when char.IsWhiteSpace(w):
string msg = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidQualifiedNameException(msg);
string msg = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorWhitespaceNotValid, i);
throw new InvalidManagedNameException(msg);
}
}

string message = string.Format(CultureInfo.CurrentCulture, FullyQualifiedNameMessages.ErrorIncompleteFullyQualifiedName);
throw new InvalidQualifiedNameException(message);
string message = string.Format(CultureInfo.CurrentCulture, ManagedNameMessages.ErrorIncompleteManagedName);
throw new InvalidManagedNameException(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,10 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);WINDOWS_UWP</DefineConstants>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx;Resources\CommonResources.resx;Resources\FullyQualifiedNameMessages.resx" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\CommonResources.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Resources\CommonResources.resx</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' OR '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Xml" />
<Reference Include="System.Runtime.Serialization" />
Expand All @@ -44,7 +33,7 @@
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0'">
<PackageReference Include="System.ComponentModel.EventBasedAsync" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
Expand All @@ -63,10 +52,10 @@
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />

<PackageReference Include="NuGet.Frameworks" Version="4.6.4" />
</ItemGroup>

<ItemGroup Condition="!$(TargetFramework.StartsWith('netstandard1')) AND '$(TargetFramework)' != 'uap10.0'">
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
<PackageReference Include="NuGet.Frameworks" Version="$(NuGetFrameworksVersion)" />
Expand All @@ -77,25 +66,35 @@
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />

<PackageReference Include="NuGet.Frameworks" Version="4.6.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0'">
<Compile Remove="DataCollector\**" />
<Compile Remove="Navigation\**" />
</ItemGroup>


<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx" />
<EmbeddedResource Include="Resources\CommonResources.resx" />
<EmbeddedResource Include="Resources\ManagedNameMessages.resx" />

<None Include="Resources\CommonResources.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Resources\CommonResources.resx</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\CommonResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CommonResources.resx</DependentUpon>
</Compile>
<Compile Update="Resources\FullyQualifiedNameMessages.Designer.cs">
<Compile Update="Resources\ManagedNameMessages.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>FullyQualifiedNameMessages.resx</DependentUpon>
<DependentUpon>ManagedNameMessages.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand All @@ -109,9 +108,9 @@
<DependentUpon>Resources\CommonResources.tt</DependentUpon>
<LastGenOutput>CommonResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\FullyQualifiedNameMessages.resx">
<EmbeddedResource Update="Resources\ManagedNameMessages.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>FullyQualifiedNameMessages.Designer.cs</LastGenOutput>
<LastGenOutput>ManagedNameMessages.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
Loading

0 comments on commit 45f3532

Please sign in to comment.