Merge pull request #1452 from CosmosOS/event_test

Add test for eventhandler
This commit is contained in:
Charles Betros 2020-08-21 14:17:47 -05:00 committed by GitHub
commit 3cd0f371d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.");
}
}
}