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

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2019-10-04 00:49:58 +0300
committerEric Maupin <ermaup@microsoft.com>2019-10-04 00:50:00 +0300
commiteb3faa176dc0e1c7705d4be69339dd39cecce0a5 (patch)
treefda9bb1d9144ed6b3cc41a5456d0f437789768c6 /Xamarin.PropertyEditing.Tests
parent67ca579ebc5481160100a620f2cc8dbd94b94946 (diff)
[Core] Support refreshing resourcesermau-refresh-resources
While most resource UIs have a popup or window that doesn't really require a live refresh, the brush resource tab does have a persistent list so it needs to be able to update. Since the view model is shared, we get the former for free anyway.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/BrushPropertyViewModelTests.cs27
-rw-r--r--Xamarin.PropertyEditing.Tests/MockControls/MockResourceProvider.cs2
2 files changed, 29 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/BrushPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/BrushPropertyViewModelTests.cs
index bf4ccb3..ba0786f 100644
--- a/Xamarin.PropertyEditing.Tests/BrushPropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/BrushPropertyViewModelTests.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Threading;
using Moq;
using NUnit.Framework;
using Xamarin.PropertyEditing.Drawing;
@@ -52,5 +53,31 @@ namespace Xamarin.PropertyEditing.Tests
Assert.IsTrue (changed);
Assert.AreNotEqual (rs1, rs2);
}
+
+ [Test]
+ public void ResourcesChangedUpdatesResources ()
+ {
+ var mockProperty = new Mock<IPropertyInfo> ();
+ mockProperty.SetupGet (pi => pi.Type).Returns (typeof (CommonBrush));
+ var mockEditor = new MockObjectEditor (mockProperty.Object);
+
+ var resource1 = new Resource ("first");
+ var resources = new List<Resource> { resource1 };
+
+ var provider = new Mock<IResourceProvider>();
+ provider.Setup (p => p.GetResourceSourcesAsync (It.IsAny<object> ())).ReturnsAsync (new[] { MockResourceProvider.SystemResourcesSource });
+ provider.Setup (p => p.GetResourcesAsync (It.IsAny<object> (), mockProperty.Object, CancellationToken.None)).ReturnsAsync (resources);
+
+ var vm = new BrushPropertyViewModel (new TargetPlatform (new MockEditorProvider(), provider.Object), mockProperty.Object, new [] { mockEditor });
+
+ Assume.That (vm.ResourceSelector.Resources, Contains.Item (resource1));
+
+ var resource2 = new Resource ("second");
+ resources.Add (resource2);
+
+ provider.Raise (rp => rp.ResourcesChanged += null, new ResourcesChangedEventArgs());
+ Assert.That (vm.ResourceSelector.Resources, Contains.Item (resource1));
+ Assert.That (vm.ResourceSelector.Resources, Contains.Item (resource2));
+ }
}
}
diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockResourceProvider.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockResourceProvider.cs
index 8d5e458..f502626 100644
--- a/Xamarin.PropertyEditing.Tests/MockControls/MockResourceProvider.cs
+++ b/Xamarin.PropertyEditing.Tests/MockControls/MockResourceProvider.cs
@@ -11,6 +11,8 @@ namespace Xamarin.PropertyEditing.Tests
public class MockResourceProvider
: IResourceProvider
{
+ public event EventHandler<ResourcesChangedEventArgs> ResourcesChanged;
+
public bool CanCreateResources => true;
public Task<ResourceCreateError> CheckNameErrorsAsync (object target, ResourceSource source, string name)