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
|
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Xamarin.PropertyEditing.Drawing;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Tests
{
internal abstract class BrushPropertyViewModelTests : PropertyViewModelTests<CommonBrush, PropertyViewModel<CommonBrush>>
{
protected override PropertyViewModel<CommonBrush> GetViewModel (TargetPlatform platform, IPropertyInfo property, IEnumerable<IObjectEditor> editors)
{
return new BrushPropertyViewModel (platform, property, editors);
}
[Test]
public void SettingValueTriggersOpacityChange()
{
var mockProperty = new Mock<IPropertyInfo> ();
mockProperty.SetupGet (pi => pi.Type).Returns (typeof (CommonBrush));
var mockEditor = new MockObjectEditor (mockProperty.Object);
var vm = new BrushPropertyViewModel (MockEditorProvider.MockPlatform, mockProperty.Object, new[] { mockEditor });
var changed = false;
vm.PropertyChanged += (s, e) => {
if (e.PropertyName == nameof(BrushPropertyViewModel.Opacity)) {
changed = true;
}
};
vm.Value = GetRandomTestValue();
Assert.IsTrue (changed);
}
[Test]
public void ChangingEditorsUpdatesResources ()
{
var mockProperty = new Mock<IPropertyInfo> ();
mockProperty.SetupGet (pi => pi.Type).Returns (typeof (CommonBrush));
var mockEditor = new MockObjectEditor (mockProperty.Object);
var vm = new BrushPropertyViewModel (new TargetPlatform (new MockEditorProvider(), new MockResourceProvider()), mockProperty.Object, new [] { mockEditor });
var changed = false;
vm.PropertyChanged += (s, e) => {
if (e.PropertyName == nameof (BrushPropertyViewModel.ResourceSelector)) {
changed = true;
}
};
var rs1 = vm.ResourceSelector;
vm.Editors.Add (new MockObjectEditor ());
var rs2 = vm.ResourceSelector;
Assert.IsTrue (changed);
Assert.AreNotEqual (rs1, rs2);
}
[Test]
public void ChangingResourceProviderUpdatesResources ()
{
var mockProperty = new Mock<IPropertyInfo> ();
mockProperty.SetupGet (pi => pi.Type).Returns (typeof (CommonBrush));
var mockEditor = new MockObjectEditor (mockProperty.Object);
var vm = new BrushPropertyViewModel (new TargetPlatform (new MockEditorProvider (), new MockResourceProvider()), mockProperty.Object, new [] { mockEditor });
var changed = false;
vm.PropertyChanged += (s, e) => {
if (e.PropertyName == nameof (BrushPropertyViewModel.ResourceSelector)) {
changed = true;
}
};
var rs1 = vm.ResourceSelector;
var rs2 = vm.ResourceSelector;
Assert.IsTrue (changed);
Assert.IsNull (rs1);
Assert.AreNotEqual (rs1, rs2);
}
}
}
|