Ooui-tws-port/Tests/ButtonTests.cs

66 lines
1.8 KiB
C#
Raw Normal View History

2017-06-14 03:42:06 +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
using Microsoft.VisualStudio.TestTools.UnitTesting;
2017-07-07 18:47:59 +00:00
#endif
2017-06-14 03:42:06 +00:00
using Ooui;
namespace Tests
{
[TestClass]
public class ButtonTests
{
[TestMethod]
public void DefaultCtor ()
{
var b = new Button ();
2017-06-17 00:33:27 +00:00
Assert.AreEqual (0, b.Children.Count);
2017-06-15 06:20:51 +00:00
Assert.AreEqual ("button", b.TagName);
2017-06-14 04:17:50 +00:00
Assert.AreEqual ("", b.Text);
2017-06-14 03:42:06 +00:00
}
2017-06-14 23:48:42 +00:00
[TestMethod]
public void TextCtor ()
{
var b = new Button ("Hello World!");
2017-06-17 00:33:27 +00:00
Assert.AreEqual (1, b.Children.Count);
2017-06-14 23:48:42 +00:00
Assert.AreEqual ("Hello World!", b.Text);
}
2017-06-15 06:10:58 +00:00
[TestMethod]
public void Clicked ()
{
var b = new Button ("Hello World!");
var clicked = false;
var listened = false;
b.MessageSent += m => {
listened = listened || (m.MessageType == MessageType.Listen);
};
Assert.IsFalse (listened);
b.Click += (s, e) => {
2017-06-15 06:10:58 +00:00
clicked = true;
};
Assert.IsTrue (listened);
Assert.IsFalse (clicked);
2017-06-15 07:58:55 +00:00
b.Receive (Message.Event (b.Id, "click"));
2017-06-15 06:10:58 +00:00
Assert.IsTrue (clicked);
}
2017-06-19 01:38:00 +00:00
[TestMethod]
public void ChangeButtonType ()
{
var b = new Button ();
Assert.AreEqual (1, b.StateMessages.Count);
Assert.AreEqual (ButtonType.Submit, b.Type);
b.Type = ButtonType.Button;
Assert.AreEqual (2, b.StateMessages.Count);
Assert.AreEqual (ButtonType.Button, b.StateMessages[1].Value);
}
2017-06-14 03:42:06 +00:00
}
}