コード例 #1
0
        public void InsertItemExpectedTextboxTextChanged_SpaceInFieldName_ErrorStatusUpdated()
        {
            const string ExpectedText      = "[[City(). Name]]";
            var          mockResourceModel = new Mock <IResourceModel>();

            mockResourceModel.Setup(model => model.DataList).Returns("<ADL><City><Name></Name></City></ADL>");

            var dataListViewModel = new DataListViewModel();

            dataListViewModel.InitializeDataListViewModel(mockResourceModel.Object);
            DataListSingleton.SetDataList(dataListViewModel);
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(
                a => a.PerformResultInsertion(It.IsAny <string>(), It.IsAny <IntellisenseProviderContext>())).Returns(ExpectedText);

            var intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, ExpectedText, "cake");

            var textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.InsertItem(intellisenseProviderResult, true);

            Thread.Sleep(250);
            Thread.Sleep(100);

            Assert.AreEqual(ExpectedText, textBox.Text, "Expected [ " + ExpectedText + " ] But got [ " + textBox.Text + " ]");
            Assert.IsTrue(textBox.HasError, "Expected [ True ] But got [ " + textBox.HasError + " ]");
        }
コード例 #2
0
        public CalculateIntellisenseProvider(ISyntaxTreeBuilderHelper syntaxTreeBuilderHelper)
        {
            _syntaxTreeBuilderHelper = syntaxTreeBuilderHelper;
            IntellisenseProviderType = IntellisenseProviderType.NonDefault;
            IFrameworkRepository <IFunction> functionList = MathOpsFactory.FunctionRepository();

            functionList.Load();
            bool creatingFunctions = false;

            if (_functionNames == null)
            {
                creatingFunctions = true;
                _functionNames    = new HashSet <string>(StringComparer.Ordinal);
            }

            IntellisenseResult = functionList.All().Select(currentFunction =>
            {
                string description         = currentFunction.Description;
                string dropDownDescription = description;
                if (description != null && description.Length > 80)
                {
                    dropDownDescription = description.Substring(0, 77) + "...";
                }
                if (creatingFunctions)
                {
                    _functionNames.Add(currentFunction.FunctionName);
                }
                IntellisenseProviderResult result = new IntellisenseProviderResult(this, currentFunction.FunctionName, dropDownDescription, description, currentFunction.arguments != null ? currentFunction.arguments.ToArray() : new string[0], currentFunction.ArgumentDescriptions != null ? currentFunction.ArgumentDescriptions.ToArray() : new string[0]);
                return(result);
            }).OrderBy(p => p.Name).ToList();
        }
コード例 #3
0
        public void InsertItemExpectedTextboxTextChangedAndErrorStatusUpdated()
        {
            var mockDataListViewModel = new Mock <IDataListViewModel>();

            mockDataListViewModel.Setup(model => model.Resource).Returns(new Mock <IResourceModel>().Object);
            DataListSingleton.SetDataList(mockDataListViewModel.Object);
            const string ExpectedText         = "[[City()";
            var          intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(
                a => a.PerformResultInsertion(It.IsAny <string>(), It.IsAny <IntellisenseProviderContext>())).Returns(ExpectedText);

            var intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, ExpectedText, "cake");

            var textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.InsertItem(intellisenseProviderResult, true);

            Thread.Sleep(250);
            Thread.Sleep(100);

            Assert.AreEqual(ExpectedText, textBox.Text, "Expected [ " + ExpectedText + " ] But got [ " + textBox.Text + " ]");
            Assert.AreEqual(true, textBox.HasError, "Expected [ True ] But got [ " + textBox.HasError + " ]");
        }
コード例 #4
0
        public void IntellisenseBoxDoesntCrashWhenInsertingResultsGivenAProviderThatThrowsAnException()
        {
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(
                a => a.PerformResultInsertion(It.IsAny <string>(), It.IsAny <IntellisenseProviderContext>()))
            .Throws(new Exception());
            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);

            var intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, "City", "cake");

            var textBox = new IntellisenseTextBox();

            textBox.InsertItem(intellisenseProviderResult, true);
            // When exepctions are thrown, no results are to be displayed
            Assert.AreEqual(0, textBox.View.Count, "Expected [ 0 ] But got [ " + textBox.View.Count + " ]");
            //The desired result is that an exception isn't thrown
        }
コード例 #5
0
        public void IntellisenseTextBox_InsertItem_InsertDateTimePartsIn_InsertsCorrectly()
        {
            //------------Setup for test--------------------------
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(false);

            var intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, "DW", "DW");
            //------------Execute Test---------------------------
            var textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.IsDropDownOpen = true;
            textBox.Text           = "d YY mm";
            textBox.CaretIndex     = 1;
            textBox.InsertItem(intellisenseProviderResult, true);
            //------------Assert Results-------------------------
            Assert.AreEqual("DW YY mm", textBox.Text);
        }
