private BSNavItem <TOwner> GetNavItem <TOwner>(TriggerContext <TOwner> context)
            where TOwner : PageObject <TOwner>
        {
            var tabPane = context.Component.GetAncestorOrSelf <BSTabPane <TOwner> >() as IUIComponent <TOwner>;

            if (tabPane == null)
            {
                throw new InvalidOperationException($"Cannot find '{nameof(BSTabPane<TOwner>)}' ancestor.");
            }

            string navItemName = tabPane.ComponentName;

            BSNavItem <TOwner> navItem = tabPane.Parent.Controls.
                                         OfType <IUIComponent <TOwner> >().
                                         FirstOrDefault(x => x.ComponentName == navItemName && (x is BSPill <TOwner> || x is BSTab <TOwner>))
                                         as BSNavItem <TOwner>;

            if (navItem == null)
            {
                string tabPillInnerXPath = $"(self::a | child::a)[@href='#{tabPane.Attributes.Id.Value}']";
                string pillXPath         = UIComponentResolver.GetControlDefinition(typeof(BSPill <TOwner>)).ScopeXPath;

                bool isUsingPill = tabPane.Parent.Scope.Exists(By.XPath($".//{pillXPath}[{tabPillInnerXPath}]").SafelyAtOnce());

                var findAttribute = new FindByInnerXPathAttribute(tabPillInnerXPath);

                navItem = isUsingPill
                    ? (BSNavItem <TOwner>)tabPane.Parent.Controls.Create <BSPill <TOwner> >(navItemName, findAttribute)
                    : tabPane.Parent.Controls.Create <BSTab <TOwner> >(navItemName, findAttribute);
            }

            return(navItem);
        }
        protected override ValidationMessage <TOwner> CreateAssociatedControl(Control <TOwner> control)
        {
            var validationMessageDefinition = UIComponentResolver.GetControlDefinition(typeof(ValidationMessage <TOwner>));

            PlainScopeLocator scopeLocator = new PlainScopeLocator(By.XPath("ancestor::" + validationMessageDefinition.ScopeXPath))
            {
                SearchContext = control.Scope
            };

            return(Component.Controls.Create <ValidationMessage <TOwner> >(control.ComponentName, scopeLocator));
        }
Пример #3
0
        /// <summary>
        ///   Fors the specified control selector.
        /// </summary>
        /// <param name="controlSelector">
        ///   The control selector.
        /// </param>
        /// <returns></returns>
        public ValidationMessage <TOwner> For(Func <TOwner, IControl <TOwner> > controlSelector)
        {
            var validationMessageDefinition = UIComponentResolver.GetControlDefinition(typeof(ValidationMessage <TOwner>));

            IControl <TOwner> boundControl = controlSelector(Component.Owner);

            PlainScopeLocator scopeLocator = new PlainScopeLocator(By.XPath("ancestor::" + validationMessageDefinition.ScopeXPath))
            {
                SearchContext = boundControl.Scope
            };

            return(Component.Controls.Create <ValidationMessage <TOwner> >(boundControl.ComponentName, scopeLocator));
        }