Hi,
The example below should answer both questions:
The Code Under Test:
public class Foo
{
public void AddHttpListener(HTTPListener httpListener)
{
httpListener.RequestReceived += OnRequestReceived;
}
public void OnRequestReceived(object sender, EventArgs e)
{
//some logic
}
}
public class HTTPListener
{
public event EventHandler RequestReceived;
}
And the test code:
[TestMethod , Isolated]
public void TestMethod1()
{
//ARRANGE
var foo = Isolate.Fake.Instance<Foo>(Members.CallOriginal);
var httpListener = new HTTPListener();
//ACT
foo.AddHttpListener(httpListener);
Isolate.Invoke.Event(() => httpListener.RequestReceived += null, null, EventArgs.Empty);
//ASSERT
Isolate.Verify.WasCalledWithAnyArguments(() => foo.OnRequestReceived(null, null));
}
You can tell that the eventhandler is correctly assigned because the invokation of the event triggered it (Isolate.Verify) shows that.
2 things to know about the test above:
1) The test should be [Isolated] so the invokation would work.
2) You can use verify only on fake objects, thats why I faked Foo with call original.
Please let me know if it helps.