Example #1
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 + " ]");
        }
Example #2
0
        public void TextContaningTabIsPasedIntoAnIntellisenseTextBoxExpectedTabInsertedEventIsRaised()
        {
            var eventRaised            = false;
            IntellisenseTextBox sender = null;

            EventManager.RegisterClassHandler(typeof(IntellisenseTextBox), IntellisenseTextBox.TabInsertedEvent,
                                              new RoutedEventHandler((s, e) =>
            {
                eventRaised = true;
                sender      = s as IntellisenseTextBox;
            }));

            System.Windows.Clipboard.SetText("Cake\t");

            var textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();

            textBox.Paste();

            Assert.IsTrue(eventRaised,
                          "The 'IntellisenseTextBox.TabInsertedEvent' wasn't raised when text containing a tab was pasted into the IntellisenseTextBox.");
            Assert.AreEqual(textBox, sender,
                            "The IntellisenseTextBox in which the text containg a tab was pasted was different from the one which raised teh event.");
        }
Example #3
0
        public void TextContaningNoTabIsPasedIntoAnIntellisenseTextBoxExpectedTabInsertedEventNotRaised()
        {
            var preserveClipboard = System.Windows.Clipboard.GetText();

            try
            {
                var eventRaised = false;
                EventManager.RegisterClassHandler(typeof(IntellisenseTextBox), IntellisenseTextBox.TabInsertedEvent,
                                                  new RoutedEventHandler((s, e) =>
                {
                    eventRaised = true;
                }));

                System.Windows.Clipboard.SetText("Cake");

                var textBox = new IntellisenseTextBox();
                textBox.Paste();

                Assert.IsFalse(eventRaised,
                               "The 'IntellisenseTextBox.TabInsertedEvent' was raised when text that didn't contain a tab was pasted into the IntellisenseTextBox.");
            }
            finally
            {
                System.Windows.Clipboard.SetText(preserveClipboard);
            }
        }
Example #4
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 + " ]");
        }
Example #5
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsAllAndTextIsRecordset_ToolTipHasNoErrorMessage()
        {
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.None
            };

            textBox.Text = "[[People(*)]]";
            Assert.IsFalse(textBox.HasError);
        }
Example #6
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsRecordsetFieldsAndTextIsRecordset_ToolTipHasNoErrorMessage()
        {
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.RecordsetFields
            };

            textBox.EnsureIntellisenseResults("[[var()]]", false, IntellisenseDesiredResultSet.Default);
            Assert.IsFalse(textBox.HasError);
        }
Example #7
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsScalarsOnlyAndTextIsScalar_ToolTipHasNoErrorMessage()
        {
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.ScalarsOnly
            };

            textBox.EnsureIntellisenseResults("[[var]]", false, IntellisenseDesiredResultSet.Default);
            Assert.IsFalse(textBox.HasError);
        }
Example #8
0
        public void IntellisenseTextBoxTests_ValidateText_FilterTypeIsJsonObjectAndTextIsJson_ToolTipHasNoErrorMessage()
        {
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.JsonObject
            };

            textBox.Text = "[[@City]]";
            Assert.IsFalse(textBox.HasError);
        }
Example #9
0
        public void IntellisenseTextBoxTests_HandlePasteMessageCallsEnsureIntellisenseResults()
        {
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.RecordsetFields
            };

            Assert.IsFalse(textBox.HasError);
            textBox.Text = "[[var]]";
            textBox.Handle(new UpdateAllIntellisenseMessage());
            Assert.IsTrue(textBox.HasError);
        }
Example #10
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsRecodsetFieldsAndTextMultipleRecordSetFields_ToolTipHasNoErrorMessage()
        {
            var textBox = new IntellisenseTextBox
            {
                FilterType             = enIntellisensePartType.RecordsetFields,
                AllowMultipleVariables = true
            };

            textBox.Text = "[[rec(*).warewolf]],[[rec(*).soa]]";
            Assert.IsFalse(textBox.HasError);
        }
