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-03-19 21:56:04 +0300
committerEric Maupin <ermaup@microsoft.com>2019-04-24 22:03:17 +0300
commitc6e3613c6ea5bc087e026d2b4ed1f0e7d3133049 (patch)
tree7e31ac421a70431fe4df0f3c267742bbdf5046af /Xamarin.PropertyEditing.Tests
parent72b0e3368581a5d0d081afcbe86ebd0a894b5d9f (diff)
[Core] Tighten variation naming
This tightens up the naming distinctions: - Variation - The set of VariationOptions defining when the Variant will be active. - Variant - The collective property, Variation and its value. It also asyncifies the request for Mac
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/CreateVariantViewModelTests.cs18
-rw-r--r--Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs68
2 files changed, 77 insertions, 9 deletions
diff --git a/Xamarin.PropertyEditing.Tests/CreateVariantViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CreateVariantViewModelTests.cs
index cd87071..2e33114 100644
--- a/Xamarin.PropertyEditing.Tests/CreateVariantViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/CreateVariantViewModelTests.cs
@@ -50,7 +50,7 @@ namespace Xamarin.PropertyEditing.Tests
{
var property = GetTestProperty (out PropertyVariationOption[] variations);
var categories = variations.Select (v => v.Category).Distinct ().ToArray();
- var vm = new CreateVariationViewModel (property.Object);
+ var vm = new CreateVariantViewModel (property.Object);
Assert.That (vm.VariationCategories.Count, Is.EqualTo (categories.Length));
CollectionAssert.AreEqual (vm.VariationCategories.Select (v => v.Name), categories);
}
@@ -59,7 +59,7 @@ namespace Xamarin.PropertyEditing.Tests
public void WhenAllAnyCommandDisabledEnabled ()
{
var property = GetTestProperty (out PropertyVariationOption[] variations);
- var vm = new CreateVariationViewModel (property.Object);
+ var vm = new CreateVariantViewModel (property.Object);
Assume.That (vm.VariationCategories.All (vvm => vvm.IsAnySelected), Is.True);
Assert.That (vm.CreateVariantCommand.CanExecute (null), Is.False);
@@ -75,12 +75,12 @@ namespace Xamarin.PropertyEditing.Tests
public void CreateVariant ()
{
var property = GetTestProperty (out PropertyVariationOption[] variations);
- var vm = new CreateVariationViewModel (property.Object);
- Assume.That (vm.Variant, Is.Null);
+ var vm = new CreateVariantViewModel (property.Object);
+ Assume.That (vm.Variation, Is.Null);
bool changed = false;
vm.PropertyChanged += (sender, args) => {
- if (args.PropertyName == nameof (CreateVariationViewModel.Variant))
+ if (args.PropertyName == nameof (CreateVariantViewModel.Variation))
changed = true;
};
@@ -89,10 +89,10 @@ namespace Xamarin.PropertyEditing.Tests
vm.CreateVariantCommand.Execute (null);
Assert.That (changed, Is.True, "Variation did not fire PropertyChanged");
- Assert.That (vm.Variant, Is.Not.Null);
- Assert.That (vm.Variant.Count, Is.EqualTo (2));
- Assert.That (vm.Variant, Contains.Item (vm.VariationCategories[0].Variations[1]));
- Assert.That (vm.Variant, Contains.Item (vm.VariationCategories[1].Variations[2]));
+ Assert.That (vm.Variation, Is.Not.Null);
+ Assert.That (vm.Variation.Count, Is.EqualTo (2));
+ Assert.That (vm.Variation, Contains.Item (vm.VariationCategories[0].Variations[1]));
+ Assert.That (vm.Variation, Contains.Item (vm.VariationCategories[1].Variations[2]));
}
private Mock<IPropertyInfo> GetTestProperty (out PropertyVariationOption[] options)
diff --git a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
index f1a0d51..84b5d84 100644
--- a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
@@ -1404,6 +1404,74 @@ namespace Xamarin.PropertyEditing.Tests
}
[Test]
+ public void RequestCreateVariant ()
+ {
+ var mockProperty = GetPropertyMock ();
+ mockProperty.SetupGet (v => v.Variations).Returns (new[] { new PropertyVariationOption ("Category", "Value") });
+
+ var target = new object ();
+ var editor = new Mock<IObjectEditor> ();
+ editor.SetTarget (target);
+ editor.Setup (oe => oe.Properties).Returns (new[] { mockProperty.Object });
+ SetupPropertyGet (editor, mockProperty.Object, default(TValue));
+
+ var vm = GetViewModel (mockProperty.Object, editor.Object);
+
+ var variation = new PropertyVariation (new[] { mockProperty.Object.Variations[0] });
+ bool requested = false;
+ vm.CreateVariantRequested += (sender, args) => {
+ requested = true;
+ args.Variation = Task.FromResult (variation);
+ };
+
+ vm.RequestCreateVariantCommand.Execute (null);
+
+ Assert.That (requested, Is.True, "CreateVariantRequested didn't fire");
+ editor.Verify (oe => oe.SetValueAsync (mockProperty.Object, It.IsAny<ValueInfo<TValue>> (), variation));
+ }
+
+ [Test]
+ public void RequestCreateVariantCancel ()
+ {
+ var mockProperty = GetPropertyMock ();
+ mockProperty.SetupGet (v => v.Variations).Returns (new[] { new PropertyVariationOption ("Category", "Value") });
+
+ var target = new object ();
+ var editor = new Mock<IObjectEditor> ();
+ editor.SetTarget (target);
+ editor.Setup (oe => oe.Properties).Returns (new[] { mockProperty.Object });
+ SetupPropertyGet (editor, mockProperty.Object, default (TValue));
+
+ var vm = GetViewModel (mockProperty.Object, editor.Object);
+
+ int t = 0;
+ bool requested = false;
+ vm.CreateVariantRequested += (sender, args) => {
+ requested = true;
+
+ switch (t) {
+ case 0:
+ args.Variation = null;
+ break;
+ case 1:
+ args.Variation = Task.FromCanceled<PropertyVariation> (new CancellationToken (true));
+ break;
+ case 2:
+ args.Variation = Task.FromResult<PropertyVariation> (null);
+ break;
+ }
+
+ t++;
+ };
+
+ for (int i = 0; i < 3; i++) {
+ Assert.That (() => vm.RequestCreateVariantCommand.Execute (null), Throws.Nothing);
+ Assert.That (requested, Is.True, "CreateVariantRequested didn't fire");
+ editor.Verify (oe => oe.SetValueAsync (mockProperty.Object, It.IsAny<ValueInfo<TValue>> (), It.IsAny<PropertyVariation> ()), Times.Never);
+ }
+ }
+
+ [Test]
public void CreateBinding ()
{
var mockProperty = GetPropertyMock ();