Ooui-tws-port/Tests/MessageSendTests.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2017-06-17 00:19:18 +00:00
using System;
2017-07-07 18:47:59 +00:00
#if NUNIT
using NUnit.Framework;
using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
using TestMethodAttribute = NUnit.Framework.TestCaseAttribute;
#else
2017-06-17 00:19:18 +00:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
2017-07-07 18:47:59 +00:00
#endif
2017-06-17 00:19:18 +00:00
using Ooui;
namespace Tests
{
[TestClass]
public class MessageSendTests
{
[TestMethod]
public void SendTriggers ()
{
var b = new Button ();
var sendCount = 0;
b.MessageSent += m => {
if (m.Key == "test") sendCount++;
};
b.Send (Message.Event (b.Id, "test"));
Assert.AreEqual (1, sendCount);
}
[TestMethod]
public void ChildSendTriggers ()
{
var p = new Div ();
var b = new Button ();
p.AppendChild (b);
var sendCount = 0;
void HandleMessage (Message m) {
if (m.Key == "test") sendCount++;
};
p.MessageSent += HandleMessage;
b.Send (Message.Event (b.Id, "test"));
Assert.AreEqual (1, sendCount);
}
[TestMethod]
public void OldChildSendDoesntTrigger ()
{
var p = new Div ();
var b = new Button ();
p.AppendChild (b);
var sendCount = 0;
void HandleMessage (Message m) {
if (m.Key == "test") sendCount++;
};
p.MessageSent += HandleMessage;
b.Send (Message.Event (b.Id, "test"));
p.RemoveChild (b);
b.Send (Message.Event (b.Id, "test"));
Assert.AreEqual (1, sendCount);
}
}
}