Ejemplo n.º 1
0
        public void ValueProviderSetValue()
        {
            TextBox        textbox = CreateConcreteFrameworkElement() as TextBox;
            AutomationPeer feap
                = CreateConcreteFrameworkElementAutomationPeer(textbox) as AutomationPeer;
            IValueProvider valueProvider = feap.GetPattern(PatternInterface.Value) as IValueProvider;

            Assert.IsNotNull(valueProvider, "#0");
            Assert.IsNotNull(valueProvider.Value, "#1");

            valueProvider.SetValue("Hello world");
            Assert.AreEqual("Hello world", textbox.Text, "#2");

            valueProvider.SetValue("new text");
            Assert.AreEqual("new text", textbox.Text, "#3");

            textbox.IsReadOnly = true;
            Assert.Throws <InvalidOperationException>(delegate {
                valueProvider.SetValue("is readonly");
            }, "#4");
            Assert.AreEqual("new text", textbox.Text, "#5");

            textbox.IsReadOnly = false;
            textbox.IsEnabled  = false;
            Assert.Throws <ElementNotEnabledException>(delegate {
                valueProvider.SetValue("is not enabled");
            }, "#6");
            Assert.AreEqual("new text", textbox.Text, "#7");
        }
Ejemplo n.º 2
0
        public void ValueProvider_SetValue()
        {
            PasswordBox    passwordbox = CreateConcreteFrameworkElement() as PasswordBox;
            AutomationPeer feap
                = CreateConcreteFrameworkElementAutomationPeer(passwordbox) as AutomationPeer;
            IValueProvider valueProvider = feap.GetPattern(PatternInterface.Value) as IValueProvider;

            Assert.IsNotNull(valueProvider, "#0");
            Assert.Throws <InvalidOperationException> (delegate {
                string value = valueProvider.Value;
                GC.KeepAlive(value);
            }, "#1");

            valueProvider.SetValue("new text");
            Assert.Throws <InvalidOperationException> (delegate {
                string value = valueProvider.Value;
                GC.KeepAlive(value);
            }, "#2");

            passwordbox.IsEnabled = false;
            Assert.Throws <ElementNotEnabledException> (delegate {
                valueProvider.SetValue("is not enabled");
            }, "#3");
            Assert.AreEqual("new text", passwordbox.Password, "#4");
        }
Ejemplo n.º 3
0
        public void IValueProviderSetValueTest()
        {
            T textBoxBase;
            IRawElementProviderSimple provider;

            GetProviderAndControl(out provider, out textBoxBase);

            textBoxBase.Multiline = false;

            IValueProvider valueProvider = (IValueProvider)
                                           provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(valueProvider, "Not returning ValuePatternIdentifiers.");

            string value = "Hello world";

            valueProvider.SetValue(value);
            Assert.AreEqual(valueProvider.Value, value, "Different value");

            try {
                textBoxBase.ReadOnly = true;
                valueProvider.SetValue(value);
                Assert.Fail("ElementNotEnabledException not thrown.");
            } catch (ElementNotEnabledException) { }
        }
Ejemplo n.º 4
0
        public void IValueProviderSetValueTest()
        {
            DomainUpDown domainUpDown          = new DomainUpDown();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(domainUpDown);

            IValueProvider valueProvider = (IValueProvider)
                                           provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(valueProvider,
                             "Not returning ValuePatternIdentifiers.");

            try {
                domainUpDown.Enabled = false;
                valueProvider.SetValue("NEW Item");
                Assert.Fail("ElementNotEnabledException not thrown.");
            } catch (ElementNotEnabledException) { }

            domainUpDown.Enabled = true;
            try {
                domainUpDown.ReadOnly = true;
                valueProvider.SetValue("NEW Item");
                Assert.Fail("ElementNotEnabledException not thrown.");
            } catch (ElementNotEnabledException) { }
            domainUpDown.ReadOnly = false;

            string value = "NEW Item";

            valueProvider.SetValue(value);
            domainUpDown.DownButton();
            Assert.AreEqual(value, valueProvider.Value, "SetValue value");
        }
Ejemplo n.º 5
0
        public void SetValue(object target, object value)
        {
            if (_inner != null)
            {
                _inner.SetValue(target, value);
            }

            if (_setter == null)
            {
                try
                {
                    var fastProp = FastProperty.GetProperty(_pi, PropertyCachingStrategy.EagerCached);
                    if (fastProp.IsPublicSettable)
                    {
                        _setter = fastProp.ValueSetter;
                    }
                    if (_setter == null)
                    {
                        throw new Exception();
                    }
                }
                catch
                {
                    CreateInnerProvider();
                    _inner.SetValue(target, value);
                    return;
                }
            }

            _setter(target, value);
        }
