public void GivenTheDropDownListAs(string dropDownList)
        {
            var expectedList = string.IsNullOrEmpty(dropDownList) ? new string[] { } : dropDownList.Split(',');
            var calc         = ScenarioContext.Current.Get <bool>("IsInCalculate");

            var context = new IntellisenseProviderContext
            {
                CaretPosition        = ScenarioContext.Current.Get <int>("cursorIndex"),
                CaretPositionOnPopup = ScenarioContext.Current.Get <int>("cursorIndex"),
                InputText            = ScenarioContext.Current.Get <string>("inputText"),
                DesiredResultSet     = calc ? IntellisenseDesiredResultSet.ClosestMatch : IntellisenseDesiredResultSet.Default,
                FilterType           = ScenarioContext.Current.Get <enIntellisensePartType>("filterType"),
                IsInCalculateMode    = calc
            };

            ScenarioContext.Current.Add("context", context);

            IIntellisenseProvider provider = ScenarioContext.Current.Get <IIntellisenseProvider>("provider");

            var getResults = provider.GetIntellisenseResults(context);
            var actualist  = getResults.Where(i => !i.IsError).Select(i => i.Name).ToArray();

            Assert.AreEqual(expectedList.Length, actualist.Length);
            CollectionAssert.AreEqual(expectedList, actualist);
        }
        public void EnsureIntellisenseResults(string text, bool forceUpdate, IntellisenseDesiredResultSet desiredResultSet)
        {
            if (text == null)
            {
                text = string.Empty;
            }
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                bool calculateMode = false;

                if (AllowUserCalculateMode)
                {
                    if (text.Length > 0 && text[0] == '=')
                    {
                        calculateMode = true;
                        text          = text.Substring(1);
                    }

                    IsInCalculateMode = calculateMode;
                }
                else if (IsInCalculateMode)
                {
                    calculateMode = true;
                }

                if (forceUpdate)
                {
                    IIntellisenseProvider provider = IntellisenseProvider;
                    var context = new IntellisenseProviderContext {
                        FilterType = FilterType, DesiredResultSet = desiredResultSet, InputText = text, CaretPosition = CaretIndex
                    };

                    if ((context.IsInCalculateMode = calculateMode) && AllowUserCalculateMode)
                    {
                        if (CaretIndex > 0)
                        {
                            context.CaretPosition = CaretIndex - 1;
                        }
                    }

                    IList <IntellisenseProviderResult> results = null;

                    try
                    {
                        results = provider.GetIntellisenseResults(context);
                        _intellisenseResults = results.ToList();
                    }
                    // ReSharper disable EmptyGeneralCatchClause
                    catch
                    // ReSharper restore EmptyGeneralCatchClause
                    {
                        //This try catch is to prevent the intellisense box from ever being crashed from a provider.
                        //This catch is intentionally blanks since if a provider throws an exception the intellisense
                        //box should simbly ignore that provider.
                    }
                    ProcessResults(text, results, false);
                }
            }
        }
        public void ThenTheResultHasErrors(string p0)
        {
            var calc = ScenarioContext.Current.Get <bool>("IsInCalculate");

            var context = new IntellisenseProviderContext
            {
                CaretPosition        = ScenarioContext.Current.Get <int>("cursorIndex"),
                CaretPositionOnPopup = ScenarioContext.Current.Get <int>("cursorIndex"),
                InputText            = ScenarioContext.Current.Get <string>("inputText"),
                DesiredResultSet     = calc ? IntellisenseDesiredResultSet.ClosestMatch : IntellisenseDesiredResultSet.Default,
                FilterType           = ScenarioContext.Current.Get <enIntellisensePartType>("filterType"),
                IsInCalculateMode    = calc
            };

            ScenarioContext.Current.Add("context", context);

            IIntellisenseProvider provider = ScenarioContext.Current.Get <IIntellisenseProvider>("provider");

            var getResults = provider.GetIntellisenseResults(context);
            var actualist  = getResults.Where(i => i.IsError);

            Assert.AreEqual(!actualist.Any(), bool.Parse(p0));
        }
        public override IActionableErrorInfo Check()
        {
            var  value   = GetValue();
            bool isValid = true;

            string calculationExpression;

            if (DataListUtil.IsCalcEvaluation(value, out calculationExpression))
            {
                IntellisenseProviderContext context = new IntellisenseProviderContext
                {
                    CaretPosition     = value.Length,
                    InputText         = value,
                    IsInCalculateMode = true,
                    DesiredResultSet  = IntellisenseDesiredResultSet.ClosestMatch
                };

                var results = _intellisenseProvider.GetIntellisenseResults(context);

                if (results.Any(e => e.IsError))
                {
                    isValid   = false;
                    ErrorText = results.First(e => e.IsError).Description;
                }
            }

            if (!isValid)
            {
                return(new ActionableErrorInfo(DoError)
                {
                    Message = string.Format("{0} {1}", LabelText, ErrorText)
                });
            }

            return(null);
        }