public void ConvertFrom_Uses_Selector_TargetType()
        {
            var target = new PerspexPropertyTypeConverter();
            var style = new Style(x => x.OfType<Class1>());
            var context = CreateContext(style);
            var result = target.ConvertFrom(context, null, "Foo");

            Assert.Equal(Class1.FooProperty, result);
        }
 private IValueContext CreateContext(Style style = null)
 {
     var context = new Mock<IValueContext>();
     var topDownValueContext = new Mock<ITopDownValueContext>();
     var typeRepository = new Mock<ITypeRepository>();
     var featureProvider = new Mock<ITypeFeatureProvider>();
     var class1XamlType = new XamlType(typeof(Class1), typeRepository.Object, null, featureProvider.Object);
     var attachedOwnerXamlType = new XamlType(typeof(AttachedOwner), typeRepository.Object, null, featureProvider.Object);
     context.Setup(x => x.TopDownValueContext).Returns(topDownValueContext.Object);
     context.Setup(x => x.TypeRepository).Returns(typeRepository.Object);
     topDownValueContext.Setup(x => x.GetLastInstance(It.IsAny<XamlType>())).Returns(style);
     typeRepository.Setup(x => x.GetByQualifiedName("Class1")).Returns(class1XamlType);
     typeRepository.Setup(x => x.GetByQualifiedName("AttachedOwner")).Returns(attachedOwnerXamlType);
     return context.Object;
 }
Exemple #3
0
        public void LocalValue_Should_Override_Style()
        {
            Style style = new Style(x => x.OfType<Class1>())
            {
                Setters = new[]
                {
                    new Setter(Class1.FooProperty, "Foo"),
                },
            };

            var target = new Class1
            {
                Foo = "Original",
            };

            style.Attach(target);
            Assert.Equal("Original", target.Foo);
        }
Exemple #4
0
        public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
        {
            Style style = new Style(x => x.OfType<Class1>().Class("foo"))
            {
                Setters = new[]
                {
                    new Setter(Class1.FooProperty, "Foo"),
                },
            };

            var target = new Class1();

            style.Attach(target);
            Assert.Equal("foodefault", target.Foo);
            target.Classes.Add("foo");
            Assert.Equal("Foo", target.Foo);
            target.Classes.Remove("foo");
            Assert.Equal("foodefault", target.Foo);
        }
Exemple #5
0
        public void Style_With_Only_Type_Selector_Should_Update_Value()
        {
            Style style = new Style(x => x.OfType<Class1>())
            {
                Setters = new[]
                {
                    new Setter(Class1.FooProperty, "Foo"),
                },
            };

            var target = new Class1();

            style.Attach(target);

            Assert.Equal("Foo", target.Foo);
        }
Exemple #6
0
        public void Style_With_Value_And_Source_Should_Throw_Exception()
        {
            var source = new BehaviorSubject<string>("Foo");

            Style style = new Style(x => x.OfType<Class1>())
            {
                Setters = new[]
                {
                    new Setter
                    {
                        Property = Class1.FooProperty,
                        Source = source,
                        Value = "Foo",
                    },
                },
            };

            var target = new Class1();

            Assert.Throws<InvalidOperationException>(() => style.Attach(target));
        }
Exemple #7
0
        public void Style_With_Source_Should_Update_Value()
        {
            var source = new BehaviorSubject<string>("Foo");

            Style style = new Style(x => x.OfType<Class1>())
            {
                Setters = new[]
                {
                    new Setter(Class1.FooProperty, source),
                },
            };

            var target = new Class1();

            style.Attach(target);

            Assert.Equal("Foo", target.Foo);
            source.OnNext("Bar");
            Assert.Equal("Bar", target.Foo);
        }