-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
error messages don't display the parent class name of an inner class object #727
Comments
@powerdude, thanks for reporting this. Would you like to submit a PR for this? This could be quite easily done by changing Moq's It just so happens that I wrote a small library called TypeNameFormatter not too long ago; see its repo on GitHub, or the source code-only package on NuGet.org. The reason for a separate library is that formatting type names the way they look in e.g. C# turns out to be non-trivial due to a few gotchas (one of which you just described), so I figured let's encapsulate the logic for that in a library so we don't have to think too hard about it anymore. I've simply not got around to applying that library to Moq yet, but +// <PackageReference Include="TypeNameFormatter.Sources" Version="1.0.0" PrivateAssets="All" />
+// using TypeNameFormatter;
+
public static StringBuilder AppendNameOf(this StringBuilder stringBuilder, Type type)
{
Debug.Assert(type != null);
+ return stringBuilder.AppendFormattedName(type);
- var name = type.Name;
- var backtickIndex = name.IndexOf('`');
- if (backtickIndex >= 0)
- {
- stringBuilder.Append(name, 0, backtickIndex);
- }
- else
- {
- stringBuilder.Append(name);
- }
-
- if (type.GetTypeInfo().IsGenericType)
- {
- var genericArguments = type.GetGenericArguments();
- stringBuilder.Append('<');
- for (int i = 0, n = genericArguments.Length; i < n; ++i)
- {
- if (i > 0)
- {
- stringBuilder.Append(", ");
- }
- stringBuilder.AppendNameOf(genericArguments[i]);
- }
- stringBuilder.Append('>');
- }
-
- return stringBuilder;
} (A few unit tests that verify diagnostic messages would start failing due to the improved formatting, but that would be trivial to fix.) |
@stakx, sure, i'll try and have a look. Do you want me to include just the file or reference the library? |
@powerdude, perhaps start with a NuGet reference. It's a source-code-only package, so the effect is much the same as including the source file manually. As long as we don't need to modify the formatting code, referencing a NuGet package should be simpler. |
Fixed by #728. |
@powerdude, I've just pushed Moq 4.10.1 to NuGet (it should become available for restore in a short moment). That version includes your change. |
yayy!!. Thanks @stakx! |
If i have classes like this:
and try to verify a mock call:
and call the service
service.Send(new Foo1.Bar())
, the messages displayed fail to indicate the parent class name.Ideally, it should say:
The text was updated successfully, but these errors were encountered: