Skip to content

Commit

Permalink
Fix mock naming code & tests in Silverlight
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jan 11, 2014
1 parent 3c3eab9 commit 4f0925d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Source.Silverlight/Moq.Silverlight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@
<Compile Include="..\Source\Proxy\IProxyFactory.cs">
<Link>Poxy\IProxyFactory.cs</Link>
</Compile>
<Compile Include="..\Source\Proxy\ProxyGenerationHelpers.cs">
<Link>Poxy\ProxyGenerationHelpers.cs</Link>
</Compile>
<Compile Include="..\Source\Range.cs">
<Link>Range.cs</Link>
</Compile>
Expand Down Expand Up @@ -414,4 +417,4 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
</Project>
10 changes: 7 additions & 3 deletions Source/Mock.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@
// http://www.opensource.org/licenses/bsd-license.php]

using System;
using System.CodeDom;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using Microsoft.CSharp;
using Moq.Language.Flow;
using Moq.Proxy;
using Moq.Language;
using Moq.Properties;
using System.Reflection;

#if !SILVERLIGHT
using System.CodeDom;
using Microsoft.CSharp;
#endif

namespace Moq
{
/// <include file='Mock.Generic.xdoc' path='docs/doc[@for="Mock{T}"]/*'/>
Expand Down Expand Up @@ -120,6 +122,7 @@ private string GenerateMockName()

var typeName = typeof (T).FullName;

#if !SILVERLIGHT
if (typeof (T).IsGenericType)
{
using (var provider = new CSharpCodeProvider())
Expand All @@ -128,6 +131,7 @@ private string GenerateMockName()
typeName = provider.GetTypeOutput(typeRef);
}
}
#endif

return "Mock<" + typeName + ":" + randomId + ">";
}
Expand Down
5 changes: 3 additions & 2 deletions UnitTests/MockFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using Xunit;
Expand Down Expand Up @@ -45,13 +44,15 @@ public void HasADefaultNameThatIncludesItsTypeAndThatItsAMock()
Assert.Contains("mock", mock.ToString().ToLower());
}

#if !SILVERLIGHT
[Fact]
public void HasADefaultNameThatIncludesItsGenericParameters()
{
var mock = new Mock<Dictionary<int, string>>();

Assert.Contains("System.Collections.Generic.Dictionary<int, string>", mock.ToString());
}
#endif

[Fact]
public void PassesItsNameOnToTheResultingMockObjectWhenMockingInterfaces()
Expand All @@ -64,7 +65,7 @@ public void PassesItsNameOnToTheResultingMockObjectWhenMockingInterfaces()
[Fact]
public void PassesItsNameOnToTheResultingMockObjectWhenMockingClasses()
{
var mock = new Mock<ArrayList>();
var mock = new Mock<Foo>();

Assert.Equal(mock.ToString() + ".Object", mock.Object.ToString());
}
Expand Down

0 comments on commit 4f0925d

Please sign in to comment.