diff --git a/.gitignore b/.gitignore
index b87a50311..bee604391 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,5 @@ _ReSharper*/
*.userprefs
*.swp
*.DotSettings
+
+/packages
diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config
new file mode 100644
index 000000000..67f8ea046
--- /dev/null
+++ b/.nuget/NuGet.Config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets
new file mode 100644
index 000000000..46a1b6ced
--- /dev/null
+++ b/.nuget/NuGet.targets
@@ -0,0 +1,133 @@
+
+
+
+ $(MSBuildProjectDirectory)\..\
+
+
+ false
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+ $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
+ $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
+
+
+
+
+ $(SolutionDir).nuget
+ packages.config
+
+
+
+
+ $(NuGetToolsPath)\NuGet.exe
+ @(PackageSource)
+
+ "$(NuGetExePath)"
+ mono --runtime=v4.0.30319 $(NuGetExePath)
+
+ $(TargetDir.Trim('\\'))
+
+ -RequireConsent
+ -NonInteractive
+
+
+ $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "
+ $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
+
+
+
+ RestorePackages;
+ $(BuildDependsOn);
+
+
+
+
+ $(BuildDependsOn);
+ BuildPackage;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/Moq.csproj b/Source/Moq.csproj
index 8d3f048d9..f41ee37cc 100644
--- a/Source/Moq.csproj
+++ b/Source/Moq.csproj
@@ -1,260 +1,264 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {1C91AC30-5977-4BE5-BA67-8EB186C03514}
- Library
- Properties
- Moq
- Moq
- v4.0
- 512
- true
- ..\Moq.snk
-
-
-
- true
- full
- false
- bin\Debug\
- TRACE;DEBUG;DESKTOP
- TRACE;DEBUG;DESKTOP;NET3x
- prompt
- 4
- bin\Debug\Moq.xml
- true
- AllRules.ruleset
- false
-
-
-
-
- full
- true
- bin\Release\
- TRACE;CODE_ANALYSIS
- TRACE;CODE_ANALYSIS;NET3x
- prompt
- 4
- bin\Release\Moq.xml
- true
- true
- true
- true
- AllRules.ruleset
-
-
-
- False
- ..\Lib\Castle\bin-NET40\Castle.Core.dll
-
-
- False
- ..\Lib\Castle\bin-NET35\Castle.Core.dll
- False
-
-
-
-
-
-
-
-
-
- True
- True
- ICallback.tt
-
-
-
- True
- True
- IRaise.tt
-
-
-
- True
- True
- IReturns.tt
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- MethodCall.tt
-
-
- True
- True
- MethodCallReturn.tt
-
-
- True
- True
- Delegates.tt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- Resources.resx
-
-
-
-
-
-
-
-
-
-
- ResXFileCodeGenerator
- Designer
- Resources.Designer.cs
-
-
-
-
- Moq.snk
-
-
- IDefaultValueProvider.cs
-
-
-
- It.cs
-
-
- TextTemplatingFileGenerator
- ICallback.Generated.cs
-
-
- TextTemplatingFileGenerator
- IRaise.Generated.cs
-
-
- TextTemplatingFileGenerator
- IReturns.Generated.cs
-
-
- Match.cs
-
-
- TextTemplatingFileGenerator
- MethodCallReturn.Generated.cs
-
-
- TextTemplatingFileGenerator
- Delegates.cs
-
-
- Mock.Generic.cs
- Designer
-
-
- Mock.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TextTemplatingFileGenerator
- MethodCall.Generated.cs
-
-
- Times.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {1C91AC30-5977-4BE5-BA67-8EB186C03514}
+ Library
+ Properties
+ Moq
+ Moq
+ v4.0
+ 512
+ true
+ ..\Moq.snk
+
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ TRACE;DEBUG;DESKTOP
+ TRACE;DEBUG;DESKTOP;NET3x
+ prompt
+ 4
+ bin\Debug\Moq.xml
+ true
+ AllRules.ruleset
+ false
+
+
+
+
+ full
+ true
+ bin\Release\
+ TRACE;CODE_ANALYSIS
+ TRACE;CODE_ANALYSIS;NET3x
+ prompt
+ 4
+ bin\Release\Moq.xml
+ true
+ true
+ true
+ true
+ AllRules.ruleset
+
+
+
+ False
+ ..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll
+
+
+ False
+ ..\packages\Castle.Core.3.2.0\lib\net35\Castle.Core.dll
+ False
+
+
+
+
+
+
+
+
+
+ True
+ True
+ ICallback.tt
+
+
+
+ True
+ True
+ IRaise.tt
+
+
+
+ True
+ True
+ IReturns.tt
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+ MethodCall.tt
+
+
+ True
+ True
+ MethodCallReturn.tt
+
+
+ True
+ True
+ Delegates.tt
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+
+
+
+
+
+ ResXFileCodeGenerator
+ Designer
+ Resources.Designer.cs
+
+
+
+
+ Moq.snk
+
+
+ IDefaultValueProvider.cs
+
+
+
+ It.cs
+
+
+ TextTemplatingFileGenerator
+ ICallback.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ IRaise.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ IReturns.Generated.cs
+
+
+ Match.cs
+
+
+ TextTemplatingFileGenerator
+ MethodCallReturn.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ Delegates.cs
+
+
+ Mock.Generic.cs
+ Designer
+
+
+ Mock.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ MethodCall.Generated.cs
+
+
+
+ Times.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs
index 3b07ce3f6..64f434d19 100644
--- a/Source/Properties/AssemblyInfo.cs
+++ b/Source/Properties/AssemblyInfo.cs
@@ -1,36 +1,35 @@
-using System;
-using System.Reflection;
-using System.Resources;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("Moq")]
-[assembly: AssemblyDescription("Mocking library for .NET 3.5+ and C# 3.0+, heavily based on Linq")]
-[assembly: AssemblyCompany("Clarius Consulting, Manas Technology Solutions, InSTEDD")]
-[assembly: AssemblyProduct("Moq")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("4.0.10818.0")]
-[assembly: AssemblyFileVersion("4.0.0.0")]
-
-[assembly: ComVisible(false)]
-[assembly: NeutralResourcesLanguage("en")]
-
-#if SILVERLIGHT
-[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")]
-#else
-[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")]
-#endif
-[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
-
-[assembly: CLSCompliant(true)]
-
-///
-///
-///
-///
-///
-///
-internal static class ThisAssembly
-{
+using System;
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("Moq")]
+[assembly: AssemblyCompany("Clarius Consulting, Manas Technology Solutions, InSTEDD")]
+[assembly: AssemblyProduct("Moq")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: AssemblyVersion("4.0.10818.0")]
+[assembly: AssemblyFileVersion("4.0.0.0")]
+
+[assembly: ComVisible(false)]
+[assembly: NeutralResourcesLanguage("en")]
+
+#if SILVERLIGHT
+[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")]
+#else
+[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")]
+#endif
+[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
+
+[assembly: CLSCompliant(true)]
+
+///
+///
+///
+///
+///
+///
+internal static class ThisAssembly
+{
}
\ No newline at end of file
diff --git a/Source/packages.config b/Source/packages.config
new file mode 100644
index 000000000..01442097e
--- /dev/null
+++ b/Source/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/UnitTests/MatcherAttributeFixture.cs b/UnitTests/MatcherAttributeFixture.cs
index 7268d413b..1c573511b 100644
--- a/UnitTests/MatcherAttributeFixture.cs
+++ b/UnitTests/MatcherAttributeFixture.cs
@@ -1,264 +1,258 @@
-using System;
-using Xunit;
-
-namespace Moq.Tests
-{
- public class MatcherAttributeFixture
- {
- public interface IFoo
- {
- void Bar(string p);
- }
-
- [Fact]
- public void ShouldFindGenericMethodMatcher()
- {
- var foo = new Mock();
-
- foo.Object.Bar("asdf");
-
- foo.Verify(f => f.Bar(Any()));
- }
-
-#pragma warning disable 618
- [Matcher]
- public T Any()
- {
- return default(T);
- }
-
-#pragma warning restore 618
-
- public bool Any(T value)
- {
- return true;
- }
-
- [Fact]
- public void ShouldNotFindPrivateMethodMatcher()
- {
- var foo = new Mock();
-
- foo.Object.Bar("asd");
-
- Assert.Throws(() => foo.Verify(f => f.Bar(OddLength())));
- }
-
-#pragma warning disable 618
- [Matcher]
- private static string OddLength()
- {
- return default(string);
- }
-#pragma warning restore 618
-
- private static bool OddLength(string value)
- {
- return value.Length % 2 == 0;
- }
-
- [Fact]
- public void ShouldTranslateToUseMatcherImplementation()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(IsMagicString()));
- IsMagicStringCalled = false;
- mock.Object.Bar("magic");
- Assert.True(IsMagicStringCalled);
- }
-
- [Fact]
- //[ExpectedException] not used so IsMagicStringCalled can be verified
- public void ShouldTranslateToUseMatcherImplementation2()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(IsMagicString()));
- IsMagicStringCalled = false;
- Exception expectedException = null;
- try
- {
- mock.Object.Bar("no-magic");
- }
- catch (Exception e)
- {
- expectedException = e;
- }
-
- Assert.True(IsMagicStringCalled);
- Assert.NotNull(expectedException);
- }
-
- private static bool IsMagicStringCalled;
-
-#pragma warning disable 618
- [Matcher]
- public static string IsMagicString()
- {
- return null;
- }
-#pragma warning restore 618
-
- public static bool IsMagicString(string arg)
- {
- IsMagicStringCalled = true;
- return arg == "magic";
- }
-
- [Fact]
- public void ShouldUseAditionalArguments()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(StartsWith("ma")));
- mock.Object.Bar("magic");
- }
-
- [Fact]
- public void ShouldUseAditionalArguments2()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(StartsWith("ma")));
- Assert.Throws(() => mock.Object.Bar("no-magic"));
- }
-
-#pragma warning disable 618
- [Matcher]
- public static string StartsWith(string prefix)
- {
- return null;
- }
-#pragma warning restore 618
-
- public static bool StartsWith(string arg, string prefix)
- {
- return arg.StartsWith(prefix);
- }
-
- [Fact]
- public void ExpectMissingMatcherMethod()
- {
- var mock = new Mock(MockBehavior.Strict);
-
- Assert.Throws(
- "public static bool MatcherHookWithoutMatcherMethod(System.String) in class Moq.Tests.MatcherAttributeFixture.",
- () => mock.Setup(x => x.Bar(MatcherHookWithoutMatcherMethod())));
- }
-
-#pragma warning disable 618
- [Matcher]
- public static string MatcherHookWithoutMatcherMethod()
- {
- return null;
- }
-#pragma warning restore 618
-
- [Fact]
- public void ExpectMissingMatcherWithArgsMethod()
- {
- var mock = new Mock(MockBehavior.Strict);
-
- Assert.Throws(
- "public static bool MatcherHook2WithoutMatcherMethod(System.String, System.Int32) in class Moq.Tests.MatcherAttributeFixture.",
- () => mock.Setup(x => x.Bar(MatcherHook2WithoutMatcherMethod(6))));
- }
-
-#pragma warning disable 618
- [Matcher]
- public static string MatcherHook2WithoutMatcherMethod(int a)
- {
- return null;
- }
-#pragma warning restore 618
-
- [Fact]
- public void UseCurrentInstanceAsContext()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(NonStaticMatcherHook()));
- NonStaticMatcherHookExpectedArg = "Do It";
-
- mock.Object.Bar("Do It");
- }
-
-#pragma warning disable 618
- [Matcher]
- public string NonStaticMatcherHook()
- {
- return null;
- }
-#pragma warning restore 618
-
- public bool NonStaticMatcherHook(string arg)
- {
- return arg == NonStaticMatcherHookExpectedArg;
- }
-
- private string NonStaticMatcherHookExpectedArg;
-
- [Fact]
- public void ExpectMissingNonStaticMatcherMethod()
- {
- var mock = new Mock(MockBehavior.Strict);
-
- Assert.Throws(
- "public bool NonStaticMatcherHookWithoutMatcherMethod(System.String) in class Moq.Tests.MatcherAttributeFixture.",
- () => mock.Setup(x => x.Bar(NonStaticMatcherHookWithoutMatcherMethod())));
- }
-
-#pragma warning disable 618
- [Matcher]
- public string NonStaticMatcherHookWithoutMatcherMethod()
- {
- return null;
- }
-#pragma warning restore 618
-
- [Fact]
- public void AllowStaticMethodsInHelperClassAsMatcherHook()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(x => x.Bar(A.NotNull()));
- mock.Object.Bar("a");
- }
-
- public static class A
- {
-#pragma warning disable 618
- [Matcher]
- public static string NotNull()
- {
- return null;
- }
-#pragma warning restore 618
-
- public static bool NotNull(string arg)
- {
- return arg != null;
- }
- }
-
- [Fact]
- public void AllowHelperClassInstance()
- {
- var mock = new Mock(MockBehavior.Strict);
- var b = new B();
- mock.Setup(x => x.Bar(b.NotNull()));
- mock.Object.Bar("a");
- }
-
- public class B
- {
-#pragma warning disable 618
- [Matcher]
- public string NotNull()
- {
- return null;
- }
-#pragma warning restore 618
-
- public bool NotNull(string arg)
- {
- return arg != null;
- }
- }
- }
-}
+using System;
+using Xunit;
+
+namespace Moq.Tests
+{
+ public class MatcherAttributeFixture
+ {
+ public interface IFoo
+ {
+ void Bar(string p);
+ }
+
+ [Fact]
+ public void ShouldFindGenericMethodMatcher()
+ {
+ var foo = new Mock();
+
+ foo.Object.Bar("asdf");
+
+ foo.Verify(f => f.Bar(Any()));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public T Any()
+ {
+ return default(T);
+ }
+
+#pragma warning restore 618
+
+ public bool Any(T value)
+ {
+ return true;
+ }
+
+ [Fact]
+ public void ShouldNotFindPrivateMethodMatcher()
+ {
+ var foo = new Mock();
+
+ foo.Object.Bar("asd");
+
+ Assert.Throws(() => foo.Verify(f => f.Bar(OddLength())));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ private static string OddLength()
+ {
+ return default(string);
+ }
+#pragma warning restore 618
+
+ private static bool OddLength(string value)
+ {
+ return value.Length % 2 == 0;
+ }
+
+ [Fact]
+ public void ShouldTranslateToUseMatcherImplementation()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(IsMagicString()));
+ IsMagicStringCalled = false;
+ mock.Object.Bar("magic");
+ Assert.True(IsMagicStringCalled);
+ }
+
+ [Fact]
+ //[ExpectedException] not used so IsMagicStringCalled can be verified
+ public void ShouldTranslateToUseMatcherImplementation2()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(IsMagicString()));
+ IsMagicStringCalled = false;
+ Exception expectedException = null;
+ try
+ {
+ mock.Object.Bar("no-magic");
+ }
+ catch (Exception e)
+ {
+ expectedException = e;
+ }
+
+ Assert.True(IsMagicStringCalled);
+ Assert.NotNull(expectedException);
+ }
+
+ private static bool IsMagicStringCalled;
+
+#pragma warning disable 618
+ [Matcher]
+ public static string IsMagicString()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ public static bool IsMagicString(string arg)
+ {
+ IsMagicStringCalled = true;
+ return arg == "magic";
+ }
+
+ [Fact]
+ public void ShouldUseAditionalArguments()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(StartsWith("ma")));
+ mock.Object.Bar("magic");
+ }
+
+ [Fact]
+ public void ShouldUseAditionalArguments2()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(StartsWith("ma")));
+ Assert.Throws(() => mock.Object.Bar("no-magic"));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public static string StartsWith(string prefix)
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ public static bool StartsWith(string arg, string prefix)
+ {
+ return arg.StartsWith(prefix);
+ }
+
+ [Fact]
+ public void ExpectMissingMatcherMethod()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+
+ Assert.Throws(() => mock.Setup(x => x.Bar(MatcherHookWithoutMatcherMethod())));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public static string MatcherHookWithoutMatcherMethod()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ [Fact]
+ public void ExpectMissingMatcherWithArgsMethod()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+
+ Assert.Throws(() => mock.Setup(x => x.Bar(MatcherHook2WithoutMatcherMethod(6))));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public static string MatcherHook2WithoutMatcherMethod(int a)
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ [Fact]
+ public void UseCurrentInstanceAsContext()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(NonStaticMatcherHook()));
+ NonStaticMatcherHookExpectedArg = "Do It";
+
+ mock.Object.Bar("Do It");
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public string NonStaticMatcherHook()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ public bool NonStaticMatcherHook(string arg)
+ {
+ return arg == NonStaticMatcherHookExpectedArg;
+ }
+
+ private string NonStaticMatcherHookExpectedArg;
+
+ [Fact]
+ public void ExpectMissingNonStaticMatcherMethod()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+
+ Assert.Throws(() => mock.Setup(x => x.Bar(NonStaticMatcherHookWithoutMatcherMethod())));
+ }
+
+#pragma warning disable 618
+ [Matcher]
+ public string NonStaticMatcherHookWithoutMatcherMethod()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ [Fact]
+ public void AllowStaticMethodsInHelperClassAsMatcherHook()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ mock.Setup(x => x.Bar(A.NotNull()));
+ mock.Object.Bar("a");
+ }
+
+ public static class A
+ {
+#pragma warning disable 618
+ [Matcher]
+ public static string NotNull()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ public static bool NotNull(string arg)
+ {
+ return arg != null;
+ }
+ }
+
+ [Fact]
+ public void AllowHelperClassInstance()
+ {
+ var mock = new Mock(MockBehavior.Strict);
+ var b = new B();
+ mock.Setup(x => x.Bar(b.NotNull()));
+ mock.Object.Bar("a");
+ }
+
+ public class B
+ {
+#pragma warning disable 618
+ [Matcher]
+ public string NotNull()
+ {
+ return null;
+ }
+#pragma warning restore 618
+
+ public bool NotNull(string arg)
+ {
+ return arg != null;
+ }
+ }
+ }
+}
diff --git a/UnitTests/MockedFixture.cs b/UnitTests/MockedFixture.cs
index ede7daeab..6fba64576 100644
--- a/UnitTests/MockedFixture.cs
+++ b/UnitTests/MockedFixture.cs
@@ -1,97 +1,95 @@
-using System;
-using Xunit;
-
-namespace Moq.Tests
-{
- public class MockedFixture
- {
- [Fact]
- public void InterfaceMockedShouldImplementMocked()
- {
- Mock mock = new Mock();
- IFoo mocked = mock.Object;
- Assert.True(mocked is IMocked);
- }
-
- [Fact]
- public void MockOfMockedInterfaceShouldReturnSame()
- {
- Mock mock = new Mock();
- IMocked mocked = mock.Object as IMocked;
- Assert.Same(mock, mocked.Mock);
- }
-
- [Fact]
- public void ClassMockedShouldImplementMocked()
- {
- Mock mock = new Mock();
- Foo mocked = mock.Object;
- Assert.True(mocked is IMocked);
- }
-
- [Fact]
- public void MockOfMockedClassShouldReturnSame()
- {
- Mock mock = new Mock();
- IMocked mocked = mock.Object as IMocked;
- Assert.Same(mock, mocked.Mock);
- }
-
- public class FooWithCtor
- {
- public FooWithCtor(int a) { }
- }
-
- [Fact]
- public void ClassWithCtorMockedShouldImplementMocked()
- {
- Mock mock = new Mock(5);
- FooWithCtor mocked = mock.Object;
- Assert.True(mocked is IMocked);
- }
-
- [Fact]
- public void MockOfMockedClassWithCtorShouldReturnSame()
- {
- Mock mock = new Mock(5);
- IMocked mocked = mock.Object as IMocked;
- Assert.Same(mock, mocked.Mock);
- }
-
- [Fact]
- public void GetReturnsMockForAMocked()
- {
- var mock = new Mock();
- var mocked = mock.Object;
- Assert.Same(mock, Mock.Get(mocked));
- }
-
- [Fact]
- public void GetReturnsMockForAMockedAbstract()
- {
- var mock = new Mock();
- var mocked = mock.Object;
- Assert.Same(mock, Mock.Get(mocked));
- }
-
- [Fact]
- public void GetThrowsIfObjectIsNotMocked()
- {
- Assert.Throws(
- "Object instance was not created by Moq.\r\nParameter name: mocked",
- () => Mock.Get("foo"));
- }
-
- public class FooBase
- {
- }
-
- public class Foo : FooBase
- {
- }
-
- public interface IFoo
- {
- }
- }
+using System;
+using Xunit;
+
+namespace Moq.Tests
+{
+ public class MockedFixture
+ {
+ [Fact]
+ public void InterfaceMockedShouldImplementMocked()
+ {
+ Mock mock = new Mock();
+ IFoo mocked = mock.Object;
+ Assert.True(mocked is IMocked);
+ }
+
+ [Fact]
+ public void MockOfMockedInterfaceShouldReturnSame()
+ {
+ Mock mock = new Mock();
+ IMocked mocked = mock.Object as IMocked;
+ Assert.Same(mock, mocked.Mock);
+ }
+
+ [Fact]
+ public void ClassMockedShouldImplementMocked()
+ {
+ Mock mock = new Mock();
+ Foo mocked = mock.Object;
+ Assert.True(mocked is IMocked);
+ }
+
+ [Fact]
+ public void MockOfMockedClassShouldReturnSame()
+ {
+ Mock mock = new Mock();
+ IMocked mocked = mock.Object as IMocked;
+ Assert.Same(mock, mocked.Mock);
+ }
+
+ public class FooWithCtor
+ {
+ public FooWithCtor(int a) { }
+ }
+
+ [Fact]
+ public void ClassWithCtorMockedShouldImplementMocked()
+ {
+ Mock mock = new Mock(5);
+ FooWithCtor mocked = mock.Object;
+ Assert.True(mocked is IMocked);
+ }
+
+ [Fact]
+ public void MockOfMockedClassWithCtorShouldReturnSame()
+ {
+ Mock mock = new Mock(5);
+ IMocked mocked = mock.Object as IMocked;
+ Assert.Same(mock, mocked.Mock);
+ }
+
+ [Fact]
+ public void GetReturnsMockForAMocked()
+ {
+ var mock = new Mock();
+ var mocked = mock.Object;
+ Assert.Same(mock, Mock.Get(mocked));
+ }
+
+ [Fact]
+ public void GetReturnsMockForAMockedAbstract()
+ {
+ var mock = new Mock();
+ var mocked = mock.Object;
+ Assert.Same(mock, Mock.Get(mocked));
+ }
+
+ [Fact]
+ public void GetThrowsIfObjectIsNotMocked()
+ {
+ Assert.Throws(() => Mock.Get("foo"));
+ }
+
+ public class FooBase
+ {
+ }
+
+ public class Foo : FooBase
+ {
+ }
+
+ public interface IFoo
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/UnitTests/Moq.Tests.csproj b/UnitTests/Moq.Tests.csproj
index b63aca7c4..c98659b7e 100644
--- a/UnitTests/Moq.Tests.csproj
+++ b/UnitTests/Moq.Tests.csproj
@@ -1,166 +1,170 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {81BBC911-4916-4E10-A955-752AE47CB2B9}
- Library
- Properties
- Moq.Tests
- Moq.Tests
- v4.0
- 512
- true
- ..\Moq.snk
-
-
-
- true
- full
- false
- bin\Debug\
- TRACE;DEBUG;DESKTOP
- $(DefineConstants);NET3x
- prompt
- 4
- AllRules.ruleset
-
-
- full
- true
- bin\Release\
- TRACE;DESKTOP
- $(DefineConstants);NET3x
- prompt
- 4
- true
- AllRules.ruleset
-
-
-
- False
- ..\Lib\Castle\bin-NET40\Castle.Core.dll
-
-
- False
- ..\Lib\Castle\bin-NET35\Castle.Core.dll
-
-
- .\ClassLibrary1.dll
-
-
- .\ClassLibrary2.dll
-
-
- False
- False
- c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\EnvDTE.dll
-
-
-
- 3.5
-
-
- 3.0
-
-
- 3.5
-
-
-
-
- False
- ..\Lib\xUnit\xunit.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Moq.snk
-
-
-
-
- {1C91AC30-5977-4BE5-BA67-8EB186C03514}
- Moq
-
-
-
-
- {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
- 2
- 5
- 0
- primary
- False
- True
-
-
- {00020905-0000-0000-C000-000000000046}
- 8
- 5
- 0
- primary
- False
- True
-
-
- {0002E157-0000-0000-C000-000000000046}
- 5
- 3
- 0
- primary
- False
- True
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {81BBC911-4916-4E10-A955-752AE47CB2B9}
+ Library
+ Properties
+ Moq.Tests
+ Moq.Tests
+ v4.0
+ 512
+ true
+ ..\Moq.snk
+
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ TRACE;DEBUG;DESKTOP
+ $(DefineConstants);NET3x
+ prompt
+ 4
+ AllRules.ruleset
+
+
+ full
+ true
+ bin\Release\
+ TRACE;DESKTOP
+ $(DefineConstants);NET3x
+ prompt
+ 4
+ true
+ AllRules.ruleset
+
+
+
+ False
+ ..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll
+
+
+ False
+ ..\packages\Castle.Core.3.2.0\lib\net35\Castle.Core.dll
+ False
+
+
+ .\ClassLibrary1.dll
+
+
+ .\ClassLibrary2.dll
+
+
+ False
+ False
+ c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\EnvDTE.dll
+
+
+
+ 3.5
+
+
+ 3.0
+
+
+ 3.5
+
+
+
+
+ False
+ ..\packages\xunit.1.9.1\lib\net20\xunit.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Moq.snk
+
+
+
+
+
+ {1C91AC30-5977-4BE5-BA67-8EB186C03514}
+ Moq
+
+
+
+
+ {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
+ 2
+ 5
+ 0
+ primary
+ False
+ True
+
+
+ {00020905-0000-0000-C000-000000000046}
+ 8
+ 5
+ 0
+ primary
+ False
+ True
+
+
+ {0002E157-0000-0000-C000-000000000046}
+ 5
+ 3
+ 0
+ primary
+ False
+ True
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UnitTests/Regressions/IssueReportsFixture.cs b/UnitTests/Regressions/IssueReportsFixture.cs
index ce6865585..657785267 100644
--- a/UnitTests/Regressions/IssueReportsFixture.cs
+++ b/UnitTests/Regressions/IssueReportsFixture.cs
@@ -1,1772 +1,1770 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.IO;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.Text;
-using Moq;
-using Moq.Properties;
-using Moq.Protected;
-using Xunit;
-
-#if !SILVERLIGHT
-using System.ServiceModel;
-using System.ServiceModel.Web;
-using System.Web.UI.HtmlControls;
-#endif
-
-#region #181
-
-// NOTE class without namespace
-public class _181
-{
- [Fact]
- public void ReproTest()
- {
- var mock = new Mock();
- mock.Object.Dispose();
-
- mock.Verify(d => d.Dispose());
- }
-}
-
-#endregion
-
-namespace Moq.Tests.Regressions
-{
- public class IssueReportsFixture
- {
- #region #47
-
- [Fact]
- public void ShouldReturnListFromDateTimeArg()
- {
- var items = new List() { "Foo", "Bar" };
-
- var mock = new Mock(MockBehavior.Strict);
- mock
- .Setup(m => m.GetValuesSince(It.IsAny()))
- .Returns(items);
-
- var actual = mock.Object.GetValuesSince(DateTime.Now).ToList();
-
- Assert.Equal(items.Count, actual.Count);
- }
-
- public interface IMyClass
- {
- IEnumerable GetValuesSince(DateTime since);
- }
-
- #endregion
-
- #region #48
-
- public class Issue48
- {
- [Fact]
- public void ExpectsOnIndexer()
- {
- var mock = new Mock();
- mock.Setup(m => m[0]).Returns("a");
- mock.Setup(m => m[1]).Returns("b");
-
- Assert.Equal("a", mock.Object[0]);
- Assert.Equal("b", mock.Object[1]);
- Assert.Equal(default(string), mock.Object[2]);
- }
-
- public interface ISomeInterface
- {
- string this[int index] { get; set; }
- }
- }
-
- #endregion
-
- #region #52
-
- [Fact]
- public void ShouldNotOverridePreviousExpectation()
- {
- var ids = Enumerable.Range(1, 10);
- var mock = new Mock(MockBehavior.Strict);
-
- foreach (var id in ids)
- {
- mock.Setup(x => x.DoSomething(id));
- }
-
- var component = mock.Object;
-
- foreach (var id in ids)
- {
- component.DoSomething(id);
- }
- }
-
- public interface IOverwritingMethod
- {
- void DoSomething(int id);
- }
-
- #endregion
-
- #region #62
-
- public interface ISomething
- {
- void DoSomething() where U : T;
- }
-
- [Fact]
- public void CreatesMockWithGenericsConstraints()
- {
- var mock = new Mock>();
- }
-
- #endregion
-
- #region #60
-
- public interface IFoo
- {
- void DoThings(object arg);
- }
-
- [Fact]
- public void TwoExpectations()
- {
- Mock mocked = new Mock(MockBehavior.Strict);
- object arg1 = new object();
- object arg2 = new object();
-
- mocked.Setup(m => m.DoThings(arg1));
- mocked.Setup(m => m.DoThings(arg2));
-
- mocked.Object.DoThings(arg1);
- mocked.Object.DoThings(arg2);
-
- mocked.VerifyAll();
- }
-
- #endregion
-
- #region #21
-
- [Fact]
- public void MatchesLatestExpectations()
- {
- var mock = new Mock();
-
- mock.Setup(m => m.Method(It.IsAny())).Returns(0);
- mock.Setup(m => m.Method(It.IsInRange(0, 20, Range.Inclusive))).Returns(1);
-
- mock.Setup(m => m.Method(5)).Returns(2);
- mock.Setup(m => m.Method(10)).Returns(3);
-
- Assert.Equal(3, mock.Object.Method(10));
- Assert.Equal(2, mock.Object.Method(5));
- Assert.Equal(1, mock.Object.Method(6));
- Assert.Equal(0, mock.Object.Method(25));
- }
-
- public interface IEvaluateLatest
- {
- int Method(int value);
- }
-
- #endregion
-
- #region #49
-
- [Fact]
- public void UsesCustomMatchersWithGenerics()
- {
- var mock = new Mock();
-
- mock.Setup(e => e.Method(IsEqual.To(5))).Returns(1);
- mock.Setup(e => e.Method(IsEqual.To(6, "foo"))).Returns(2);
-
- Assert.Equal(1, mock.Object.Method(5));
- Assert.Equal(2, mock.Object.Method(6));
- }
-
- public static class IsEqual
- {
-#pragma warning disable 618
- [Matcher]
- public static T To(T value)
- {
- return value;
- }
-#pragma warning restore 618
-
- public static bool To(T left, T right)
- {
- return left.Equals(right);
- }
-
-#pragma warning disable 618
- [Matcher]
- public static T To(T value, U value2)
- {
- return value;
- }
-#pragma warning restore 618
-
- public static bool To(T left, T right, U value)
- {
- return left.Equals(right);
- }
- }
-
- #endregion
-
- #region #68
-
- [Fact]
- public void GetMockCastedToObjectThrows()
- {
- var mock = new Mock();
- object m = mock.Object;
-
- Assert.Throws(() => Mock.Get(m));
- }
-
- #endregion
-
- #region #69
-
- public interface IFooPtr
- {
- IntPtr Get(string input);
- }
-
- [Fact]
- public void ReturnsIntPtr()
- {
- Mock mock = new Mock(MockBehavior.Strict);
- IntPtr ret = new IntPtr(3);
-
- mock.Setup(m => m.Get("a")).Returns(ret);
-
- IntPtr ret3 = mock.Object.Get("a");
-
- Assert.Equal(ret, mock.Object.Get("a"));
- }
-
-
- #endregion
-
- #region #85
-
- public class Issue85
- {
- [Fact]
- public void FooTest()
- {
- // Setup
- var fooMock = new Mock();
- fooMock.CallBase = true;
- fooMock.Setup(o => o.GetBar()).Returns(new Bar());
- var bar = ((IFoolery)fooMock.Object).DoStuffToBar();
- Assert.NotNull(bar);
- }
-
- public interface IFoolery
- {
- Bar DoStuffToBar();
- }
-
- public class Foo : IFoolery
- {
- public virtual Bar GetBar()
- {
- return new Bar();
- }
-
- Bar IFoolery.DoStuffToBar()
- {
- return DoWeirdStuffToBar();
- }
-
- protected internal virtual Bar DoWeirdStuffToBar()
- {
- var bar = GetBar();
- //Would do stuff here.
- return bar;
- }
- }
-
- public class Bar
- {
- }
- }
-
- #endregion
-
- #region #89
-
- public class Issue89
- {
- [Fact]
- public void That_last_expectation_should_win()
- {
- var mock = new Mock();
- mock.Setup(s => s.Get(1)).Returns("blah");
- mock.Setup(s => s.Get(It.IsAny())).Returns("foo");
- mock.Setup(s => s.Get(1)).Returns("bar");
- Assert.Equal("bar", mock.Object.Get(1));
- }
-
- public interface ISample
- {
- string Get(int i);
- }
- }
-
- #endregion
-
- #region #134
-
- public class Issue134
- {
- [Fact]
- public void Test()
- {
- var target = new Mock();
- target.Setup(t => t.Submit(It.IsAny(), It.IsAny(), It.IsAny()));
-
- var e = Assert.Throws(() => target.VerifyAll());
-
- Assert.Contains(
- "IFoo t => t.Submit(It.IsAny(), It.IsAny(), new[] { It.IsAny() })",
- e.Message);
- }
-
- public interface IFoo
- {
- void Submit(string mailServer, string from, params int[] toRecipient);
- }
- }
-
- #endregion
-
- #region #136
-
- public class _136
- {
- // Fixed on PropertiesFixture.cs
- }
-
- #endregion
-
- #region #138
-
- public class _138
- {
- public interface SuperFoo
- {
- string Bar { get; set; }
- }
- public interface Foo : SuperFoo
- {
- string Baz { get; set; }
- }
-
- [Fact]
- public void superFooMockSetupAllProperties()
- {
- var repo = new MockRepository(MockBehavior.Default);
- var superFooMock = repo.Create();
- superFooMock.SetupAllProperties();
-
- var superFoo = superFooMock.Object;
- superFoo.Bar = "Bar";
- Assert.Equal("Bar", superFoo.Bar);
- }
- }
-
- #endregion
-
- #region #145
-
- public class _145
- {
- public interface IResolver
- {
- string Resolve();
- }
-
- public class DataWriter
- {
- }
-
- public class DataA { }
- public class DataB { }
-
- [Fact]
- public void ShouldDifferentiateBetweenGenericsParams()
- {
- var mock = new Mock();
- mock.Setup(m => m.Resolve>()).Returns("Success A");
-
- Assert.Equal("Success A", mock.Object.Resolve>());
-
- mock.Setup(m => m.Resolve>()).Returns("Success B");
-
- Assert.Equal("Success B", mock.Object.Resolve>());
- Assert.Equal("Success A", mock.Object.Resolve>());
- }
-
- }
-
- #endregion
-
- #region #111 & #155
-
- public class _111
- {
- [Fact]
- public void TestTypedParamsWithNoParams()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(p => p.Submit(It.IsAny(), It.IsAny()));
-
- mock.Object.Submit("foo");
-
- mock.VerifyAll();
- }
-
- [Fact]
- public void TestTypedParams()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(p => p.Submit(It.IsAny(), It.IsAny()));
-
- mock.Object.Submit("foo", 0, 1, 2);
-
- mock.VerifyAll();
- }
-
- [Fact]
- public void TestObjectParamsWithoutParams()
- {
- var mock = new Mock(MockBehavior.Strict);
- mock.Setup(p => p.Execute(It.IsAny(), It.IsAny