I have tried to raise event in cSharp to notify code change in my application in order to have tellDontAsk scenario.
I have simple class that implement from event class
public class SimpleTellDontAsk : ISomeEvent
{
public void doSomething(string text, EventHandlerArgs args)
{
Console.WriteLine("Email this message {0}", text);
//sending message with email
args.IsDo = true;
RaiseEvent(this, args);
}
public event EventHandler RaiseEvent;
}
I define my event class like below
public interface ISomeEvent
{
event EventHandler RaiseEvent;
}
public class SomeEvent : ISomeEvent
{
public event EventHandler RaiseEvent;
}
public class EventHandlerArgs : EventArgs
{
public bool IsDo { get; set; }
}
I try to use my code with Nunit test
[TestFixture]
public class TestSimpleTellDontAsk
{
[Test]
public void Given_Text_When_doSomething_Then_ShouldPubliushArgs()
{
var tellDontAsk = new SimpleTellDontAsk();
var senderEventHandlerArgs = new EventHandlerArgs();
tellDontAsk.doSomething("test message", senderEventHandlerArgs);
Assert.IsTrue(senderEventHandlerArgs.IsDo);
}
}
When I run the test it comes up with null reference exception
System.NullReferenceException : Object reference not set to an instance of an object.
I believe something is missing but could not figure out , any idea ?