Skip to content

Instantly share code, notes, and snippets.

@Vannevelj
Created February 1, 2016 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vannevelj/5d0e348fd1424492ff8f to your computer and use it in GitHub Desktop.
Save Vannevelj/5d0e348fd1424492ff8f to your computer and use it in GitHub Desktop.
public class Domain
{
public event EventHandler<MyArgs> MyEvent;
public void Invoke()
{
var sw = new Stopwatch();
sw.Start();
Console.WriteLine($"{sw.ElapsedMilliseconds}: Entering delay");
while (sw.ElapsedMilliseconds < 5000)
{
}
Console.WriteLine($"{sw.ElapsedMilliseconds}: Invoking event");
MyEvent?.Invoke(this, new MyArgs { TheAnswer = 42 });
Console.WriteLine($"{sw.ElapsedMilliseconds}: Event invoked");
sw.Stop();
}
}
public class MyArgs : EventArgs
{
public int TheAnswer = 69;
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var d = new Domain();
d.Invoke();
d.MyEvent += (o, e) =>
{
Assert.AreEqual(e.TheAnswer, "42");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment