Exemple #1
0
        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));
        }
Exemple #2
0
        public async Task ResourceRoots()
        {
            object target    = new object();
            var    property  = GetBasicProperty();
            var    editor    = GetBasicEditor(target, property.Object);
            var    resources = new MockResourceProvider();
            var    bindings  = GetBasicBindingProvider(target, property.Object);
            var    source    = new BindingSource("Resources", BindingSourceType.Resource);

            bindings.Setup(bp => bp.GetBindingSourcesAsync(target, property.Object)).ReturnsAsync(new[] { source });
            bindings.Setup(bp => bp.GetResourcesAsync(source, target))
            .Returns <BindingSource, object> (async(bs, t) => {
                var rs = await resources.GetResourcesAsync(target, CancellationToken.None);
                return(rs.ToLookup(r => r.Source));
            });

            var vm = new CreateBindingViewModel(
                new TargetPlatform(new MockEditorProvider(editor.Object), resources, bindings.Object), editor.Object,
                property.Object);

            Assume.That(vm.SelectedBindingSource, Is.EqualTo(source));

            Assert.That(vm.SourceResources, Is.Not.Null);
            await vm.SourceResources.Task;

            Assert.That(vm.SourceResources.Value.First().Key, Is.EqualTo(DefaultResourceSources[0]));
        }
Exemple #3
0
        public Task <IReadOnlyList <object> > GetRootElementsAsync(BindingSource source, object target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (source.Type != BindingSourceType.Object && source.Type != BindingSourceType.SingleObject)
            {
                throw new ArgumentException("source.Type was not Object", nameof(source));
            }

            if (source is BindingSourceInstance instance)
            {
                source = instance.Original;
            }

            if (source == RelativeSelf)
            {
                return(Task.FromResult <IReadOnlyList <object> > (new [] { target }));
            }
            if (source == StaticResource)
            {
                return(MockResourceProvider.GetResourceSourcesAsync(target).ContinueWith(t => (IReadOnlyList <object>)t.Result));
            }

            throw new NotImplementedException();
        }
Exemple #4
0
        public async Task Types()
        {
            object target    = new object();
            var    property  = GetBasicProperty();
            var    editor    = GetBasicEditor(target, property.Object);
            var    resources = new MockResourceProvider();
            var    source    = new BindingSource("Resources", BindingSourceType.Type);

            var type     = typeof(MockSampleControl).ToTypeInfo();
            var bindings = GetBasicBindingProvider(target, property.Object, sources: new[] { source });

            bindings.Setup(bp => bp.GetSourceTypesAsync(source, target))
            .ReturnsAsync(new AssignableTypesResult(new[] { type }));

            var provider = new MockEditorProvider(editor.Object);
            var vm       = new CreateBindingViewModel(new TargetPlatform(provider, resources, bindings.Object), editor.Object, property.Object);

            Assume.That(vm.SelectedBindingSource, Is.EqualTo(source));
            Assume.That(vm.TypeSelector, Is.Not.Null);

            while (vm.SelectedObjects.Count == 0 && vm.TypeSelector.IsLoading)
            {
                await Task.Delay(1);
            }

            var binding = (MockBinding)vm.SelectedObjects.First();

            Assert.That(vm.TypeSelector.SelectedType, Is.Null);

            bool propertyChanged = false;

            vm.PropertyChanged += (o, e) => {
                if (e.PropertyName == nameof(CreateBindingViewModel.PropertyRoot))
                {
                    propertyChanged = true;
                }
            };

            vm.TypeSelector.SelectedType = type;
            Assert.That(propertyChanged, Is.True, "INPC didn't change for PropertyRoot on selected source param");
            Assert.That(vm.PropertyRoot, Is.Not.Null);
            Assert.That(binding.SourceParameter, Is.EqualTo(type));

            await vm.PropertyRoot.Task;

            CollectionAssert.AreEqual(provider.GetPropertiesForTypeAsync(type).Result,
                                      vm.PropertyRoot.Value.Children.Select(pe => pe.Property));
        }
Exemple #5
0
        public async Task ResourceProperties()
        {
            object target    = new object();
            var    property  = GetBasicProperty();
            var    editor    = GetBasicEditor(target, property.Object);
            var    resources = new MockResourceProvider();
            var    source    = new BindingSource("Resources", BindingSourceType.Resource);
            var    bindings  = GetBasicBindingProvider(target, property.Object, sources: new [] { source });

            bindings.Setup(bp => bp.GetResourcesAsync(source, target))
            .Returns <BindingSource, object> (async(bs, t) => {
                var rs = await resources.GetResourcesAsync(target, CancellationToken.None);
                return(rs.ToLookup(r => r.Source));
            });

            var vm = new CreateBindingViewModel(
                new TargetPlatform(new MockEditorProvider(editor.Object), resources, bindings.Object), editor.Object,
                property.Object);

            Assume.That(vm.SelectedBindingSource, Is.EqualTo(source));
            Assume.That(vm.SourceResources, Is.Not.Null);
            await vm.SourceResources.Task;

            while (vm.SelectedObjects.Count == 0)
            {
                await Task.Delay(1);
            }

            var binding = (MockBinding)vm.SelectedObjects.First();

            vm.SelectedResource = vm.SourceResources.Value.First().OfType <Resource <CommonSolidBrush> >().First();
            Assert.That(binding.SourceParameter, Is.EqualTo(vm.SelectedResource));
            Assume.That(vm.PropertyRoot, Is.Not.Null);
            await vm.PropertyRoot.Task;

            Assert.That(vm.PropertyRoot.Value.TargetType, Is.EqualTo(typeof(CommonSolidBrush).ToTypeInfo()));
            CollectionAssert.AreEqual(ReflectionEditorProvider.GetPropertiesForType(typeof(CommonSolidBrush)),
                                      vm.PropertyRoot.Value.Children.Select(pe => pe.Property));
        }
 Task <IReadOnlyList <ResourceSource> > IResourceProvider.GetResourceSourcesAsync(object target)
 {
     return(MockResourceProvider.GetResourceSourcesAsync(target));
 }