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

Fixed PropertyBehavior method to work with internal properties #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Rhino.Mocks.Tests.Model/Internal.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
namespace Rhino.Mocks.Tests.Model
{
internal class Internal
Expand All @@ -11,5 +12,12 @@ internal virtual string Foo()
{
return Bar();
}

internal virtual object Baz
{
get { throw new Exception("exception thrown from baz property getter"); }
set { throw new Exception("exception thrown from baz property setter"); }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Rhino.Mocks.Tests.Model;
using Xunit;

namespace Rhino.Mocks.Tests.FieldsProblem
{
public class FieldProblem_PropertyBehaviorOnInternalProperty
{
[Fact]
public void CanUsePropertyBehaviorOnInternalProperty()
{
MockRepository mocks = new MockRepository();
var mock = mocks.PartialMock<Internal>();
mock.Stub(m => m.Baz).PropertyBehavior();

mock.Baz = "baz";

Assert.Equal("baz", mock.Baz);
}
}
}
1 change: 1 addition & 0 deletions Rhino.Mocks.Tests/Rhino.Mocks.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<Compile Include="FieldsProblem\FieldProblem_Bill.cs" />
<Compile Include="FieldsProblem\FieldProblem_JPBoodhoo.cs" />
<Compile Include="FieldsProblem\FieldProblem_KeithD.cs" />
<Compile Include="FieldsProblem\FieldProblem_PropertyBehaviorOnInternalProperty.cs" />
<Compile Include="MethodProblems\MethodProblem_JPBoodhoo.cs" />
<Compile Include="PartialMockTestsAAA.cs" />
<Compile Include="MultiMocksWithAAA.cs" />
Expand Down
8 changes: 6 additions & 2 deletions Rhino.Mocks/Impl/MethodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,12 @@ private PropertyInfo GetPropertyFromMethod(MethodInfo method)
continue;
types.Add(args[i].ParameterType);
}
PropertyInfo prop = expectation.Method.DeclaringType.GetProperty(propName,
(Type[]) types.ToArray(typeof (Type)));
PropertyInfo prop = expectation.Method.DeclaringType.GetProperty(propName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
null, null,
(Type[])types.ToArray(typeof(Type)),
null);

return prop;
}

Expand Down