Skip to content

Commit

Permalink
Fixed #206: Linq-to-Mocks never returns on implicit Boolean property.
Browse files Browse the repository at this point in the history
Added support to negation of implicit Boolean property.
ExpressionVisitor method names and visibility changed to adecuate it to the .NET Framework 4.0 ExpressionVisitor.
Guard now receives an Expression to get the parameter name.

git-svn-id: http://moq.googlecode.com/svn/trunk@641 b33fba48-7441-0410-8d5c-f397f7ceaa6c
  • Loading branch information
marianoor committed Nov 8, 2009
1 parent b161d54 commit 732fe52
Show file tree
Hide file tree
Showing 27 changed files with 1,144 additions and 998 deletions.
40 changes: 36 additions & 4 deletions Moq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,72 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Debug35|Any CPU = Debug35|Any CPU
Debug35|x86 = Debug35|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
Release35|Any CPU = Release35|Any CPU
Release35|x86 = Release35|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.ActiveCfg = Debug|x86
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.Build.0 = Debug|x86
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.ActiveCfg = Debug|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug35|x86.ActiveCfg = Debug35|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.Build.0 = Release|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.ActiveCfg = Release|x86
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.Build.0 = Release|x86
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.ActiveCfg = Release|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release35|Any CPU.Build.0 = Release35|Any CPU
{1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release35|x86.ActiveCfg = Release35|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug|x86.ActiveCfg = Debug|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug|x86.Build.0 = Debug|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug35|x86.ActiveCfg = Debug35|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Debug35|x86.Build.0 = Debug35|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|Any CPU.Build.0 = Release|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|x86.ActiveCfg = Release|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|x86.Build.0 = Release|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release35|Any CPU.Build.0 = Release35|Any CPU
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release35|x86.ActiveCfg = Release35|x86
{81BBC911-4916-4E10-A955-752AE47CB2B9}.Release35|x86.Build.0 = Release35|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug|x86.ActiveCfg = Debug|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug|x86.Build.0 = Debug|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug35|x86.ActiveCfg = Debug35|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Debug35|x86.Build.0 = Debug35|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release|Any CPU.Build.0 = Release|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release|x86.ActiveCfg = Release|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release35|Any CPU.Build.0 = Release35|Any CPU
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release35|x86.ActiveCfg = Release35|x86
{5136C8E1-E17F-481F-B29A-C7FAB528BD2D}.Release35|x86.Build.0 = Release35|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug|x86.ActiveCfg = Debug|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug|x86.Build.0 = Debug|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug35|x86.ActiveCfg = Debug35|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Debug35|x86.Build.0 = Debug35|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|Any CPU.Build.0 = Release|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|x86.ActiveCfg = Release|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release35|Any CPU.Build.0 = Release35|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release35|x86.ActiveCfg = Release35|x86
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release35|x86.Build.0 = Release35|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
72 changes: 72 additions & 0 deletions Source.Silverlight/Moq.Silverlight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,78 @@
<TargetFrameworkSDKDirectory>$(SilverlightBuildResources)Libraries\Client\</TargetFrameworkSDKDirectory>
<SilverlightRuntimeVersion>2.0.31005.0</SilverlightRuntimeVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug35|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug35\</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT</DefineConstants>
<DocumentationFile>bin\Debug\Moq.Silverlight.xml</DocumentationFile>
<NoStdLib>true</NoStdLib>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>bin\Debug\Moq.Silverlight.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisInputAssembly>bin\Debug35\Moq.Silverlight.dll</CodeAnalysisInputAssembly>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
<NoConfig>true</NoConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug35|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug35\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
<DocumentationFile>bin\Debug\Moq.Silverlight.xml</DocumentationFile>
<NoStdLib>true</NoStdLib>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>bin\Debug\Moq.Silverlight.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisInputAssembly>bin\x86\Debug35\Moq.Silverlight.dll</CodeAnalysisInputAssembly>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release35|AnyCPU'">
<OutputPath>bin\Release35\</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;NET35</DefineConstants>
<DocumentationFile>bin\Release\Moq.Silverlight.xml</DocumentationFile>
<Optimize>true</Optimize>
<NoStdLib>true</NoStdLib>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>bin\Release\Moq.Silverlight.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisInputAssembly>bin\Release35\Moq.Silverlight.dll</CodeAnalysisInputAssembly>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<NoConfig>true</NoConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release35|x86'">
<OutputPath>bin\x86\Release35\</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
<DocumentationFile>bin\Release\Moq.Silverlight.xml</DocumentationFile>
<Optimize>true</Optimize>
<NoStdLib>true</NoStdLib>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>bin\Release\Moq.Silverlight.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisInputAssembly>bin\x86\Release35\Moq.Silverlight.dll</CodeAnalysisInputAssembly>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<Import Project="$(SilverlightBuildResources)MSBuild\Microsoft.Silverlight.CSharp.targets" />
<!--<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" />-->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
18 changes: 8 additions & 10 deletions Source/AdvancedMatcherAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,26 @@ namespace Moq
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
internal sealed class AdvancedMatcherAttribute : Attribute
{
Type matcherType;

public AdvancedMatcherAttribute(Type matcherType)
{
Guard.ArgumentNotNull(matcherType, "matcherType");
Guard.CanBeAssigned(matcherType, typeof(IMatcher), "matcherType");
Guard.NotNull(() => matcherType, matcherType);
Guard.CanBeAssigned(() => matcherType, matcherType, typeof(IMatcher));

this.matcherType = matcherType;
this.MatcherType = matcherType;
}

public Type MatcherType { get { return matcherType; } }
public Type MatcherType { get; private set; }

public IMatcher CreateMatcher()
{
try
{
return (IMatcher)Activator.CreateInstance(matcherType);
return (IMatcher)Activator.CreateInstance(MatcherType);
}
catch (TargetInvocationException tie)
catch (TargetInvocationException e)
{
throw tie.InnerException;
throw e.InnerException;
}
}
}
}
}
1 change: 0 additions & 1 deletion Source/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using IQToolkit;

