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

Ensure default mock names are (more) unique #359

Merged
merged 1 commit into from
Jun 5, 2017
Merged
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
6 changes: 4 additions & 2 deletions Source/Mock.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
using Moq.Proxy;
using Moq.Language;
using System.Reflection;
using System.Threading;

#if !NETCORE
using System.CodeDom;
Expand All @@ -58,6 +59,7 @@ namespace Moq
public partial class Mock<T> : Mock, IMock<T> where T : class
{
private static IProxyFactory proxyFactory = new CastleProxyFactory();
private static int serialNumberCounter = 0;
private T instance;
private object[] constructorArguments;

Expand Down Expand Up @@ -123,7 +125,7 @@ public Mock(MockBehavior behavior, params object[] args)

private string GenerateMockName()
{
var randomId = Guid.NewGuid().ToString("N").Substring(0, 4);
var serialNumber = Interlocked.Increment(ref serialNumberCounter).ToString("x8");

var typeName = typeof (T).FullName;

Expand All @@ -138,7 +140,7 @@ private string GenerateMockName()
}
#endif

return "Mock<" + typeName + ":" + randomId + ">";
return "Mock<" + typeName + ":" + serialNumber + ">";
}

private void CheckParameters()
Expand Down