コード例 #6
0
        public void CalculateIntellisenseProvider_GetIntellisenseResults_DesiredResultSetIsEntiresetAndInputIsInvalidText_EntiresetPlusAndError()
        {
            var context = new IntellisenseProviderContext
            {
                CaretPosition     = 2,
                InputText         = "XXXXX",
                IsInCalculateMode = true,
                DesiredResultSet  = IntellisenseDesiredResultSet.EntireSet
            };

            CalculateIntellisenseProvider calculateIntellisenseProvider = GetCalculateProvider(true);

            IList <IntellisenseProviderResult> results = calculateIntellisenseProvider.GetIntellisenseResults(context);

            Assert.AreEqual(176, results.Count);
            IntellisenseProviderResult intellisenseProviderResult = results.Last();

            Assert.AreEqual("Syntax Error", intellisenseProviderResult.Name);
            Assert.AreEqual("An error occurred while parsing { XXXXX } It appears to be malformed", intellisenseProviderResult.Description);
        }
コード例 #7
0
        void AppendResults(IList <IntellisenseProviderResult> results)
        {
            IntellisenseProviderResult popup = null;

            foreach (var currentResult in results)
            {
                if (!currentResult.IsError && currentResult.IsPopup)
                {
                    popup = currentResult;
                }
            }
            if (popup != null)
            {
                var description = popup.Description;

                _toolTip.Content = string.IsNullOrEmpty(description) ? "" : description;
                _toolTip.IsOpen  = true;
                ToolTip          = _toolTip;
            }
        }
コード例 #8
0
        public void IntellisenseTextBox_InsertItem_AppendDateTimePartsWithDifferentCase_InsertsCorrectly()
        {
            //------------Setup for test--------------------------
            Mock <IIntellisenseProvider> intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(false);

            IntellisenseProviderResult intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, "yyyy", "yyyy");
            //------------Execute Test---------------------------
            IntellisenseTextBox textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.IsOpen     = true;
            textBox.Text       = "dd YY";
            textBox.CaretIndex = 5;
            textBox.InsertItem(intellisenseProviderResult, false);
            //------------Assert Results-------------------------
            Assert.AreEqual("dd yyyy", textBox.Text);
        }
コード例 #9
0
        public CalculateIntellisenseProvider(ISyntaxTreeBuilderHelper syntaxTreeBuilderHelper)
        {
            _syntaxTreeBuilderHelper = syntaxTreeBuilderHelper;
            IntellisenseProviderType = IntellisenseProviderType.NonDefault;
            var functionList = MathOpsFactory.FunctionRepository();

            functionList.Load();
            IntellisenseResult = functionList.All().Select(currentFunction =>
            {
                var description         = currentFunction.Description;
                var dropDownDescription = description;
                if (description != null && description.Length > 80)
                {
                    dropDownDescription = description.Substring(0, 77) + "...";
                }
                _functionNames.Add(currentFunction.FunctionName);

                var result = new IntellisenseProviderResult(this, currentFunction.FunctionName, dropDownDescription, description, currentFunction.arguments?.ToArray() ?? new string[0], currentFunction.ArgumentDescriptions?.ToArray() ?? new string[0]);
                return(result);
            }).OrderBy(p => p.Name).ToList();
        }
コード例 #10
0
        private void ProcessResults(string text, IList <IntellisenseProviderResult> results, bool cleared)
        {
            if (results != null && results.Count > 0)
            {
                IntellisenseProviderResult popup = null;

                for (int i = 0; i < results.Count; i++)
                {
                    IntellisenseProviderResult currentResult = results[i];

                    if (!currentResult.IsError)
                    {
                        if (!currentResult.IsPopup)
                        {
                            if (!cleared)
                            {
                                cleared = true;
                            }
                        }
                        else
                        {
                            popup = currentResult;
                        }
                    }
                }
                if (popup != null)
                {
                    string description = popup.Description;

                    _toolTip.Content = string.IsNullOrEmpty(description) ? "" : description;
                    _toolTip.IsOpen  = true;
                    ToolTip          = _toolTip;
                }
            }
            else
            {
                var ttErrorBuilder = new StringBuilder();
                if (text.Contains("[[") && text.Contains("]]"))
                {
                    if (FilterType == enIntellisensePartType.RecordsetFields || FilterType == enIntellisensePartType.RecordsetsOnly)
                    {
                        if (!(text.Contains("(") && text.Contains(")")))
                        {
                            HasError = true;
                            ttErrorBuilder.AppendLine("Scalar is not allowed");
                        }
                    }
                    else if (FilterType == enIntellisensePartType.ScalarsOnly)
                    {
                        if (text.Contains("(") && text.Contains(")"))
                        {
                            HasError = true;
                            ttErrorBuilder.AppendLine("Recordset is not allowed");
                        }
                    }
                }

                string errorText = ttErrorBuilder.ToString();
                _toolTip.Content = string.IsNullOrEmpty(errorText) ? "" : errorText;
            }
        }