Example #11
0
        public void IntellisenseTextBox_KeyDown_CannotCauseWrapInBrackets_WhenNotWrapInBrackets()
        {
            //------------Setup for test--------------------------
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.RecordsetFields, WrapInBrackets = false, Text = "var()"
            };

            //------------Execute Test---------------------------
            textBox.HandleWrapInBrackets(Key.F6);
            //------------Assert Results-------------------------
            Assert.AreEqual("var()", textBox.Text);
        }
Example #12
0
        static void RunWrappedKeyPress(Key key)
        {
            //------------Setup for test--------------------------
            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.RecordsetFields, WrapInBrackets = false, Text = "var()"
            };

            //------------Execute Test---------------------------
            textBox.HandleWrapInBrackets(key);
            //------------Assert Results-------------------------
            Assert.AreEqual("var()", textBox.Text);
        }
Example #13
0
        public void GivenAnExpression_IntellisenseTextBox_SetAppendTextBasedOnSelection()
        {
            //------------Setup for test--------------------------
            var textBox = new IntellisenseTextBox
            {
                FilterType = enIntellisensePartType.ScalarsOnly
                ,
                WrapInBrackets = true
            };
            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
        }
        // This test is here for when the designers load. The check is to prevent them from hammering the providers on load ;)
        public void IntellisenseBoxDoesntQueryProvidersWhenTextLengthIsZero()
        {

            Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();
            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny<IntellisenseProviderContext>())).Verifiable();

            IntellisenseTextBox textBox = new IntellisenseTextBox();
            textBox.CreateVisualTree();
            textBox.IntellisenseProvider = intellisenseProvider.Object;
            textBox.Text = "";

            // Ensure the get results method is never called, mimics a initalize event from the design surface ;)
            intellisenseProvider.Verify(s => s.GetIntellisenseResults(It.IsAny<IntellisenseProviderContext>()), Times.Exactly(0));
        }
Example #15
0
        // This test is here for when the designers load. The check is to prevent them from hammering the providers on load ;)
        public void IntellisenseBoxDoesntQueryProvidersWhenTextLengthIsZero()
        {
            Mock <IIntellisenseProvider> intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>())).Verifiable();

            IntellisenseTextBox textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.IntellisenseProvider = intellisenseProvider.Object;
            textBox.Text = "";

            // Ensure the get results method is never called, mimics a initalize event from the design surface ;)
            intellisenseProvider.Verify(s => s.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()), Times.Exactly(0));
        }
Example #16
0
        public void IntellisenseBoxDoesntCrashWhenGettingResultsGivenAProviderThatThrowsAnException()
        {
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()))
            .Throws(new Exception());

            var textBox = new IntellisenseTextBox();

            textBox.IntellisenseProvider = intellisenseProvider.Object;
            textBox.Text = "[[City([[Scalar]]).Na";

            // When exceptions are thrown, no results are to be displayed
            Assert.AreEqual(0, textBox.View.Count);
        }
Example #17
0
        public void GivenJsonExpression_IntellisenseTextBox_AddBracketsToExpression_ShouldAddBrackets()
        {
            //------------Setup for test--------------------------
            var textBox = new IntellisenseTextBox
            {
                FilterType = enIntellisensePartType.JsonObject
                ,
                WrapInBrackets = true
            };
            //------------Execute Test---------------------------
            var bracketsToExpression = textBox.AddBracketsToExpression("Person");

            //------------Assert Results-------------------------
            Assert.IsNotNull(bracketsToExpression);
            Assert.AreEqual("[[@Person]]", bracketsToExpression);
        }
Example #18
0
        public void IntellisenseBox_GivenInvalidVariables_JsonObjectHasError_LogsTracking()
        {
            const string expectTooltipError = "Variable name \"[[obj!]]\" contains invalid character(s). Only use alphanumeric _ and - ";

            var textBoxTest = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.JsonObject
            };

            textBoxTest.Text = "\"[[obj!]]\"";

            var privateObj = new Warewolf.Testing.PrivateObject(textBoxTest);
            var results    = privateObj.Invoke("LostFocusImpl");

            Assert.IsTrue(textBoxTest.HasError);
            Assert.AreEqual(expectTooltipError, textBoxTest.ToolTip);
        }
