Skip to content

Fix issue #325 #13

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

Merged
merged 1 commit into from
Jun 21, 2012
Merged
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
4 changes: 2 additions & 2 deletions Source/Interceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void Intercept(ICallContext invocation)
// TODO: validate we can get the event?
var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(4));

if (this.Mock.CallBase)
if (this.Mock.CallBase && !eventInfo.DeclaringType.IsInterface)
{
invocation.InvokeBase();
}
Expand All @@ -186,7 +186,7 @@ public void Intercept(ICallContext invocation)
// TODO: validate we can get the event?
var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(7));

if (this.Mock.CallBase)
if (this.Mock.CallBase && !eventInfo.DeclaringType.IsInterface)
{
invocation.InvokeBase();
}
Expand Down
49 changes: 49 additions & 0 deletions UnitTests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,55 @@ public class Baz : ClassLibrary2.Bar

#endregion

#region #325

public class _325
{
[Fact]
public void SubscribingWorks()
{
var target = new Mock<Foo> { CallBase = true };
target.As<IBar>();

var bar = (IBar)target.Object;
var raised = false;
bar.SomeEvent += (sender, e) => raised = true;

target.As<IBar>().Raise(b => b.SomeEvent += null, EventArgs.Empty);

Assert.True(raised);
}

[Fact]
public void UnsubscribingWorks()
{
var target = new Mock<Foo> { CallBase = true };
target.As<IBar>();

var bar = (IBar)target.Object;
var raised = false;
EventHandler handler = (sender, e) => raised = true;
bar.SomeEvent += handler;
bar.SomeEvent -= handler;

target.As<IBar>().Raise(b => b.SomeEvent += null, EventArgs.Empty);

Assert.False(raised);
}

public class Foo
{
}

public interface IBar
{
event EventHandler SomeEvent;
}

}

#endregion

#region Recursive issue

public class RecursiveFixture
Expand Down