public void DisagreeingValues() { const string name = "name"; var info = new Mock <IEventInfo> (); info.SetupGet(i => i.Name).Returns(name); var editor = new MockObjectEditor { Events = new[] { info.Object } }; const string handler = "handler"; editor.AttachHandlerAsync(info.Object, handler); var editor2 = new MockObjectEditor { Events = new[] { info.Object } }; editor.AttachHandlerAsync(info.Object, "handler2"); var ev = new EventViewModel(MockEditorProvider.MockPlatform, info.Object, new[] { editor, editor2 }); Assert.That(ev.MethodName, Is.Null); Assert.That(ev.MultipleValues, Is.True); }
public void FilterGroupableWhenNotGrouped() { var stringProvider = new StringViewModelTests(); var stringProperty1 = stringProvider.GetPropertyMock("string1"); var stringProperty2 = stringProvider.GetPropertyMock("string2"); var editor = new MockObjectEditor(stringProperty1.Object, stringProperty2.Object); var provider = new Mock <IEditorProvider> (); provider.Setup(p => p.GetObjectEditorAsync(editor.Target)).ReturnsAsync(editor); var platform = new TargetPlatform(provider.Object) { GroupedTypes = new Dictionary <Type, string> { { typeof(string), "B" } } }; var vm = new PanelViewModel(platform); Assume.That(vm.ArrangeMode, Is.EqualTo(PropertyArrangeMode.Name)); vm.SelectedObjects.Add(editor.Target); Assume.That(vm.ArrangedEditors[0].Editors.Count, Is.EqualTo(2)); vm.FilterText = "A"; Assert.That(vm.ArrangedEditors.Count, Is.EqualTo(0)); }
public void HasChildElementsUpdates() { var property = new Mock <IPropertyInfo> (); property.Setup(p => p.Name).Returns("Name"); property.Setup(p => p.Category).Returns("Category"); property.Setup(p => p.Type).Returns(typeof(string)); property.Setup(p => p.IsUncommon).Returns(false); var editor = new MockObjectEditor(property.Object); var propertyVm = new StringPropertyViewModel(MockEditorProvider.MockPlatform, property.Object, new[] { editor }); var group = new PanelGroupViewModel(MockEditorProvider.MockPlatform, "Category", new[] { propertyVm }); Assert.That(group.HasChildElements, Is.True); bool changed = false; group.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(PanelGroupViewModel.HasChildElements)) { changed = true; } }; group.Remove(propertyVm); Assert.That(group.HasChildElements, Is.False); Assert.That(changed, Is.True, "INPC did not fire for HasChildElements during remove"); changed = false; group.Add(propertyVm); Assert.That(group.HasChildElements, Is.True); Assert.That(changed, Is.True, "INPC did not fire for HasChildElements during add"); }
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)); }
public void GroupedPropertiesArrange() { var intProvider = new IntegerPropertyViewModelTests(); var stringProvider = new StringViewModelTests(); var brushProvider = new SolidBrushPropertyViewModelTests(); var intProperty = intProvider.GetPropertyMock("int", "A"); var stringProperty1 = stringProvider.GetPropertyMock("string1"); var stringProperty2 = stringProvider.GetPropertyMock("string2"); var brushProperty = brushProvider.GetPropertyMock("brush", "C"); var editor = new MockObjectEditor(intProperty.Object, stringProperty1.Object, stringProperty2.Object, brushProperty.Object); var provider = new Mock <IEditorProvider> (); provider.Setup(p => p.GetObjectEditorAsync(editor.Target)).ReturnsAsync(editor); var platform = new TargetPlatform(provider.Object) { GroupedTypes = new Dictionary <Type, string> { { typeof(string), "B" } } }; var vm = new PanelViewModel(platform); Assume.That(vm.ArrangeMode, Is.EqualTo(PropertyArrangeMode.Name)); vm.ArrangeMode = PropertyArrangeMode.Category; vm.SelectedObjects.Add(editor.Target); Assert.That(vm.ArrangedEditors[0].Category, Is.EqualTo("A")); Assert.That(vm.ArrangedEditors[1].Category, Is.EqualTo("B")); Assert.That(vm.ArrangedEditors[2].Category, Is.EqualTo("C")); }
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); }
public void UnavailablePropertyNotInList() { IObjectEditor editor; var constraint = new Mock <IAvailabilityConstraint>(); var prop = new Mock <IPropertyInfo> (); prop.SetupGet(p => p.Type).Returns(typeof(int)); prop.SetupGet(p => p.AvailabilityConstraints).Returns(new[] { constraint.Object }); var constraint2 = new Mock <IAvailabilityConstraint> (); var prop2 = new Mock <IPropertyInfo> (); prop2.SetupGet(p => p.Type).Returns(typeof(int)); prop2.SetupGet(p => p.AvailabilityConstraints).Returns(new[] { constraint2.Object }); editor = new MockObjectEditor(prop.Object, prop2.Object); constraint.Setup(c => c.GetIsAvailableAsync(editor)).ReturnsAsync(true); constraint2.Setup(c => c.GetIsAvailableAsync(editor)).ReturnsAsync(false); var pvm = new PropertyViewModel <int> (TargetPlatform.Default, prop.Object, new[] { editor }); var pvm2 = new PropertyViewModel <int> (TargetPlatform.Default, prop2.Object, new[] { editor }); var vm = new PropertyGroupViewModel(TargetPlatform.Default, "category", new[] { pvm, pvm2 }, new [] { editor }); Assert.That(vm.Properties, Contains.Item(pvm)); Assert.That(vm.Properties, Does.Not.Contain(pvm2)); }
public async Task ResourceBrushMatchesMaterialStaysResource() { var platform = new TargetPlatform(new MockEditorProvider()) { SupportsMaterialDesign = true }; var mockProperty = new Mock <IPropertyInfo> (); mockProperty.SetupGet(pi => pi.Type).Returns(typeof(CommonSolidBrush)); var mockEditor = new MockObjectEditor(mockProperty.Object); var provider = new MockResourceProvider(); var resources = await provider.GetResourcesAsync(mockEditor.Target, mockProperty.Object, CancellationToken.None); var resource = resources.OfType <Resource <CommonSolidBrush> > ().First(r => r.Value == new CommonSolidBrush(0, 0, 0)); await mockEditor.SetValueAsync(mockProperty.Object, new ValueInfo <CommonSolidBrush> { Source = ValueSource.Resource, Value = resource.Value, SourceDescriptor = resource }); var vm = new BrushPropertyViewModel(platform, mockProperty.Object, new[] { mockEditor }); Assume.That(vm.ValueSource, Is.EqualTo(ValueSource.Resource)); Assert.That(vm.SelectedBrushType, Is.EqualTo(CommonBrushType.Resource)); }
public void TypeRequestedWhenMultipleAssignableTypes() { object value = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { GetTypeInfo(typeof(ChildClass)), childsubInfo } } }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); var vm = new ObjectPropertyViewModel(providerMock.Object, TargetPlatform.Default, p.Object, new[] { editor }); bool requested = false; vm.TypeRequested += (sender, args) => { requested = true; }; Assume.That(vm.CreateInstanceCommand.CanExecute(childsubInfo), Is.True); vm.CreateInstanceCommand.Execute(childsubInfo); Assert.That(requested, Is.True, "TypeRequested was not raised"); }
public async Task MultiValueSourcesUnknown() { object value = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childsubInfo } } }); await editor.SetValueAsync(p.Object, new ValueInfo <object> { Value = value, Source = ValueSource.Local, ValueDescriptor = childsubInfo }); var editor2 = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childsubInfo } } }); await editor2.SetValueAsync(p.Object, new ValueInfo <object> { Value = value, Source = ValueSource.Default, ValueDescriptor = childsubInfo }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); var vm = new ObjectPropertyViewModel(providerMock.Object, TargetPlatform.Default, p.Object, new[] { editor, editor2 }); Assert.That(vm.ValueSource, Is.EqualTo(ValueSource.Unknown)); }
private static BrushPropertyViewModel PrepareMockViewModel() { var mockProperty = new Mock <IPropertyInfo> (); mockProperty.SetupGet(pi => pi.Type).Returns(typeof(CommonSolidBrush)); mockProperty.As <IColorSpaced> ().SetupGet(pi => pi.ColorSpaces).Returns(SampleColorSpaces); var mockEditor = new MockObjectEditor(mockProperty.Object); return(new BrushPropertyViewModel(MockEditorProvider.MockPlatform, mockProperty.Object, new[] { mockEditor })); }
public void AvailabilityUpdates() { IObjectEditor editor = null; var constraint = new Mock <IAvailabilityConstraint>(); var prop = new Mock <IPropertyInfo> (); prop.SetupGet(p => p.Type).Returns(typeof(int)); prop.SetupGet(p => p.AvailabilityConstraints).Returns(new[] { constraint.Object }); bool isAvailable = false; var constraint2 = new Mock <IAvailabilityConstraint> (); constraint2.SetupGet(a => a.ConstrainingProperties).Returns(new[] { prop.Object }); var prop2 = new Mock <IPropertyInfo> (); prop2.SetupGet(p => p.Type).Returns(typeof(int)); prop2.SetupGet(p => p.AvailabilityConstraints).Returns(new[] { constraint2.Object }); editor = new MockObjectEditor(prop.Object, prop2.Object); constraint.Setup(c => c.GetIsAvailableAsync(editor)).ReturnsAsync(true); constraint2.Setup(c => c.GetIsAvailableAsync(editor)).ReturnsAsync(() => isAvailable); var pvm = new PropertyViewModel <int> (TargetPlatform.Default, prop.Object, new[] { editor }); var pvm2 = new PropertyViewModel <int> (TargetPlatform.Default, prop2.Object, new[] { editor }); var vm = new PropertyGroupViewModel(TargetPlatform.Default, "category", new[] { pvm, pvm2 }, new [] { editor }); Assume.That(vm.Properties, Contains.Item(pvm)); Assume.That(vm.Properties, Does.Not.Contain(pvm2)); INotifyCollectionChanged notify = vm.Properties as INotifyCollectionChanged; Assume.That(notify, Is.Not.Null); bool changed = false; notify.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Add && args.NewItems[0] == pvm2) { changed = true; } }; isAvailable = true; // Bit of integration here, constrainting property changes will trigger availability requery pvm.Value = 5; Assert.That(changed, Is.True); Assert.That(vm.Properties, Contains.Item(pvm)); Assert.That(vm.Properties, Contains.Item(pvm2)); }
private static BrushPropertyViewModel PrepareMockViewModel() { var platform = new TargetPlatform { SupportsMaterialDesign = true }; var mockProperty = new Mock <IPropertyInfo> (); mockProperty.SetupGet(pi => pi.Type).Returns(typeof(CommonSolidBrush)); var mockEditor = new MockObjectEditor(mockProperty.Object); return(new BrushPropertyViewModel(platform, mockProperty.Object, new[] { mockEditor })); }
public async Task ValidatorMultiSelect() { var p = GetPropertyMock(); var validator = p.As <IValidator <IReadOnlyList <int> > > (); validator.Setup(l => l.IsValid(It.IsAny <IReadOnlyList <int> > ())).Returns <IReadOnlyList <int> > (l => !(l == null || l.Count == 0)); var editor = new MockObjectEditor(p.Object); await editor.SetValueAsync(p.Object, new ValueInfo <int> { Value = (int)FlagsTestEnum.Flag1, Source = ValueSource.Local }); var editor2 = new MockObjectEditor(p.Object); await editor2.SetValueAsync(p.Object, new ValueInfo <int> { Value = (int)FlagsTestEnum.Flag2, Source = ValueSource.Local }); var vm = GetViewModel(p.Object, new [] { editor, editor2 }); Assume.That(vm.Choices.Count, Is.EqualTo(7)); var flag1choice = vm.Choices.Single(c => c.Value == (int)FlagsTestEnum.Flag1); Assume.That(flag1choice.IsFlagged, Is.Null); var flag2choice = vm.Choices.Single(c => c.Value == (int)FlagsTestEnum.Flag2); Assume.That(flag1choice.IsFlagged, Is.Null); var flag3choice = vm.Choices.Single(c => c.Value == (int)FlagsTestEnum.Flag3); Assume.That(flag3choice.IsFlagged, Is.False); // initial state has o1: flag1, o2: flag2. // unflagging flag1 results in invalid o1 property state // impl swaps flag1 back on, now o1 is flag1; o2 is flag1|flag2 flag1choice.IsFlagged = false; var setValue = await editor.GetValueAsync <IReadOnlyList <int> > (p.Object); var setValue2 = await editor2.GetValueAsync <IReadOnlyList <int> > (p.Object); CollectionAssert.AreEquivalent(new[] { (int)FlagsTestEnum.Flag1 }, setValue.Value); CollectionAssert.AreEquivalent(new[] { (int)FlagsTestEnum.Flag1, (int)FlagsTestEnum.Flag2 }, setValue2.Value); Assert.That(flag1choice.IsFlagged, Is.True); Assert.That(flag2choice.IsFlagged, Is.Null); }
public async Task CanDelve() { object value = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childsubInfo } } }); await editor.SetValueAsync(p.Object, new ValueInfo <object> { Value = value, Source = ValueSource.Local }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); var vm = new ObjectPropertyViewModel(new TargetPlatform(providerMock.Object), p.Object, new IObjectEditor[0]); Assert.That(vm.CanDelve, Is.False); bool changed = false; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(ObjectPropertyViewModel.CanDelve)) { changed = true; } }; vm.Editors.Add(editor); Assert.That(vm.CanDelve, Is.True); Assert.That(changed, Is.True, "PropertyChanged for CanDelve didn't fire adding"); changed = false; vm.Editors.Clear(); Assert.That(vm.CanDelve, Is.False); Assert.That(changed, Is.True, "PropertyChanged for CanDelve didn't fire clearing"); changed = false; vm.Editors.Add(null); Assert.That(vm.CanDelve, Is.False); Assert.That(changed, Is.False, "PropertyChanged for CanDelve when hasn't changed"); }
public void FilteredOutOfChildren() { IObjectEditor editor = null; var prop = new Mock <IPropertyInfo> (); prop.SetupGet(p => p.Type).Returns(typeof(int)); prop.SetupGet(p => p.Name).Returns("one"); var prop2 = new Mock <IPropertyInfo> (); prop2.SetupGet(p => p.Type).Returns(typeof(int)); prop2.SetupGet(p => p.Name).Returns("two"); editor = new MockObjectEditor(prop.Object, prop2.Object); var pvm = new PropertyViewModel <int> (TargetPlatform.Default, prop.Object, new[] { editor }); var pvm2 = new PropertyViewModel <int> (TargetPlatform.Default, prop2.Object, new[] { editor }); var vm = new PropertyGroupViewModel(TargetPlatform.Default, "category", new[] { pvm, pvm2 }, new [] { editor }); Assume.That(vm.Properties, Contains.Item(pvm)); Assume.That(vm.Properties, Contains.Item(pvm2)); bool changed = false; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(PropertyGroupViewModel.HasChildElements)) { changed = true; } }; vm.FilterText = "1"; Assert.That(changed, Is.True, "HasChildElements didn't change"); Assert.That(vm.HasChildElements, Is.False); Assert.That(vm.Properties, Does.Not.Contain(pvm2)); Assert.That(vm.Properties, Does.Not.Contain(pvm)); changed = false; vm.FilterText = null; Assert.That(changed, Is.True, "HasChildElements didn't change"); Assert.That(vm.HasChildElements, Is.True); Assert.That(vm.Properties, Contains.Item(pvm2)); Assert.That(vm.Properties, Contains.Item(pvm)); }
public void MethodName() { const string name = "name"; var info = new Mock <IEventInfo> (); info.SetupGet(i => i.Name).Returns(name); var editor = new MockObjectEditor { Events = new[] { info.Object } }; const string handler = "handler"; editor.AttachHandlerAsync(info.Object, handler); var ev = new EventViewModel(MockEditorProvider.MockPlatform, info.Object, new[] { editor }); Assert.That(ev.MethodName, Is.EqualTo(handler)); }
public void Filtered() { IObjectEditor editor = null; var prop = new Mock <IPropertyInfo> (); prop.SetupGet(p => p.Type).Returns(typeof(int)); prop.SetupGet(p => p.Name).Returns("one"); var prop2 = new Mock <IPropertyInfo> (); prop2.SetupGet(p => p.Type).Returns(typeof(int)); prop2.SetupGet(p => p.Name).Returns("two"); editor = new MockObjectEditor(prop.Object, prop2.Object); var pvm = new PropertyViewModel <int> (TargetPlatform.Default, prop.Object, new[] { editor }); var pvm2 = new PropertyViewModel <int> (TargetPlatform.Default, prop2.Object, new[] { editor }); var vm = new PropertyGroupViewModel(TargetPlatform.Default, "category", new[] { pvm, pvm2 }, new [] { editor }); Assume.That(vm.Properties, Contains.Item(pvm)); Assume.That(vm.Properties, Contains.Item(pvm2)); INotifyCollectionChanged notify = vm.Properties as INotifyCollectionChanged; Assume.That(notify, Is.Not.Null); bool changed = false; notify.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Remove && args.OldItems[0] == pvm) { changed = true; } }; vm.FilterText = "t"; Assert.That(changed, Is.True, "Collection changed event didn't trigger correctly"); Assert.That(vm.Properties, Contains.Item(pvm2)); Assert.That(vm.Properties, Does.Not.Contain(pvm)); Assert.That(vm.HasChildElements, Is.True); }
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); }
public void NoValueToMaterialSets() { var platform = new TargetPlatform(new MockEditorProvider()) { SupportsMaterialDesign = true }; var mockProperty = new Mock <IPropertyInfo> (); mockProperty.SetupGet(pi => pi.Type).Returns(typeof(CommonSolidBrush)); var mockEditor = new MockObjectEditor(mockProperty.Object); var vm = new BrushPropertyViewModel(platform, mockProperty.Object, new[] { mockEditor }); Assume.That(vm.MaterialDesign.Color, Is.EqualTo(new CommonColor(0, 0, 0))); Assume.That(vm.ValueSource, Is.EqualTo(ValueSource.Default).Or.EqualTo(ValueSource.Unset)); Assume.That(vm.SelectedBrushType, Is.EqualTo(CommonBrushType.NoBrush)); vm.SelectedBrushType = CommonBrushType.MaterialDesign; Assert.That(vm.ValueSource, Is.EqualTo(ValueSource.Local)); }
public async Task PropertyRootChildren() { var target = new object(); var property = new Mock <IPropertyInfo> (); property.SetupGet(p => p.ValueSources).Returns(ValueSources.Local | ValueSources.Binding); property.SetupGet(p => p.Type).Returns(typeof(object)); property.SetupGet(p => p.Name).Returns("name"); property.SetupGet(p => p.RealType).Returns(typeof(object).ToTypeInfo()); property.SetupGet(p => p.CanWrite).Returns(true); var editor = GetBasicEditor(target, property.Object); var controlTarget = new MockWpfControl(); var controlEditor = new MockObjectEditor(controlTarget); var provider = new MockEditorProvider(controlEditor); var source = new BindingSource("Control", BindingSourceType.Object); var bpmock = new Mock <IBindingProvider> (); bpmock.Setup(bp => bp.GetBindingSourcesAsync(target, property.Object)).ReturnsAsync(new[] { source }); bpmock.Setup(bp => bp.GetRootElementsAsync(source, target)).ReturnsAsync(new[] { controlTarget }); bpmock.Setup(bp => bp.GetValueConverterResourcesAsync(It.IsAny <object> ())).ReturnsAsync(new Resource[0]); var vm = new CreateBindingViewModel(new TargetPlatform(provider, bpmock.Object), editor.Object, property.Object); Assume.That(vm.SelectedBindingSource, Is.EqualTo(source)); Assume.That(vm.PropertyRoot, Is.Not.Null); await vm.PropertyRoot.Task; var childrenProperty = controlEditor.Properties.First(p => p.Type == typeof(CommonThickness)); var element = vm.PropertyRoot.Value.Children.First(p => Equals(p.Property, childrenProperty)); Assert.That(element.Children, Is.Not.Null); await element.Children.Task; var expected = await provider.GetPropertiesForTypeAsync(typeof(CommonThickness).ToTypeInfo()); CollectionAssert.AreEqual(expected, element.Children.Value.Select(te => te.Property)); }
public void PropertyGroup() { IObjectEditor editor = null; var prop = new Mock <IPropertyInfo> (); prop.SetupGet(p => p.Type).Returns(typeof(int)); var prop2 = new Mock <IPropertyInfo> (); prop2.SetupGet(p => p.Type).Returns(typeof(int)); editor = new MockObjectEditor(prop.Object, prop2.Object); var pvm = new PropertyViewModel <int> (TargetPlatform.Default, prop.Object, new[] { editor }); var pvm2 = new PropertyViewModel <int> (TargetPlatform.Default, prop2.Object, new[] { editor }); var vm = new PropertyGroupViewModel(TargetPlatform.Default, "category", new[] { pvm, pvm2 }, new [] { editor }); Assert.That(vm.Properties, Contains.Item(pvm)); Assert.That(vm.Properties, Contains.Item(pvm2)); }
public async Task MultiValueTypesNull() { object value = new object(), value2 = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var childInfo = GetTypeInfo(typeof(ChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childInfo, childsubInfo } } }); await editor.SetValueAsync(p.Object, new ValueInfo <object> { Value = value, Source = ValueSource.Local, ValueDescriptor = childInfo }); var editor2 = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childInfo, childsubInfo } } }); await editor2.SetValueAsync(p.Object, new ValueInfo <object> { Value = value2, Source = ValueSource.Local, ValueDescriptor = childsubInfo }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); providerMock.Setup(a => a.GetObjectEditorAsync(value2)).ReturnsAsync(new MockObjectEditor { Target = value2 }); var vm = new ObjectPropertyViewModel(new TargetPlatform(providerMock.Object), p.Object, new[] { editor, editor2 }); Assume.That(vm.ValueSource, Is.EqualTo(ValueSource.Local)); Assert.That(vm.ValueType, Is.Null); }
public async Task ClearedValueSourcesDefault() { object value = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { childsubInfo } } }); await editor.SetValueAsync(p.Object, new ValueInfo <object> { Value = value, Source = ValueSource.Local, ValueDescriptor = childsubInfo }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); var vm = new ObjectPropertyViewModel(providerMock.Object, TargetPlatform.Default, p.Object, new[] { editor }); Assume.That(vm.ValueSource, Is.EqualTo(ValueSource.Local)); bool changed = false; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(ObjectPropertyViewModel.ValueSource)) { changed = true; } }; vm.Editors.Clear(); Assert.That(vm.ValueSource, Is.EqualTo(ValueSource.Default)); Assert.That(changed, Is.True, "PropertyChanged did not fire for ValueSource"); }
public void ReturnedNullTypeCancels() { object value = new object(); var p = CreatePropertyMock("prop"); var childsubInfo = GetTypeInfo(typeof(SubChildClass)); var editor = new MockObjectEditor(new[] { p.Object }, new Dictionary <IPropertyInfo, IReadOnlyList <ITypeInfo> > { { p.Object, new[] { GetTypeInfo(typeof(ChildClass)), childsubInfo } } }); var providerMock = CreateProviderMock(value, new MockObjectEditor { Target = value }); var vm = new ObjectPropertyViewModel(new TargetPlatform(providerMock.Object), p.Object, new[] { editor }); var tcs = new TaskCompletionSource <ITypeInfo> (); bool requested = false; vm.TypeRequested += (sender, args) => { requested = true; args.SelectedType = tcs.Task; }; Assume.That(vm.CreateInstanceCommand.CanExecute(childsubInfo), Is.True); vm.CreateInstanceCommand.Execute(null); Assume.That(requested, Is.True); tcs.SetResult(null); providerMock.Verify(ep => ep.CreateObjectAsync(null), Times.Never); }
public async Task SetFlagsMultipleValues() { FlagsTestEnum value = FlagsTestEnum.Flag2 | FlagsTestEnum.Flag3; FlagsTestEnum value2 = FlagsTestEnum.Flag2 | FlagsTestEnum.Flag4; var p = GetPropertyMock(); var editor = new MockObjectEditor(p.Object); await editor.SetValueAsync(p.Object, new ValueInfo <int> { Value = (int)value, Source = ValueSource.Local }); var editor2 = new MockObjectEditor(p.Object); await editor2.SetValueAsync(p.Object, new ValueInfo <int> { Value = (int)value2, Source = ValueSource.Local }); var vm = GetViewModel(p.Object, new [] { editor, editor2 }); Assume.That(vm.Choices.Count, Is.EqualTo(7)); Assume.That(vm.Value, Is.EqualTo(default(int))); var flag1Choice = vm.Choices.Single(v => v.Name == nameof(FlagsTestEnum.Flag1)); Assume.That(flag1Choice.Value, Is.EqualTo((int)FlagsTestEnum.Flag1)); Assume.That(flag1Choice.IsFlagged.HasValue && !flag1Choice.IsFlagged.Value); var flag2Choice = vm.Choices.Single(v => v.Name == nameof(FlagsTestEnum.Flag2)); Assume.That(flag2Choice.Value, Is.EqualTo((int)FlagsTestEnum.Flag2)); Assume.That(flag2Choice.IsFlagged.HasValue && flag2Choice.IsFlagged.Value, Is.True); var flag3Choice = vm.Choices.Single(v => v.Name == nameof(FlagsTestEnum.Flag3)); Assume.That(flag3Choice.Value, Is.EqualTo((int)FlagsTestEnum.Flag3)); Assume.That(flag3Choice.IsFlagged.HasValue, Is.False); var flag4Choice = vm.Choices.Single(v => v.Name == nameof(FlagsTestEnum.Flag4)); Assume.That(flag4Choice.Value, Is.EqualTo((int)FlagsTestEnum.Flag4)); Assume.That(flag4Choice.IsFlagged.HasValue, Is.False); var flag5Choice = vm.Choices.Single(v => v.Name == nameof(FlagsTestEnum.Flag5)); Assume.That(flag5Choice.Value, Is.EqualTo((int)FlagsTestEnum.Flag5)); Assume.That(flag5Choice.IsFlagged.HasValue, Is.False); flag1Choice.IsFlagged = true; Assert.That(flag1Choice.IsFlagged, Is.True); Assert.That(flag2Choice.IsFlagged, Is.True); Assert.That(flag3Choice.IsFlagged, Is.Null); Assert.That(flag4Choice.IsFlagged, Is.Null); Assert.That(flag5Choice.IsFlagged, Is.Null); Assert.That(vm.Value, Is.EqualTo(default(int))); var setValue = await editor.GetValueAsync <IReadOnlyList <int> > (p.Object); var setValue2 = await editor2.GetValueAsync <IReadOnlyList <int> > (p.Object); CollectionAssert.AreEquivalent(new[] { (int)FlagsTestEnum.Flag1, (int)FlagsTestEnum.Flag2, (int)FlagsTestEnum.Flag3 }, setValue.Value); CollectionAssert.AreEquivalent(new[] { (int)FlagsTestEnum.Flag1, (int)FlagsTestEnum.Flag2, (int)FlagsTestEnum.Flag4, (int)FlagsTestEnum.Flag5 }, setValue2.Value); }