public void ValidationSummaryPeerInvoke() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { bool clicked = false; FocusingInvalidControlEventArgs eArgs = null; ValidationSummaryItem vsi = null; vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e) { clicked = true; eArgs = e; vsi = e.Item; }); ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs); Assert.IsNotNull(peer); ((IInvokeProvider)peer).Invoke(); Assert.IsFalse(clicked, "No error is selected, so the event should not fire"); ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this); vs.Errors.Add(newEsi); vs.ErrorsListBoxInternal.SelectedItem = newEsi; ((IInvokeProvider)peer).Invoke(); Assert.IsTrue(clicked, "Invoking with a selected ESI triggers the event to fire"); Assert.AreEqual(newEsi, vsi, "The ESI should match the selected item"); Assert.AreEqual("property name", eArgs.Target.PropertyName, "The source should match the selected item"); }); EnqueueTestComplete(); }
private void ExecuteClick(object sender) { ListBox lb = sender as ListBox; if (lb != null) { ValidationSummaryItem vsi = lb.SelectedItem as ValidationSummaryItem; if (vsi != null && this.FocusControlsOnClick) { int idx; // Ensure the currently selected item source is valid if (vsi.Sources.Count == 0) { // Clear the current ESI source if the ESI has none, such as when the ESI has changed this._currentValidationSummaryItemSource = null; } else { // If the current ESI source is not part of the current set, select the first one by default. idx = FindMatchingErrorSource(vsi.Sources, this._currentValidationSummaryItemSource); if (idx < 0) { this._currentValidationSummaryItemSource = vsi.Sources[0]; } } // Raise the event FocusingInvalidControlEventArgs e = new FocusingInvalidControlEventArgs(vsi, this._currentValidationSummaryItemSource); this.OnFocusingInvalidControl(e); #if OPENSILVER // Raise the AutomationPeer event ValidationSummaryAutomationPeer peer = ValidationSummaryAutomationPeer.FromElement(this) as ValidationSummaryAutomationPeer; if (peer != null && AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } #endif // Focus the target, which will usually be the current ESI source or the overwritten one if (!e.Handled && e.Target != null && e.Target.Control != null) { e.Target.Control.Focus(); } // Update currently selected item, but only if there are multiple ESI sources. if (vsi.Sources.Count > 0) { idx = FindMatchingErrorSource(vsi.Sources, e.Target); idx = idx < 0 ? 0 : ++idx % vsi.Sources.Count; this._currentValidationSummaryItemSource = vsi.Sources[idx]; } } } }
public void ValidationSummaryPeer() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs); Assert.IsNotNull(peer); Assert.AreEqual(AutomationControlType.Group, peer.GetAutomationControlType()); Assert.AreEqual("ValidationSummary", peer.GetClassName()); Assert.AreEqual("0 Errors", peer.GetName()); vs.Errors.Add(new ValidationSummaryItem("header1", "msg1", ValidationSummaryItemType.PropertyError, null, null)); Assert.AreEqual("1 Error", peer.GetName()); vs.Errors.Add(new ValidationSummaryItem("header2", "msg2", ValidationSummaryItemType.PropertyError, null, null)); Assert.AreEqual("2 Errors", peer.GetName()); }); EnqueueTestComplete(); }