diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8ef10080..cf9894639 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
## Unreleased
+
#### Fixed
* `NullReferenceException` when using `SetupSet` on indexers with multiple parameters (@idigra, #694)
@@ -15,6 +16,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
#### Changed
* Dropped the dependency on the `System.ValueTuple` NuGet package, at no functional cost (i.e. value tuples are still supported just fine) (@stakx, #721)
+* Updated failure messages to show richer class names (@powerdude, #727)
## 4.10.0 (2018-09-08)
diff --git a/src/Moq/Moq.csproj b/src/Moq/Moq.csproj
index 08c8ad12e..c3b68f51d 100644
--- a/src/Moq/Moq.csproj
+++ b/src/Moq/Moq.csproj
@@ -39,6 +39,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
diff --git a/src/Moq/StringBuilderExtensions.cs b/src/Moq/StringBuilderExtensions.cs
index e01a95501..56f423a83 100644
--- a/src/Moq/StringBuilderExtensions.cs
+++ b/src/Moq/StringBuilderExtensions.cs
@@ -7,6 +7,8 @@
using System.Reflection;
using System.Text;
+using TypeNameFormatter;
+
namespace Moq
{
internal static class StringBuilderExtensions
@@ -38,33 +40,7 @@ public static StringBuilder AppendNameOf(this StringBuilder stringBuilder, Type
{
Debug.Assert(type != null);
- 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;
+ return stringBuilder.AppendFormattedName(type);
}
public static StringBuilder AppendValueOf(this StringBuilder stringBuilder, object obj)
diff --git a/tests/Moq.Tests/CustomMatcherFixture.cs b/tests/Moq.Tests/CustomMatcherFixture.cs
index c9e7f182f..f218ec717 100644
--- a/tests/Moq.Tests/CustomMatcherFixture.cs
+++ b/tests/Moq.Tests/CustomMatcherFixture.cs
@@ -73,7 +73,7 @@ public void Custom_matcher_property_appears_by_name_in_verification_error_messag
var ex = Assert.Throws(() => child.Verify());
- Assert.Contains(".PlayWith(Toy.IsRed)", ex.Message);
+ Assert.Contains(".PlayWith(CustomMatcherFixture.Toy.IsRed)", ex.Message);
}
[Fact]
@@ -84,7 +84,7 @@ public void Custom_matcher_method_appears_by_name_in_verification_error_message(
var ex = Assert.Throws(() => child.Verify());
- Assert.Contains(".PlayWith(Toy.IsGreen())", ex.Message);
+ Assert.Contains(".PlayWith(CustomMatcherFixture.Toy.IsGreen())", ex.Message);
}
public class Toy
diff --git a/tests/Moq.Tests/ExpressionExtensionsFixture.cs b/tests/Moq.Tests/ExpressionExtensionsFixture.cs
index dda843dca..34821ea7a 100644
--- a/tests/Moq.Tests/ExpressionExtensionsFixture.cs
+++ b/tests/Moq.Tests/ExpressionExtensionsFixture.cs
@@ -36,7 +36,7 @@ public void PrefixesStaticGenericMethodWithClass()
var value = expr.ToStringFixed();
- Assert.Contains("ExpressionExtensionsFixture.DoStaticGeneric(5)", value);
+ Assert.Contains("ExpressionExtensionsFixture.DoStaticGeneric(5)", value);
}
[Fact]
diff --git a/tests/Moq.Tests/MockRepositoryFixture.cs b/tests/Moq.Tests/MockRepositoryFixture.cs
index 204df8ba0..3b05826f4 100644
--- a/tests/Moq.Tests/MockRepositoryFixture.cs
+++ b/tests/Moq.Tests/MockRepositoryFixture.cs
@@ -145,10 +145,10 @@ public void ShouldAggregateFailures()
Assert.NotNull(ex);
Assert.True(ex.Message.ContainsConsecutiveLines(
$"The following setups on mock \'{foo}\' were not matched:",
- $"IFoo f => f.Do()",
+ $"MockRepositoryFixture.IFoo f => f.Do()",
$"",
$"The following setups on mock \'{bar}\' were not matched:",
- $"IBar b => b.Redo()"));
+ $"MockRepositoryFixture.IBar b => b.Redo()"));
}
[Fact]
diff --git a/tests/Moq.Tests/Regressions/IssueReportsFixture.cs b/tests/Moq.Tests/Regressions/IssueReportsFixture.cs
index 7383b9fd1..8e71b13f5 100644
--- a/tests/Moq.Tests/Regressions/IssueReportsFixture.cs
+++ b/tests/Moq.Tests/Regressions/IssueReportsFixture.cs
@@ -2398,7 +2398,7 @@ public void Test()
Assert.True(e.IsVerificationError);
Assert.Contains(
- "IFoo t => t.Submit(It.IsAny(), It.IsAny(), new[] { It.IsAny() })",
+ "IFoo t => t.Submit(It.IsAny(), It.IsAny(), new[] { It.IsAny() })",
e.Message);
}
@@ -3031,8 +3031,8 @@ public void Test()
var e = Assert.Throws(() => mock.Verify(m => m.Execute(0)));
Assert.True(e.Message.ContainsConsecutiveLines(
"Configured setups: ",
- "IFoo m => m.Execute(1)",
- "IFoo m => m.Execute(It.IsInRange(2, 20, Range.Exclusive))"));
+ "IssueReportsFixture._183.IFoo m => m.Execute(1)",
+ "IssueReportsFixture._183.IFoo m => m.Execute(It.IsInRange(2, 20, Range.Exclusive))"));
}
[Fact]
@@ -3047,7 +3047,7 @@ public void TestGeneric()
var e = Assert.Throws(() => mock.Verify(m => m.Execute(1, 1)));
Assert.True(e.Message.ContainsConsecutiveLines(
"Configured setups: ",
- "IFoo m => m.Execute(1, 10)"));
+ "IssueReportsFixture._183.IFoo m => m.Execute(1, 10)"));
}
[Fact]
diff --git a/tests/Moq.Tests/VerifyFixture.cs b/tests/Moq.Tests/VerifyFixture.cs
index 0c20138f9..3b1c21578 100644
--- a/tests/Moq.Tests/VerifyFixture.cs
+++ b/tests/Moq.Tests/VerifyFixture.cs
@@ -60,7 +60,7 @@ public void ThrowsWithExpressionIfVerifiableExpectationWithLambdaMatcherNotCalle
var mex = Assert.Throws(() => mock.Verify());
Assert.True(mex.IsVerificationError);
- Assert.Contains(@".Execute(It.Is(s => String.IsNullOrEmpty(s)))", mex.Message);
+ Assert.Contains(@".Execute(It.Is(s => string.IsNullOrEmpty(s)))", mex.Message);
}
[Fact]
@@ -1407,7 +1407,7 @@ public void Verification_error_message_contains_setup_for_delegate_mock_with_par
var ex = Record.Exception(() => mock.Verify(m => m(1, 2), Times.Once()));
Assert.Contains("Configured setups:", ex.Message);
- Assert.Contains("Action m => m(1, It.IsAny())", ex.Message);
+ Assert.Contains("Action m => m(1, It.IsAny())", ex.Message);
}
[Fact]