Example #19
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsScalarsOnlyButTextIsRecordset_ToolTipHaErrorMessage()
        {
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()))
            .Returns(default(IList <IntellisenseProviderResult>));
            var textBox = new IntellisenseTextBox
            {
                FilterType           = enIntellisensePartType.ScalarsOnly,
                Text                 = "[[var()]]",
                IntellisenseProvider = intellisenseProvider.Object
            };

            textBox.EnsureIntellisenseResults("[[var()]]", false, IntellisenseDesiredResultSet.Default);
            Assert.IsTrue(textBox.HasError);
        }
        public void IntellisenseBoxDoesntCrashWhenGettingResultsGivenAProviderThatThrowsAnException()
        {
            Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();
            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny<IntellisenseProviderContext>()))
                                .Throws(new Exception());

            IntellisenseTextBox textBox = new IntellisenseTextBox();
            textBox.CreateVisualTree();
            textBox.IntellisenseProvider = intellisenseProvider.Object;
            textBox.Text = "[[City([[Scalar]]).Na";

            // When exceptions are thrown, no results are to be displayed
            Assert.AreEqual(0, textBox.Items.Count);
            //The desired result is that an exception isn't thrown


            // GetIntellisenseResults -> OnIntellisenseProviderChanged
        }
Example #21
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
        }
Example #22
0
        public void IntellisenseTextBoxTests_SetText_InvalidJsonArrayIndex_ShouldError()
        {
            var mockDataListViewModel = new Mock <IDataListViewModel>();

            mockDataListViewModel.Setup(model => model.Resource).Returns(new Mock <IResourceModel>().Object);
            DataListSingleton.SetDataList(mockDataListViewModel.Object);
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()))
            .Returns(default(IList <IntellisenseProviderResult>));

            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.JsonObject, IntellisenseProvider = intellisenseProvider.Object
            };

            textBox.Text = "[[@this.new(1).val(x).s]]";
            Assert.IsTrue(textBox.HasError);
            Assert.AreEqual("Variable name [[@this.new(1).val(x).s]] contains invalid character(s). Only use alphanumeric _ and - ", textBox.ToolTip.ToString());
        }
Example #23
0
        public void IntellisenseBoxDoesntCrashWhenGettingResultsGivenAProviderThatThrowsAnException()
        {
            Mock <IIntellisenseProvider> intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()))
            .Throws(new Exception());

            IntellisenseTextBox textBox = new IntellisenseTextBox();

            textBox.CreateVisualTree();
            textBox.IntellisenseProvider = intellisenseProvider.Object;
            textBox.Text = "[[City([[Scalar]]).Na";

            // When exceptions are thrown, no results are to be displayed
            Assert.AreEqual(0, textBox.Items.Count);
            //The desired result is that an exception isn't thrown


            // GetIntellisenseResults -> OnIntellisenseProviderChanged
        }
Example #24
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);
        }
Example #25
0
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsRecordsetFieldsButTextIsScalar_ToolTipHasErrorMessage()
        {
            var mockDataListViewModel = new Mock <IDataListViewModel>();

            mockDataListViewModel.Setup(model => model.Resource).Returns(new Mock <IResourceModel>().Object);
            DataListSingleton.SetDataList(mockDataListViewModel.Object);
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(a => a.GetIntellisenseResults(It.IsAny <IntellisenseProviderContext>()))
            .Returns(default(IList <IntellisenseProviderResult>));

            var textBox = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.RecordsetFields, IntellisenseProvider = intellisenseProvider.Object
            };

            textBox.Text = "[[var]]";
            textBox.EnsureIntellisenseResults("[[var]]", false, IntellisenseDesiredResultSet.Default);
            Assert.IsTrue(textBox.HasError);
        }
