summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/PinchGestureRecognizerTests.cs
blob: 3af550358bf2645d95c6f501cb6df6f4fba7ce8c (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
´╗┐using System;
using NUnit.Framework;

namespace Xamarin.Forms.Core.UnitTests
{
	public class PinchGestureRecognizerTests  : BaseTestFixture
	{
		[Test]
		public void Constructor ()
		{
			var pinch = new PinchGestureRecognizer ();
	
		}

		[Test]
		public void PinchStartedTest ()
		{
			var view = new View ();
			var pinch = new PinchGestureRecognizer ();

			GestureStatus result = GestureStatus.Canceled;
			var point = new Point (10, 10);
			var resultPoint = Point.Zero;
			pinch.PinchUpdated += (object sender, PinchGestureUpdatedEventArgs e) => {
				result = e.Status;
				resultPoint = e.ScaleOrigin;
			};

			((IPinchGestureController)pinch).SendPinchStarted (view,point);
			Assert.AreEqual (GestureStatus.Started, result);
			Assert.AreEqual (point, resultPoint);
		}

		[Test]
		public void PinchCompletedTest ()
		{
			var view = new View ();
			var pinch = new PinchGestureRecognizer ();

			GestureStatus result = GestureStatus.Canceled;
			pinch.PinchUpdated += (object sender, PinchGestureUpdatedEventArgs e) => {
				result = e.Status;
			};

			((IPinchGestureController)pinch).SendPinchEnded (view);
			Assert.AreEqual (GestureStatus.Completed, result);
		}

		[Test]
		public void PinchUpdatedTest ()
		{
			var view = new View ();
			var pinch = new PinchGestureRecognizer ();
			var point = new Point (10, 10);
			var resultPoint = Point.Zero;
			double result = -1;
			pinch.PinchUpdated += (object sender, PinchGestureUpdatedEventArgs e) => {
				result = e.Scale;
				resultPoint = e.ScaleOrigin;
			};

			((IPinchGestureController)pinch).SendPinch (view, 2, point);
			Assert.AreEqual (2, result);
		}

		[Test]
		public void OnlyOnePinchGesturePerViewTest ()
		{
			var view = new View ();
			view.GestureRecognizers.Add(new PinchGestureRecognizer ());
			Assert.Throws<InvalidOperationException> (() => view.GestureRecognizers.Add (new PinchGestureRecognizer ()));
		}
	}
}