namespace Moq
{
Expand Down
13 changes: 6 additions & 7 deletions Source/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
using System.Text;
using System.Text.RegularExpressions;
using Moq.Properties;
using IQToolkit;

namespace Moq
{
Expand All @@ -60,7 +59,7 @@ internal static class ExpressionExtensions
/// </summary>
public static LambdaExpression ToLambda(this Expression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

LambdaExpression lambda = expression as LambdaExpression;
if (lambda == null)
Expand All @@ -84,7 +83,7 @@ public static LambdaExpression ToLambda(this Expression expression)
/// <exception cref="ArgumentException">If the body is not a method call.</exception>
public static MethodCallExpression ToMethodCall(this LambdaExpression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

var methodCall = expression.Body as MethodCallExpression;
if (methodCall == null)
Expand Down Expand Up @@ -123,7 +122,7 @@ public static PropertyInfo ToPropertyInfo(this LambdaExpression expression)
/// </summary>
public static bool IsProperty(this LambdaExpression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

return IsProperty(expression.Body);
}
Expand All @@ -133,7 +132,7 @@ public static bool IsProperty(this LambdaExpression expression)
/// </summary>
public static bool IsProperty(this Expression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

var prop = expression as MemberExpression;

Expand All @@ -148,7 +147,7 @@ public static bool IsProperty(this Expression expression)
/// </summary>
public static bool IsPropertyIndexer(this LambdaExpression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

return IsPropertyIndexer(expression.Body);
}
Expand All @@ -161,7 +160,7 @@ public static bool IsPropertyIndexer(this LambdaExpression expression)
/// </summary>
public static bool IsPropertyIndexer(this Expression expression)
{
Guard.ArgumentNotNull(expression, "expression");
Guard.NotNull(() => expression, expression);

var call = expression as MethodCallExpression;

Expand Down
7 changes: 2 additions & 5 deletions Source/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ public static bool IsMockeable(this Type typeToMock)
{
// A value type does not match any of these three
// condition and therefore returns false.
return
typeToMock.IsInterface ||
typeToMock.IsAbstract ||
(typeToMock.IsClass && !typeToMock.IsSealed);
return typeToMock.IsInterface || typeToMock.IsAbstract || (typeToMock.IsClass && !typeToMock.IsSealed);
}

public static bool CanOverrideGet(this PropertyInfo property)
Expand Down Expand Up @@ -187,7 +184,7 @@ public static bool CanOverrideSet(this PropertyInfo property)
public static EventInfo GetEvent<TMock>(this Action<TMock> eventExpression, TMock mock)
where TMock : class
{
Guard.ArgumentNotNull(eventExpression, "eventExpression");
Guard.NotNull(() => eventExpression, eventExpression);

MethodBase addRemove = null;
using (var context = new FluentMockContext())
Expand Down
16 changes: 11 additions & 5 deletions Source/FluentMockContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,25 @@ namespace Moq
internal class FluentMockContext : IDisposable
{
[ThreadStatic]
static FluentMockContext current;
private static FluentMockContext current;

List<MockInvocation> invocations = new List<MockInvocation>();
private List<MockInvocation> invocations = new List<MockInvocation>();

public static FluentMockContext Current { get { return current; } }
public static FluentMockContext Current
{
get { return current; }
}

/// <summary>
/// Having an active fluent mock context means that the invocation
/// is being performed in "trial" mode, just to gather the
/// target method and arguments that need to be matched later
/// when the actual invocation is made.
/// </summary>
public static bool IsActive { get { return current != null; } }
public static bool IsActive
{
get { return current != null; }
}

public FluentMockContext()
{
Expand Down Expand Up @@ -105,7 +111,7 @@ public MockInvocation(Mock mock, ICallContext invocation, Match matcher)
public Mock Mock { get; private set; }

public ICallContext Invocation { get; private set; }

public Match Match { get; private set; }

public void Dispose()
Expand Down
Loading

0 comments on commit 732fe52

Please sign in to comment.