summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/EntryUnitTests.cs
blob: 83f71b9a38ddc7b22a50641509fb898a59d84249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Diagnostics;

using NUnit.Framework;

namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class EntryUnitTests : BaseTestFixture
	{
		[Test]
		public void ValueChangedFromSetValue()
		{
			var entry = new Entry();

			const string value = "Foo";

			bool signaled = false;
			entry.TextChanged += (sender, args) => {
				signaled = true;
				Assert.AreEqual (value, args.NewTextValue);
			};

			entry.SetValue (Entry.TextProperty, value);

			Assert.IsTrue (signaled, "ValueChanged did not fire");
		}

		[TestCase (null, "foo")]
		[TestCase ("foo", "bar")]
		[TestCase ("foo", null)]
		public void ValueChangedArgs (string initial, string final)
		{
			var entry = new Entry {
				Text = initial
			};

			string oldValue = null;
			string newValue = null;

			Entry entryFromSender = null;

			entry.TextChanged += (s, e) => {
				entryFromSender = (Entry)s;
				oldValue = e.OldTextValue;
				newValue = e.NewTextValue;
			};

			entry.Text = final;

			Assert.AreEqual (entry, entryFromSender);
			Assert.AreEqual (initial, oldValue);
			Assert.AreEqual (final, newValue);
		}
	}
}