Example #26
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);
        }
Example #27
0
        public void IntellisenseTextBox_Text_NotLatinCharacter_ShowMessageBox_TextMadeEmpty()
        {
            //------------Setup for test--------------------------
            CustomContainer.DeRegister <IPopupController>();
            var mockPopupController = new Mock <IPopupController>();

            mockPopupController.Setup(controller => controller.ShowInvalidCharacterMessage(It.IsAny <string>()));
            CustomContainer.Register(mockPopupController.Object);
            var intellisenseProvider = new Mock <IIntellisenseProvider>();

            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(false);
            //------------Execute Test---------------------------
            var textBox = new IntellisenseTextBox();
            var checkHasUnicodeInText = textBox.CheckHasUnicodeInText("أَبْجَدِي");

            //------------Assert Results-------------------------
            Assert.IsTrue(checkHasUnicodeInText);
            Assert.AreEqual("", textBox.Text);
            mockPopupController.Verify(controller => controller.ShowInvalidCharacterMessage(It.IsAny <string>()), Times.AtLeastOnce());
        }
        public void IntellisenseBox_GivenInvalidVariables_JsonObjectHasError_LogsTracking()
        {
            var _applicationTrackerMock = new Mock <IApplicationTracker>();

            _applicationTrackerMock.Setup(controller => controller.TrackCustomEvent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
            CustomContainer.Register(_applicationTrackerMock.Object);

            const string expectTooltipError = "Variable name \"[[obj!]]\" contains invalid character(s). Only use alphanumeric _ and - ";

            var textBoxTest = new IntellisenseTextBox {
                FilterType = enIntellisensePartType.JsonObject
            };

            textBoxTest.Text = "\"[[obj!]]\"";

            var privateObj = new PrivateObject(textBoxTest);
            var results    = privateObj.Invoke("LostFocusImpl");

            Assert.IsTrue(textBoxTest.HasError);
            Assert.AreEqual(expectTooltipError, textBoxTest.ToolTip);
            _applicationTrackerMock.Verify(controller => controller.TrackCustomEvent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce());
        }
Example #29
0
        public void IntellisenseTextBox_Properties_Not_SetTo_Null()
        {
            //------------Setup for test--------------------------
            var textBox = new IntellisenseTextBox();

            //------------Execute Test---------------------------
            //------------Assert Results-------------------------
            Assert.IsNotNull(textBox.MinLines);
            Assert.IsNotNull(textBox.LineCount);
            Assert.IsNotNull(textBox.IsPaste);
            Assert.IsNotNull(textBox.IsInCalculateMode);
            Assert.IsNotNull(textBox.HorizontalScrollBarVisibility);
            Assert.IsNotNull(textBox.VerticalScrollBarVisibility);
            Assert.IsNotNull(textBox.TextWrapping);
            Assert.IsNotNull(textBox.AcceptsTab);
            Assert.IsNotNull(textBox.AcceptsReturn);
            Assert.IsNotNull(textBox.AllowMultipleVariables);
            Assert.IsNotNull(textBox.AllowMultilinePaste);
            Assert.IsNotNull(textBox.AllowUserCalculateMode);
            Assert.IsFalse(textBox.SelectAllOnGotFocus);
            Assert.IsTrue(textBox.IsUndoEnabled);
            Assert.IsFalse(textBox.HasError);
        }
        public void TextContaningNoTabIsPasedIntoAnIntellisenseTextBoxExpectedTabInsertedEventNotRaised()
        {
            var preserveClipboard = Clipboard.GetText();
            try
            {
                bool eventRaised = false;
                EventManager.RegisterClassHandler(typeof(IntellisenseTextBox), IntellisenseTextBox.TabInsertedEvent,
                                                  new RoutedEventHandler((s, e) =>
                                                      {
                                                          eventRaised = true;
                                                      }));

                Clipboard.SetText("Cake");

                IntellisenseTextBox textBox = new IntellisenseTextBox();
                textBox.CreateVisualTree();
                textBox.Paste();

                Assert.IsFalse(eventRaised,
                               "The 'IntellisenseTextBox.TabInsertedEvent' was raised when text that didn't contain a tab was pasted into the IntellisenseTextBox.");
            }
            finally
            {
                Clipboard.SetText(preserveClipboard);
            }

        }
 public void IntellisenseTextBoxTests_SetText_FilterTypeIsRecordsetFieldsAndTextIsRecordset_ToolTipHasNoErrorMessage()
 {
     var textBox = new IntellisenseTextBox { FilterType = enIntellisensePartType.RecordsetFields };
     textBox.EnsureIntellisenseResults("[[var()]]", false, IntellisenseDesiredResultSet.Default);
     Assert.IsFalse(textBox.HasError);
 }
 private static void RunWrappedKeyPress(Key key)
 {
     //------------Setup for test--------------------------
     var textBox = new IntellisenseTextBox { FilterType = enIntellisensePartType.RecordsetFields, WrapInBrackets = false, Text = "var()" };
     //------------Execute Test---------------------------
     textBox.HandleWrapInBrackets(key);
     //------------Assert Results-------------------------
     Assert.AreEqual("var()", textBox.Text);
 }
 public void IntellisenseTextBox_KeyDown_CannotCauseWrapInBrackets_WhenNotWrapInBrackets()
 {
     //------------Setup for test--------------------------
     var textBox = new IntellisenseTextBox { FilterType = enIntellisensePartType.RecordsetFields, WrapInBrackets = false, Text = "var()" };
     //------------Execute Test---------------------------
     textBox.HandleWrapInBrackets(Key.F6);
     //------------Assert Results-------------------------
     Assert.AreEqual("var()", textBox.Text);
 }
        public void InsertItemExpectedTextboxTextChanged_SpaceInFieldName_ErrorStatusUpdated()
        {
            const string ExpectedText = "[[City(). Name]]";
            Mock<IResourceModel> 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);
            Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();
            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(
                a => a.PerformResultInsertion(It.IsAny<string>(), It.IsAny<IntellisenseProviderContext>())).Returns(ExpectedText);

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

            IntellisenseTextBox 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 + " ]");
        }
        public void IntellisenseTextBoxTests_SetText_FilterTypeIsScalarsOnlyButTextIsRecordset_ToolTipHaErrorMessage()
        {
            var textBox = new IntellisenseTextBox { FilterType = enIntellisensePartType.ScalarsOnly };
            textBox.EnsureIntellisenseResults("[[var()]]", false, IntellisenseDesiredResultSet.Default);
            Assert.IsTrue(textBox.HasError);

        }
 public void IntellisenseTextBox_Text_NotLatinCharacter_ShowMessageBox_TextMadeEmpty()
 {
     //------------Setup for test--------------------------            
     CustomContainer.DeRegister<IPopupController>();
     var mockPopupController = new Mock<IPopupController>();
     mockPopupController.Setup(controller => controller.ShowInvalidCharacterMessage(It.IsAny<string>()));
     CustomContainer.Register(mockPopupController.Object);
     Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();
     intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(false);
     //------------Execute Test---------------------------
     IntellisenseTextBox textBox = new IntellisenseTextBox();
     textBox.CreateVisualTree();
     textBox.Text = "أَبْجَدِي";
     var checkHasUnicodeInText = textBox.CheckHasUnicodeInText(textBox.Text);
     //------------Assert Results-------------------------
     Assert.IsTrue(checkHasUnicodeInText);
     Assert.AreEqual("", textBox.Text);
     mockPopupController.Verify(controller => controller.ShowInvalidCharacterMessage(It.IsAny<string>()), Times.AtLeastOnce());
 }
        public void IntellisenseTextBox_InsertItem_InsertDateTimePartsIn_InsertsCorrectly()
        {
            //------------Setup for test--------------------------            
            Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();

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

            IntellisenseProviderResult intellisenseProviderResult =
                new IntellisenseProviderResult(intellisenseProvider.Object, "DW", "DW");
            //------------Execute Test---------------------------
            IntellisenseTextBox textBox = new IntellisenseTextBox();
            textBox.CreateVisualTree();
            textBox.IsOpen = true;
            textBox.Text = "d YY mm";
            textBox.CaretIndex = 1;
            textBox.InsertItem(intellisenseProviderResult, false);
            //------------Assert Results-------------------------
            Assert.AreEqual("DW YY mm", textBox.Text);
        }
        public void IntellisenseBoxDoesntCrashWhenInsertingResultsGivenAProviderThatThrowsAnException()
        {
            Mock<IIntellisenseProvider> 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);

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

            IntellisenseTextBox textBox = new IntellisenseTextBox();
            textBox.CreateVisualTree();
            textBox.InsertItem(intellisenseProviderResult, true);

            // When exepctions are thrown, no results are to be displayed
            Assert.AreEqual(0, textBox.Items.Count, "Expected [ 0 ] But got [ " + textBox.Items.Count + " ]");
            //The desired result is that an exception isn't thrown
        }
        public void DefaultIntellisenseProvider_UpdateIntellisenseMessage_IntellisenseTextBoxToolTipIsNull_ToolTipIsUpdated()
        {
            //------------Setup for test--------------------------
            var intellisenseTextBox = new IntellisenseTextBox(true);

            var context = new IntellisenseProviderContext
            {
                CaretPosition = 2,
                InputText = "[[",
                DesiredResultSet = IntellisenseDesiredResultSet.Default,
                FilterType = enIntellisensePartType.All,
                TextBox = intellisenseTextBox
            };

            var provider = new DefaultIntellisenseProvider();
            provider.GetIntellisenseResults(context);
            var toolTipBefore = intellisenseTextBox.ToolTip;

            //------------Execute Test---------------------------
            provider.Handle(new UpdateIntellisenseMessage());

            Assert.IsNull(toolTipBefore);
            Assert.IsNotNull(intellisenseTextBox.ToolTip);
        }
 public void IntellisenseTextBoxTests_HandlePasteMessageCallsEnsureIntellisenseResults()
 {
     var textBox = new IntellisenseTextBox { FilterType = enIntellisensePartType.RecordsetFields };
     Assert.IsFalse(textBox.HasError);
     textBox.Text = "[[var]]";
     textBox.Handle(new UpdateAllIntellisenseMessage());
     Assert.IsTrue(textBox.HasError);
 }
        public void TextContaningTabIsPasedIntoAnIntellisenseTextBoxExpectedTabInsertedEventIsRaised()
        {
            bool eventRaised = false;
            IntellisenseTextBox sender = null;
            EventManager.RegisterClassHandler(typeof(IntellisenseTextBox), IntellisenseTextBox.TabInsertedEvent,
                                              new RoutedEventHandler((s, e) =>
                                                  {
                                                      eventRaised = true;
                                                      sender = s as IntellisenseTextBox;
                                                  }));

            Clipboard.SetText("Cake\t");

            IntellisenseTextBox textBox = new IntellisenseTextBox();
            textBox.CreateVisualTree();

            textBox.Paste();

            Assert.IsTrue(eventRaised,
                          "The 'IntellisenseTextBox.TabInsertedEvent' wasn't raised when text containing a tab was pasted into the IntellisenseTextBox.");
            Assert.AreEqual(textBox, sender,
                            "The IntellisenseTextBox in which the text containg a tab was pasted was different from the one which raised teh event.");

        }
        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()";
            Mock<IIntellisenseProvider> intellisenseProvider = new Mock<IIntellisenseProvider>();
            intellisenseProvider.Setup(a => a.HandlesResultInsertion).Returns(true);
            intellisenseProvider.Setup(
                a => a.PerformResultInsertion(It.IsAny<string>(), It.IsAny<IntellisenseProviderContext>())).Returns(ExpectedText);

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

            IntellisenseTextBox 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 + " ]");
        }