Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ThicknessPropertyViewModelTests.cs « Xamarin.PropertyEditing.Tests - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9e42a909c3264a48a94a857a1eec50100f90c8c (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Xamarin.PropertyEditing.Drawing;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Tests
{
	[TestFixture]
	internal class ThicknessPropertyViewModelTests
		:PropertyViewModelTests<CommonThickness, ThicknessPropertyViewModel>
	{
		[Test]
		public void Top ()
		{
			var property = GetPropertyMock ();
			var editor = GetBasicEditor (property.Object);
			var vm = GetViewModel (property.Object, new [] { editor });
			Assume.That (vm.Value, Is.EqualTo (new CommonThickness (0, 0, 0, 0)));

			bool topChanged = false, valueChanged = false;
			vm.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Top))
					topChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Value))
					valueChanged = true;
			};

			vm.Top = 5;
			Assert.That (vm.Value.Top, Is.EqualTo (5));
			Assert.That (topChanged, Is.True);
			Assert.That (valueChanged, Is.True);
		}

		[Test]
		public void Left ()
		{
			var property = GetPropertyMock ();
			var editor = GetBasicEditor (property.Object);
			var vm = GetViewModel (property.Object, new [] { editor });
			Assume.That (vm.Value, Is.EqualTo (new CommonThickness (0, 0, 0, 0)));

			bool leftChanged = false, valueChanged = false;
			vm.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Left))
					leftChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Value))
					valueChanged = true;
			};

			vm.Left = 5;
			Assert.That (vm.Value.Left, Is.EqualTo (5));
			Assert.That (leftChanged, Is.True);
			Assert.That (valueChanged, Is.True);
		}

		[Test]
		public void Right ()
		{
			var property = GetPropertyMock ();
			var editor = GetBasicEditor (property.Object);
			var vm = GetViewModel (property.Object, new [] { editor });
			Assume.That (vm.Value, Is.EqualTo (new CommonThickness (0, 0, 0, 0)));

			bool rightChanged = false, valueChanged = false;
			vm.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Right))
					rightChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Value))
					valueChanged = true;
			};

			vm.Right = 5;
			Assert.That (vm.Value.Right, Is.EqualTo (5));
			Assert.That (rightChanged, Is.True);
			Assert.That (valueChanged, Is.True);
		}

		[Test]
		public void Bottom ()
		{
			var property = GetPropertyMock ();
			var editor = GetBasicEditor (property.Object);
			var vm = GetViewModel (property.Object, new [] { editor });
			Assume.That (vm.Value, Is.EqualTo (new CommonThickness (0, 0, 0, 0)));

			bool bottomChanged = false, valueChanged = false;
			vm.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Bottom))
					bottomChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Value))
					valueChanged = true;
			};

			vm.Bottom = 5;
			Assert.That (vm.Value.Bottom, Is.EqualTo (5));
			Assert.That (bottomChanged, Is.True);
			Assert.That (valueChanged, Is.True);
		}

		[Test]
		public void ValueChangesProps ()
		{
			var property = GetPropertyMock ();
			var editor = GetBasicEditor (property.Object);
			var vm = GetViewModel (property.Object, new [] { editor });
			Assume.That (vm.Left, Is.EqualTo (0));
			Assume.That (vm.Top, Is.EqualTo (0));
			Assume.That (vm.Bottom, Is.EqualTo (0));
			Assume.That (vm.Right, Is.EqualTo (0));

			bool leftChanged = false, topChanged = false, bottomChanged = false, rightChanged = false, valueChanged = false;
			vm.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Left))
					leftChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Top))
					topChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Bottom))
					bottomChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Right))
					rightChanged = true;
				if (args.PropertyName == nameof (ThicknessPropertyViewModel.Value))
					valueChanged = true;
			};

			vm.Value = new CommonThickness (top:5, left: 10, bottom: 15, right: 20);

			Assert.That (vm.Left, Is.EqualTo (10));
			Assert.That (vm.Top, Is.EqualTo (5));
			Assert.That (vm.Bottom, Is.EqualTo (15));
			Assert.That (vm.Right, Is.EqualTo (20));
			Assert.That (topChanged, Is.True);
			Assert.That (leftChanged, Is.True);
			Assert.That (rightChanged, Is.True);
			Assert.That (bottomChanged, Is.True);
			Assert.That (valueChanged, Is.True);
		}

		protected override CommonThickness GetRandomTestValue (Random rand)
		{
			return new CommonThickness (rand.Next (), rand.Next (), rand.Next (), rand.Next ());
		}

		protected override ThicknessPropertyViewModel GetViewModel (TargetPlatform platform, IPropertyInfo property, IEnumerable<IObjectEditor> editors)
		{
			return new ThicknessPropertyViewModel (platform, property, editors);
		}
	}
}