Ejemplo n.º 6
0
 public void SetValue(object target, object value)
 {
     if (value == null)
     {
         Provider.SetValue(target, null);
     }
     Provider.SetValue(target, value);
 }
Ejemplo n.º 7
0
            private void SetValue(TextBox textbox, string value)
            {
                TextBoxAutomationPeer peer     = new TextBoxAutomationPeer(textbox);
                IValueProvider        provider = peer.GetPattern(PatternInterface.Value) as IValueProvider;

                provider.SetValue(value);
            }
Ejemplo n.º 8
0
        public void Read(IValueProvider value, XElement serialized)
        {
            string name     = serialized.Name.LocalName;
            var    type     = FindDerivedType(value.Type, name);
            var    instance = Activator.CreateInstance(type);

            var discoveryStrategy = ValueDiscoveryStrategy.Get(type) ?? valueDiscovery;
            var values            = discoveryStrategy.GetValues(instance);

            foreach (var property in values)
            {
                XAttribute attribute = serialized.Attribute(property.Name);
                if (attribute != null)
                {
                    SerializationService.Instance.Read(property, attribute.Value);
                    continue;
                }

                XElement subElement = serialized.Element(property.Name);
                if (subElement != null)
                {
                    SerializationService.Instance.Read(property, subElement);
                    continue;
                }
            }

            value.SetValue(instance);
        }
        /// <summary>
        /// Sets the value of an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="value">The value to set the element's value to.</param>
        private static void SetValue(UIElement element, string value)
        {
            FrameworkElementAutomationPeer elementPeer = FrameworkElementAutomationPeer.CreatePeerForElement(element) as FrameworkElementAutomationPeer;
            IValueProvider elementValueProvider        = elementPeer.GetPattern(PatternInterface.Value) as IValueProvider;

            elementValueProvider.SetValue(value);
        }
Ejemplo n.º 10
0
        // Sets the text of the edit part of the Combo
        void IValueProvider.SetValue(string str)
        {
            // Ensure that the window and all its parents are enabled.
            Misc.CheckEnabled(_hwnd);

            // piggy-back on win32editbox proxy
            NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize);

            if (GetComboInfo(_hwnd, ref cbInfo) && SafeNativeMethods.IsWindowVisible(cbInfo.hwndItem))
            {
                WindowsEditBox editBox       = new WindowsEditBox(cbInfo.hwndItem, null, -1);
                IValueProvider valueProvider = (IValueProvider)editBox.GetPatternProvider(ValuePattern.Pattern);

                // try to set user-provided text
                valueProvider.SetValue(str);

                // Let the parent know that the value has change, to allow the parent to do any processing it needs
                // to do on value change.
                IntPtr hwndParent = Misc.GetParent(_hwnd);
                if (hwndParent != IntPtr.Zero)
                {
                    int    id     = Misc.GetWindowId(_hwnd);
                    IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE));

                    Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd);
                }

                return;
            }

            throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
        }
Ejemplo n.º 11
0
 public void SetValue(object target, object value)
 {
     // Make sure the default value is cloned since arrays are not truly read only.
     if (value != null && object.ReferenceEquals(value, defaultValue))
     {
         value = defaultValue.Clone();
     }
     baseProvider.SetValue(target, value);
 }
Ejemplo n.º 12
0
 public void SetValue(object target, object value)
 {
     foreach (var mapped in reverseMap[value ?? NullValue])
     {
         // Use the first.
         value = mapped;
         break;
     }
     baseProvider.SetValue(target, value);
 }
Ejemplo n.º 13
0
        public void Read(IValueProvider value, string serialized)
        {
            var    parseMethod = GetParseMethod(value);
            object result      = null;

            if (parseMethod != null)
            {
                result = parseMethod.Invoke(null, new object[] { serialized, CultureInfo.InvariantCulture });
            }
            value.SetValue <object>(result);
        }
