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

PanelGroupViewModelTests.cs « Xamarin.PropertyEditing.Tests - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 62389ac5a91b24add7db8a52746905710ab57698 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Tests
{
	[TestFixture]
	internal class PanelGroupViewModelTests
	{
		[Test]
		public void HasChildElementsUpdates ()
		{
			var property = new Mock<IPropertyInfo> ();
			property.Setup (p => p.Name).Returns ("Name");
			property.Setup (p => p.Category).Returns ("Category");
			property.Setup (p => p.Type).Returns (typeof(string));
			property.Setup (p => p.IsUncommon).Returns (false);

			var editor = new MockObjectEditor (property.Object);
			var propertyVm = new StringPropertyViewModel (MockEditorProvider.MockPlatform, property.Object, new[] { editor });
			var group = new PanelGroupViewModel (MockEditorProvider.MockPlatform, "Category", new[] { propertyVm });

			Assert.That (group.HasChildElements, Is.True);

			bool changed = false;
			group.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof(PanelGroupViewModel.HasChildElements))
					changed = true;
			};

			group.Remove (propertyVm);
			Assert.That (group.HasChildElements, Is.False);
			Assert.That (changed, Is.True, "INPC did not fire for HasChildElements during remove");
			changed = false;

			group.Add (propertyVm);
			Assert.That (group.HasChildElements, Is.True);
			Assert.That (changed, Is.True, "INPC did not fire for HasChildElements during add");
		}

		[Test]
		public void HasUncommonElementsUpdates ()
		{
			var property = new Mock<IPropertyInfo> ();
			property.Setup (p => p.Name).Returns ("Name");
			property.Setup (p => p.Category).Returns ("Category");
			property.Setup (p => p.Type).Returns (typeof (string));
			property.Setup (p => p.IsUncommon).Returns (true);

			var editor = new MockObjectEditor (property.Object);
			var propertyVm = new StringPropertyViewModel (MockEditorProvider.MockPlatform, property.Object, new[] { editor });
			var group = new PanelGroupViewModel (MockEditorProvider.MockPlatform, "Category", new[] { propertyVm });

			Assert.That (group.HasChildElements, Is.True);
			Assert.That (group.HasUncommonElements, Is.True);

			bool childChanged = false, uncommonChanged = false;
			group.PropertyChanged += (sender, args) => {
				if (args.PropertyName == nameof (PanelGroupViewModel.HasChildElements))
					childChanged = true;
				else if (args.PropertyName == nameof(PanelGroupViewModel.HasUncommonElements))
					uncommonChanged = true;
			};

			group.Remove (propertyVm);
			Assert.That (group.HasChildElements, Is.False);
			Assert.That (group.HasUncommonElements, Is.False);
			Assert.That (childChanged, Is.True, "INPC did not fire for HasChildElements during remove");
			Assert.That (uncommonChanged, Is.True, "INPC did not fire for HasUncommonElements during remove");
			childChanged = false;

			group.Add (propertyVm);
			Assert.That (group.HasChildElements, Is.True);
			Assert.That (group.HasUncommonElements, Is.True);
			Assert.That (childChanged, Is.True, "INPC did not fire for HasChildElements during add");
			Assert.That (uncommonChanged, Is.True, "INPC did not fire for HasUncommonElements during add");
		}
	}
}