Add test for eventhandler

This commit is contained in:
Charles Betros 2020-08-21 13:55:54 -05:00
parent 89e5f33a5a
commit 434d3a6171
2 changed files with 38 additions and 1 deletions

View file

@ -37,6 +37,7 @@ namespace Cosmos.Compiler.Tests.Bcl
BitConverterTest.Execute();
UnsafeCodeTest.Execute();
DelegatesTest.Execute();
EventsTest.Execute();
RandomTests.Execute();
// System.Collections
@ -44,7 +45,7 @@ namespace Cosmos.Compiler.Tests.Bcl
// System.Collections.Generic
ListTest.Execute();
QueueTest.Execute();
QueueTest.Execute();
DictionaryTest.Execute();
// System.Text

View file

@ -0,0 +1,36 @@
using System;
using Cosmos.TestRunner;
namespace Cosmos.Compiler.Tests.Bcl.System
{
internal class TestClass
{
private static bool handlerInvoked;
public event EventHandler EventFired = (sender, args) =>
{
handlerInvoked = true;
};
private void OnEventFired(EventArgs e)
{
EventHandler handler = EventFired;
handler?.Invoke(this, e);
}
public bool ExecuteTest()
{
OnEventFired(null);
return handlerInvoked;
}
}
public class EventsTest
{
public static void Execute()
{
var test = new TestClass();
Assert.IsTrue(test.ExecuteTest(), "Event handler was not invoked.");
}
}
}