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-02-09 01:05:24 +0300
committerEric Maupin <ermaup@microsoft.com>2019-02-11 19:39:45 +0300
commitd3e884a275ad6aaaccaf42d8a75efd071472375c (patch)
tree2037855e60f39bac63e70bad9eea5af2d948488f /Xamarin.PropertyEditing.Tests
parente35b493b34e6f1a21eb0e1c1866eee7eb57823ed (diff)
[Core] Fix grouped type properties not swapping properly
Fixes #525 When we moved to the new panel group system, the grouped editors weren't accounted for and so when we try to remove their child property from the container group it's not found since they're inside the group editor VM. This also meant that even if removal had worked, we wouldn't properly add new shared view model types to the group.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs202
1 files changed, 201 insertions, 1 deletions
diff --git a/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
index 0626626..32197d6 100644
--- a/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
@@ -414,6 +414,206 @@ namespace Xamarin.PropertyEditing.Tests
Assert.That (vm.GetIsExpanded (normalProp.Object.Category), Is.True);
}
+ [Test]
+ public void GroupedTypesDoNotLeavePhantomCategory ()
+ {
+ var target = new object ();
+
+ var property = new Mock<IPropertyInfo> ();
+ property.SetupGet (p => p.Type).Returns (typeof (string));
+ property.SetupGet (p => p.Category).Returns ((string)null);
+ property.SetupGet (p => p.Name).Returns ("name");
+
+ var provider = new Mock<IEditorProvider> ();
+ provider.Setup (ep => ep.GetObjectEditorAsync (target))
+ .ReturnsAsync (new MockObjectEditor (property.Object) { Target = target });
+
+ var platform = new TargetPlatform (provider.Object) {
+ GroupedTypes = new Dictionary<Type, string> {
+ { typeof(string), "strings" }
+ }
+ };
+
+ var vm = CreateVm (platform);
+ vm.ArrangeMode = PropertyArrangeMode.Category;
+ vm.AutoExpand = true;
+ vm.SelectedObjects.Add (target);
+
+ Assert.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
+ }
+
+ [Test]
+ [Description ("https://github.com/xamarin/Xamarin.PropertyEditing/issues/525")]
+ public void SwitchingFromObjectWithGroupedType ()
+ {
+ var targetWithProperties = new object ();
+ var targetWithoutProperties = new object ();
+
+ var property = new Mock<IPropertyInfo> ();
+ property.SetupGet (p => p.Type).Returns (typeof (string));
+ property.SetupGet (p => p.Category).Returns ((string)null);
+ property.SetupGet (p => p.Name).Returns ("name");
+
+ var property2 = new Mock<IPropertyInfo> ();
+ property2.SetupGet (p => p.Type).Returns (typeof (string));
+ property2.SetupGet (p => p.Category).Returns ((string)null);
+ property2.SetupGet (p => p.Name).Returns ("name2");
+
+ var provider = new Mock<IEditorProvider> ();
+ provider.Setup (ep => ep.GetObjectEditorAsync (targetWithProperties))
+ .ReturnsAsync (new MockObjectEditor (property.Object, property2.Object) { Target = targetWithProperties });
+ provider.Setup (ep => ep.GetObjectEditorAsync (targetWithoutProperties))
+ .ReturnsAsync (new MockObjectEditor (new IPropertyInfo[0]) { Target = targetWithoutProperties });
+
+ var platform = new TargetPlatform (provider.Object) {
+ GroupedTypes = new Dictionary<Type, string> {
+ { typeof(string), "strings" }
+ }
+ };
+
+ var vm = CreateVm (platform);
+ vm.ArrangeMode = PropertyArrangeMode.Category;
+ vm.AutoExpand = true;
+ vm.SelectedObjects.Add (targetWithProperties);
+
+ Assume.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
+
+ Assert.That (() => vm.SelectedObjects.ReplaceOrAdd (targetWithProperties, targetWithoutProperties),
+ Throws.Nothing);
+ Assert.That (vm.ArrangedEditors.Count, Is.EqualTo (0));
+ }
+
+ [Test]
+ public void SwitchingToObjectWithGroupedType ()
+ {
+ var targetWithProperties = new object ();
+ var targetWithoutProperties = new object ();
+
+ var property = new Mock<IPropertyInfo> ();
+ property.SetupGet (p => p.Type).Returns (typeof (string));
+ property.SetupGet (p => p.Category).Returns ((string)null);
+ property.SetupGet (p => p.Name).Returns ("name");
+
+ var property2 = new Mock<IPropertyInfo> ();
+ property2.SetupGet (p => p.Type).Returns (typeof (string));
+ property2.SetupGet (p => p.Category).Returns ((string)null);
+ property2.SetupGet (p => p.Name).Returns ("name2");
+
+ var provider = new Mock<IEditorProvider> ();
+ provider.Setup (ep => ep.GetObjectEditorAsync (targetWithProperties))
+ .ReturnsAsync (new MockObjectEditor (property.Object, property2.Object) { Target = targetWithProperties });
+ provider.Setup (ep => ep.GetObjectEditorAsync (targetWithoutProperties))
+ .ReturnsAsync (new MockObjectEditor (new IPropertyInfo[0]) { Target = targetWithoutProperties });
+
+ var platform = new TargetPlatform (provider.Object) {
+ GroupedTypes = new Dictionary<Type, string> {
+ { typeof(string), "strings" }
+ }
+ };
+
+ var vm = CreateVm (platform);
+ vm.ArrangeMode = PropertyArrangeMode.Category;
+ vm.AutoExpand = true;
+ vm.SelectedObjects.Add (targetWithoutProperties);
+
+ Assume.That (vm.ArrangedEditors.Count, Is.EqualTo (0));
+
+ Assert.That (() => vm.SelectedObjects.ReplaceOrAdd (targetWithoutProperties, targetWithProperties),
+ Throws.Nothing);
+ Assert.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
+
+ var group = vm.ArrangedEditors[0].Editors[0] as PropertyGroupViewModel;
+ Assert.That (group, Is.Not.Null);
+ Assert.That (group.Properties.Count, Is.EqualTo (2));
+ }
+
+ [Test]
+ public void GroupedTypeMultiselect ()
+ {
+ var outer = new object ();
+ var inner = new object ();
+
+ var property = new Mock<IPropertyInfo> ();
+ property.SetupGet (p => p.Type).Returns (typeof (string));
+ property.SetupGet (p => p.Category).Returns ((string)null);
+ property.SetupGet (p => p.Name).Returns ("name");
+
+ var property2 = new Mock<IPropertyInfo> ();
+ property2.SetupGet (p => p.Type).Returns (typeof (string));
+ property2.SetupGet (p => p.Category).Returns ((string)null);
+ property2.SetupGet (p => p.Name).Returns ("name2");
+
+ var provider = new Mock<IEditorProvider> ();
+ provider.Setup (ep => ep.GetObjectEditorAsync (outer))
+ .ReturnsAsync (new MockObjectEditor (property.Object, property2.Object) { Target = outer });
+ provider.Setup (ep => ep.GetObjectEditorAsync (inner))
+ .ReturnsAsync (new MockObjectEditor (property.Object) { Target = inner });
+
+ var platform = new TargetPlatform (provider.Object) {
+ GroupedTypes = new Dictionary<Type, string> {
+ { typeof(string), "strings" }
+ }
+ };
+
+ var vm = CreateVm (platform);
+ vm.ArrangeMode = PropertyArrangeMode.Category;
+ vm.AutoExpand = true;
+ vm.SelectedObjects.Add (outer);
+
+ Assume.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
+
+ var group = vm.ArrangedEditors[0].Editors[0] as PropertyGroupViewModel;
+ Assume.That (group, Is.Not.Null);
+ Assume.That (group.Properties.Count, Is.EqualTo (2));
+
+ bool shouldChange = false, changed = false;
+ if (group.Properties is INotifyCollectionChanged incc) {
+ shouldChange = true;
+ incc.CollectionChanged += (o, e) => changed = true;
+ }
+
+ vm.SelectedObjects.Add (inner);
+ Assert.That (vm.ArrangedEditors[0].Editors[0] as PropertyGroupViewModel, Is.SameAs (group));
+ Assert.That (group.Properties.Count, Is.EqualTo (1), "Number of remaining properties isn't correct");
+ Assert.That (group.Properties[0].Property, Is.EqualTo (property.Object), "Wrong property found in the group");
+ Assert.That (changed, Is.EqualTo (shouldChange), "Changed status didn't match expected");
+
+ vm.SelectedObjects.Remove (inner);
+ group = vm.ArrangedEditors[0].Editors[0] as PropertyGroupViewModel;
+ Assert.That (group, Is.Not.Null);
+ Assert.That (group.Properties.Count, Is.EqualTo (2), "Outer properties didn't restore");
+ }
+
+ [Test]
+ public void GroupedTypeWhileNamed ()
+ {
+ var outer = new object ();
+
+ var property = new Mock<IPropertyInfo> ();
+ property.SetupGet (p => p.Type).Returns (typeof (string));
+ property.SetupGet (p => p.Category).Returns ((string)null);
+ property.SetupGet (p => p.Name).Returns ("name");
+
+ var provider = new Mock<IEditorProvider> ();
+ provider.Setup (ep => ep.GetObjectEditorAsync (outer))
+ .ReturnsAsync (new MockObjectEditor (property.Object) { Target = outer });
+
+ var platform = new TargetPlatform (provider.Object) {
+ GroupedTypes = new Dictionary<Type, string> {
+ { typeof(string), "strings" }
+ }
+ };
+
+ var vm = CreateVm (platform);
+ vm.ArrangeMode = PropertyArrangeMode.Name;
+ vm.SelectedObjects.Add (outer);
+
+ Assume.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
+
+ var group = vm.ArrangedEditors[0].Editors[0] as StringPropertyViewModel;
+ Assert.That (group, Is.Not.Null);
+ }
+
internal override PanelViewModel CreateVm (TargetPlatform platform)
{
return new PanelViewModel (platform);
@@ -421,4 +621,4 @@ namespace Xamarin.PropertyEditing.Tests
private TestContext context;
}
-} \ No newline at end of file
+}