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

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

namespace Xamarin.PropertyEditing.Tests
{
	[TestFixture]
	public class ResourceSelectorViewModelTests
	{
		[Test]
		public void Resources()
		{
			var tests = new StringViewModelTests();
			var mproperty = tests.GetPropertyMock ("Property");

			object target = new object();

			var resource = new Resource<string> (MockResourceProvider.SystemResourcesSource, "Resource", "value");
			var mprovider = new Mock<IResourceProvider>();

			mprovider.Setup (r => r.GetResourcesAsync (target, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource });

			var vm = new ResourceSelectorViewModel (mprovider.Object, new[] { target }, mproperty.Object);
			Assert.That (vm.Resources, Contains.Item (resource));
		}

		[Test]
		public void MultipleTargetResources()
		{
			var tests = new StringViewModelTests();
			var mproperty = tests.GetPropertyMock ("Property");

			object target = new object();
			object target2 = new object();

			var resource = new Resource<string> (MockResourceProvider.SystemResourcesSource, "Resource", "value");
			var resource2 = new Resource<string> (MockResourceProvider.SystemResourcesSource, "Resource2", "value2");
			var resource3 = new Resource<string> (MockResourceProvider.SystemResourcesSource, "Resource3", "value3");

			var mprovider = new Mock<IResourceProvider>();
			mprovider.Setup (r => r.GetResourcesAsync (target, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource, resource3 });
			mprovider.Setup (r => r.GetResourcesAsync (target2, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource2, resource3 });

			var vm = new ResourceSelectorViewModel (mprovider.Object, new[] { target, target2 }, mproperty.Object);
			Assert.That (vm.Resources, Does.Not.Contain (resource));
			Assert.That (vm.Resources, Does.Not.Contain (resource2));
			Assert.That (vm.Resources, Contains.Item (resource3));
		}

		[Test]
		public void FuzzyFilter ()
		{
			var tests = new StringViewModelTests();
			var mproperty = tests.GetPropertyMock ("Property");

			var target = new object();
			var resource = new Resource<string> (MockResourceProvider.SystemResourcesSource, "@android:string/foo_bar", "value");
			var resource2 = new Resource<string> (MockResourceProvider.SystemResourcesSource, "@android:string/foo_baz", "value");

			var mprovider = new Mock<IResourceProvider>();
			mprovider.Setup (r => r.GetResourcesAsync (target, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource, resource2 });

			var vm = new ResourceSelectorViewModel (mprovider.Object, new[] { target }, mproperty.Object);
			Assume.That (vm.Resources, Contains.Item (resource));
			Assume.That (vm.Resources, Contains.Item (resource2));

			vm.FilterText = "baz";
			Assert.That (vm.Resources, Does.Not.Contain (resource));
			Assert.That (vm.Resources, Contains.Item (resource2));

			vm.FilterText = "string";
			Assert.That (vm.Resources, Contains.Item (resource));
			Assert.That (vm.Resources, Contains.Item (resource2));
		}

		[Test]
		public void OnlyLocal ()
		{
			var tests = new StringViewModelTests ();
			var mproperty = tests.GetPropertyMock ("Property");

			var target = new object ();
			var resource = new Resource<string> (MockResourceProvider.SystemResourcesSource, "@android:string/foo_bar", "value");
			var resource2 = new Resource<string> (MockResourceProvider.ApplicationResourcesSource, "@android:string/foo_baz", "value");

			var mprovider = new Mock<IResourceProvider> ();
			mprovider.Setup (r => r.GetResourcesAsync (target, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource, resource2 });

			var vm = new ResourceSelectorViewModel (mprovider.Object, new[] { target }, mproperty.Object);
			Assume.That (vm.Resources, Contains.Item (resource));
			Assume.That (vm.Resources, Contains.Item (resource2));

			vm.ShowOnlyLocalResources = true;
			Assert.That (vm.Resources, Does.Not.Contain (resource));
			Assert.That (vm.Resources, Contains.Item (resource2));
		}

		[Test]
		public void OnlyShared ()
		{
			var tests = new StringViewModelTests ();
			var mproperty = tests.GetPropertyMock ("Property");

			var target = new object ();
			var resource = new Resource<string> (MockResourceProvider.SystemResourcesSource, "@android:string/foo_bar", "value");
			var resource2 = new Resource<string> (MockResourceProvider.ApplicationResourcesSource, "@android:string/foo_baz", "value");

			var mprovider = new Mock<IResourceProvider> ();
			mprovider.Setup (r => r.GetResourcesAsync (target, mproperty.Object, CancellationToken.None)).ReturnsAsync (new[] { resource, resource2 });

			var vm = new ResourceSelectorViewModel (mprovider.Object, new[] { target }, mproperty.Object);
			Assume.That (vm.Resources, Contains.Item (resource));
			Assume.That (vm.Resources, Contains.Item (resource2));

			vm.ShowOnlySystemResources = true;
			Assert.That (vm.Resources, Does.Not.Contain (resource2));
			Assert.That (vm.Resources, Contains.Item (resource));
		}
	}
}