<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using Signum.Entities;
using Signum.Entities.UserQueries;
using Signum.Utilities;
using Signum.Engine.Basics;
using Signum.Entities.Reflection;
using Signum.Entities.DynamicQuery;
using Signum.Engine;
using Signum.Entities.Omnibox;

namespace Signum.Windows.UIAutomation
{
    public class OmniBoxProxy
    {
        public int OmniboxTimeout = 4000;

        public AutomationElement Element { get; private set; }

        public OmniBoxProxy(AutomationElement element)
        {
            this.Element = element; 
        }

        public SearchWindowProxy SelectQuery(object queryName)
        {
            var omniboxName = QueryUtils.GetNiceName(queryName).ToOmniboxPascal();

            return new SearchWindowProxy(SelectCapture(omniboxName, "Q:" + QueryUtils.GetQueryUniqueKey(queryName))); 
        }

        public NormalWindowProxy<T> SelectEntity<T>(Lite<T> lite) where T : IdentifiableEntity
        {
            var omniboxName = lite.EntityType.NiceName().ToOmniboxPascal() + " " + lite.Id;

            return new NormalWindowProxy<T>(SelectCapture(omniboxName, "E:" + lite.Key())); 
        }

        public SearchWindowProxy SelectUserQuery(Lite<UserQueryDN> userQuery)
        {
            var omniboxName = "'" + userQuery.ToString() + "'";

            return new SearchWindowProxy(SelectCapture(omniboxName, "UQ:" + userQuery.Key())); 
        }

        public AutomationElement SelectCapture(string autoCompleteText, string name, int? timeOut = null)
        {
            return Element.CaptureWindow(
                () =>
                {
                    Element.Value(autoCompleteText);

                    timeOut = timeOut ?? OmniboxTimeout;

                    var lb = Element.WaitChildById("lstBox", timeOut);

                    var item = lb.TryDescendant(e => e.Current.Name == name);

                    if (item == null)
                        throw new ElementNotFoundException("{0} not found after writing {1} on the Omnibox".Formato(name, autoCompleteText));

                    var listItem = item.Normalize(a => a.Current.ControlType == ControlType.ListItem);

                    listItem.Pattern<SelectionItemPattern>().Select();
                },
                () => "window after selecting {0} on the omnibox".Formato(name), timeOut);
        }
    }
}
<commit_msg>NicePluralName OmniBox in Test Windows<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using Signum.Entities;
using Signum.Entities.UserQueries;
using Signum.Utilities;
using Signum.Engine.Basics;
using Signum.Entities.Reflection;
using Signum.Entities.DynamicQuery;
using Signum.Engine;
using Signum.Entities.Omnibox;

namespace Signum.Windows.UIAutomation
{
    public class OmniBoxProxy
    {
        public int OmniboxTimeout = 4000;

        public AutomationElement Element { get; private set; }

        public OmniBoxProxy(AutomationElement element)
        {
            this.Element = element; 
        }

        public SearchWindowProxy SelectQuery(object queryName)
        {
            var omniboxName = QueryUtils.GetNiceName(queryName).ToOmniboxPascal();

            return new SearchWindowProxy(SelectCapture(omniboxName, "Q:" + QueryUtils.GetQueryUniqueKey(queryName))); 
        }

        public NormalWindowProxy<T> SelectEntity<T>(Lite<T> lite) where T : IdentifiableEntity
        {
            var omniboxName = lite.EntityType.NicePluralName().ToOmniboxPascal() + " " + lite.Id;

            return new NormalWindowProxy<T>(SelectCapture(omniboxName, "E:" + lite.Key())); 
        }

        public SearchWindowProxy SelectUserQuery(Lite<UserQueryDN> userQuery)
        {
            var omniboxName = "'" + userQuery.ToString() + "'";

            return new SearchWindowProxy(SelectCapture(omniboxName, "UQ:" + userQuery.Key())); 
        }

        public AutomationElement SelectCapture(string autoCompleteText, string name, int? timeOut = null)
        {
            return Element.CaptureWindow(
                () =>
                {
                    Element.Value(autoCompleteText);

                    timeOut = timeOut ?? OmniboxTimeout;

                    var lb = Element.WaitChildById("lstBox", timeOut);

                    var item = lb.TryDescendant(e => e.Current.Name == name);

                    if (item == null)
                        throw new ElementNotFoundException("{0} not found after writing {1} on the Omnibox".Formato(name, autoCompleteText));

                    var listItem = item.Normalize(a => a.Current.ControlType == ControlType.ListItem);

                    listItem.Pattern<SelectionItemPattern>().Select();
                },
                () => "window after selecting {0} on the omnibox".Formato(name), timeOut);
        }
    }
}

{'fraction_non_alphanumeric': 0.09696969696969697, 'fraction_numerical': 0.002737047898338221, 'mean_word_length': 2.191515907673113, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7319730', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1384, 'n_words': 282}