summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/PickerTests.cs
blob: 859f902563dc31bd7c31f8ca8b3cee7d5eacf6fc (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
56
57
58
59
using System;

using NUnit.Framework;
using System.Collections.Generic;

namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class PickerTests : BaseTestFixture
	{
		[Test]
		public void TestSetSelectedIndexOnNullRows()
		{
			var picker = new Picker ();

			Assert.IsEmpty (picker.Items);
			Assert.AreEqual (-1, picker.SelectedIndex);

			picker.SelectedIndex = 2;

			Assert.AreEqual (-1, picker.SelectedIndex);		
		}

		[Test]
		public void TestSelectedIndexInRange ()
		{
			var picker = new Picker { Items =  { "John", "Paul", "George", "Ringo" } };

			picker.SelectedIndex = 2;
			Assert.AreEqual (2, picker.SelectedIndex);

			picker.SelectedIndex = 42;
			Assert.AreEqual (3, picker.SelectedIndex);

			picker.SelectedIndex = -1;
			Assert.AreEqual (-1, picker.SelectedIndex);

			picker.SelectedIndex = -42;
			Assert.AreEqual (-1, picker.SelectedIndex);
		}

		[Test]
		public void TestSelectedIndexChangedOnCollectionShrink()
		{
			var picker = new Picker { Items = { "John", "Paul", "George", "Ringo" }, SelectedIndex = 3 };

			Assert.AreEqual (3, picker.SelectedIndex);

			picker.Items.RemoveAt (3);
			picker.Items.RemoveAt (2);


			Assert.AreEqual (1, picker.SelectedIndex);

			picker.Items.Clear ();
			Assert.AreEqual (-1, picker.SelectedIndex);
		}
	}	
}