Ejemplo n.º 14
0
        public void Read(IValueProvider value, XElement serialized)
        {
            serialized = serialized.Elements().First();
            SetNamespace(serialized, "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
#if SILVERLIGHT
            var brush = XamlReader.Load(serialized.ToString());
#else
            var brush = XamlReader.Parse(serialized.ToString());
#endif
            value.SetValue(brush);
        }
Ejemplo n.º 15
0
 public void SetValue(object target, object value)
 {
     if (valueProvider == null)
     {
         property.SetValue(target, value);
     }
     else
     {
         valueProvider.SetValue(target, value);
     }
 }
        public void SetValuesWithAutomationPeers()
        {
            DataClass       dataClass = null;
            IInvokeProvider invokeProvider;

            this.EnqueueCallback(() =>
            {
                dataClass = DataClassList.GetDataClassList(1, ListOperations.All)[0];
                this.DataForm.CurrentItem = dataClass;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                this.GetAutomationPeer();
                this.GetChildAutomationPeers();

                Assert.AreEqual(true, dataClass.BoolProperty);
                Assert.AreEqual("test string 0", dataClass.StringProperty);
                invokeProvider = this._editButtonAutomationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                this.ExpectContentLoaded();
                invokeProvider.Invoke();
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                this.GetChildAutomationPeers();

                IToggleProvider toggleProvider = (this._inputControlAutomationPeers[0] as CheckBoxAutomationPeer).GetPattern(PatternInterface.Toggle) as IToggleProvider;
                IValueProvider valueProvider   = (this._inputControlAutomationPeers[2] as TextBoxAutomationPeer).GetPattern(PatternInterface.Value) as IValueProvider;

                toggleProvider.Toggle();
                valueProvider.SetValue("new string");

                invokeProvider = this._commitButtonAutomationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                this.ExpectContentLoaded();
                invokeProvider.Invoke();
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(false, dataClass.BoolProperty);
                Assert.AreEqual("new string", dataClass.StringProperty);
            });

            this.EnqueueTestComplete();
        }
Ejemplo n.º 17
0
        public void MaxLengthTest()
        {
            TextBox textBox;
            IRawElementProviderSimple provider;

            GetProviderAndControl(out provider, out textBox);

            IValueProvider valueProvider
                = (IValueProvider)provider.GetPatternProvider(
                      ValuePatternIdentifiers.Pattern.Id);

            textBox.MaxLength = 0;
            valueProvider.SetValue(TEST_MESSAGE);
            Assert.AreEqual(TEST_MESSAGE, valueProvider.Value);

            textBox.MaxLength = 1;
            valueProvider.SetValue(TEST_MESSAGE);
            Assert.AreEqual("O", valueProvider.Value);

            textBox.MaxLength = 5;
            valueProvider.SetValue(TEST_MESSAGE);
            Assert.AreEqual("One m", valueProvider.Value);
        }
Ejemplo n.º 18
0
        public void TestHasKeyboardFocusAfterPattern()
        {
            PasswordBox fe = CreateConcreteFrameworkElement() as PasswordBox;

            AutomationPeer peer     = FrameworkElementAutomationPeer.CreatePeerForElement(fe);
            IValueProvider provider = null;

            CreateAsyncTest(fe,
                            () => {
                provider = (IValueProvider)peer.GetPattern(PatternInterface.Value);
                Assert.IsNotNull(provider, "#0");
            },
                            () => provider.SetValue("Hello world"),
                            () => Assert.IsTrue(peer.HasKeyboardFocus(), "#1"));
        }
        public virtual void ShouldBeAbleToSetValueThroughAutomationPeer()
        {
            TimePickerPopup item = TimePickerPopupInstance;

            item.Culture = new CultureInfo("nl-NL");
            item.Format  = new CustomTimeFormat("HH:mm:ss");
            TimePickerPopupAutomationPeer peer = null;
            IValueProvider provider            = null;

            TestAsync(
                item,
                () => peer     = (TimePickerPopupAutomationPeer)FrameworkElementAutomationPeer.CreatePeerForElement(item),
                () => provider = (IValueProvider)peer.GetPattern(PatternInterface.Value),
                () => provider.SetValue("03:30:00"),     // take care to set a time that is not snapped
                () => Assert.AreEqual(item.Value.Value.TimeOfDay, new DateTime(1900, 1, 1, 3, 30, 00).TimeOfDay));
        }
Ejemplo n.º 20
0
        public virtual void ShouldBeAbleToSetValueThroughAutomationPeer()
        {
            TimeUpDown item = new TimeUpDown();

            item.Culture = new CultureInfo("nl-NL");
            item.Format  = new CustomTimeFormat("HH:mm:ss");
            TimeUpDownAutomationPeer peer     = null;
            IValueProvider           provider = null;

            TestAsync(
                item,
                () => peer     = (TimeUpDownAutomationPeer)FrameworkElementAutomationPeer.CreatePeerForElement(item),
                () => provider = (IValueProvider)peer.GetPattern(PatternInterface.Value),
                () => provider.SetValue("03:45:12"),
                () => Assert.AreEqual(item.Value.Value.TimeOfDay, new DateTime(1900, 1, 1, 3, 45, 12).TimeOfDay));
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Sets the value.
        /// </summary>
        /// <param name="target">The target to set the value on.</param>
        /// <param name="value">The value to set on the target.</param>
        public void SetValue(object target, object value)
        {
            try
            {
                Provider.SetValue(target, value);
            }
            catch (Exception ex)
            {
                if (ex.InnerException is ObjectDisposedException)
                {
                    return;
                }

                throw;
            }
        }
        public void SetValue(object target, object value)
        {
            var permision = PermissionHandler.GeneralAccessChainValidation(
                Request: this.IRequest,
                Type: this.PropertyType,
                ModelAction: this.ModelAction,
                RequestMethod: this.RequestMethod,
                RelationType: this.Relation,
                ModelItself: target,
                TypeValue: value);

            if (!(permision is bool && (bool)permision))
            {
                throw new Exception(permision as string);
            }
            else
            {
                ValueProvider.SetValue(target, value);
            }
        }
Ejemplo n.º 23
0
        void CheckObject(object value, JsonObjectContract contract)
        {
            parsedCount++;
            // Traverse all properties in the same way the Json.NET serialized does,
            // by taking in account only the serializable properties and skipping JsonIgnore ones.
            for (int index = 0; index < contract.Properties.Count; index++)
            {
                JsonProperty property = contract.Properties [index];
                try {
                    object memberValue;

                    // Check if the object has the IsChanged flag and update the StorableNode
                    // Also reset the flag if it's required.
                    if (property.PropertyName == "IsChanged")
                    {
                        IValueProvider provider = property.ValueProvider;
                        bool           changed  = (bool)provider.GetValue(value);
                        if (changed)
                        {
                            if (!current.IsChanged)
                            {
                                current.IsChanged = true;
                            }
                            if (reset)
                            {
                                provider.SetValue(value, false);
                            }
                        }
                    }
                    else
                    {
                        if (!CalculatePropertyValues(value, property, out memberValue))
                        {
                            continue;
                        }
                        CheckValue(memberValue);
                    }
                } catch (Exception ex) {
                }
            }
        }
Ejemplo n.º 24
0
            public void SetValue(object target, object value)
            {
                switch (value)
                {
                case null:
                    _baseProvider.SetValue(target, null);
                    break;

                case string _:
                    _targetProperty.SetValue(target, RemovePrefix((string)value));
                    break;

                case IList <string> _:
                    _targetProperty.SetValue(target, ((IEnumerable <string>)value).Select(RemovePrefix).ToList());
                    break;

                default:
                    _targetProperty.SetValue(target, ((IEnumerable <string>)value).Select(RemovePrefix).ToArray());
                    break;
                }
            }
Ejemplo n.º 25
0
        public void ValueProvider_Methods()
        {
            bool             concreteLoaded = false;
            ComboBoxConcrete concrete       = CreateConcreteFrameworkElement() as ComboBoxConcrete;

            concrete.Loaded += (o, e) => concreteLoaded = true;
            concrete.Items.Add(new ComboBoxItem()
            {
                Content = "1"
            });
            concrete.Items.Add(new ComboBoxItem()
            {
                Content = "2"
            });
            concrete.Width = 300;
            TestPanel.Children.Add(concrete);

            EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0");
            Enqueue(() => concrete.ApplyTemplate());
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete);
                Assert.IsNotNull(peer, "CreatePeerForElement #0");

                IValueProvider value
                    = peer.GetPattern(PatternInterface.Value) as IValueProvider;
                // Yes is returning null!
                Assert.IsNull(value, "ValueProvider #0");

                // We are going to try again using explicit cast
                value = peer as IValueProvider;
                Assert.IsNotNull(value, "ValueProvider #1");

                // We can't change the value anyway
                Assert.IsTrue(value.IsReadOnly, "IsReadOnly #0");
                Assert.Throws <InvalidOperationException> (delegate {
                    value.SetValue("1");
                }, "SetValue #0");
            });
            EnqueueTestComplete();
        }
Ejemplo n.º 26
0
 public void SetValue(object target, object value)
 {
     _underlyingValueProvider.SetValue(target, value ?? 0);
 }
Ejemplo n.º 27
0
 public void SetValue(object target, object value) => UnderlyingValueProvider.SetValue(target, value);
 public void SetValue(object target, object value)
 {
     _valueProvider.SetValue(target, value);
 }
Ejemplo n.º 29
0
 public void SetValue(object target, object value)
 {
     _defaultMemberValueProvider.SetValue(target, value);
 }
Ejemplo n.º 30
0
 public void SetValue(object target, object value)
 {
     innerProvider.SetValue(target, value ?? defaultValue);
 }