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

Allow Mock<T>.Raise to raise events on child mocks #397

Merged
merged 2 commits into from
Jun 28, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jun 28, 2017

This fixes #166.

These three tests show that `Mock.Raise` does not correctly raise
events of "child mocks" in an expression such as:

    mock.Raise(_ => _.Foo.Bar.Event += null, ...)
                         ^^^^^
@@ -503,7 +503,7 @@ public void Raise(Action<T> eventExpression, EventArgs args)

try
{
this.DoRaise(ev, args);
ev.Target.DoRaise(ev.MemberInfo, args);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing this with ev.Target is what really fixes this issue.

@@ -352,7 +352,7 @@ public void DoesNotRaiseEventOnSubObject()

mock.Raise(p => p.Adder.Added += null, EventArgs.Empty);

Assert.False(raised);
Assert.True(raised);
Copy link
Contributor Author

@stakx stakx Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is in effect a functional change. The changes of this change breaking any client code are probably quite small (see #166 (comment)).

At the same time, replacing this unit test with its exact opposite also has the advantage of fixing an inconsistency, since the quickstart guide already documents the ability to raise events on sub-objects.

@stakx stakx merged commit 6d9c06e into devlooped:develop Jun 28, 2017
@stakx stakx deleted the raises-wrong-or-no-event branch June 28, 2017 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant