Ejemplo n.º 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));
        }
Ejemplo n.º 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]));
        }
Ejemplo n.º 3
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));
        }