public void TextBoxBaseUiaTextProvider_LineCount_Get_ReturnsCorrectValue()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.Equal(1, provider.LinesCount);

            textBoxBase.Multiline = true;
            textBoxBase.Size      = new Size(30, 50);
            Assert.Equal(1, provider.LinesCount);

            textBoxBase.Text += "1\r\n";
            Assert.Equal(2, provider.LinesCount);

            textBoxBase.Text += "2\r\n";
            Assert.Equal(3, provider.LinesCount);

            textBoxBase.Text += "3\r\n";
            Assert.Equal(4, provider.LinesCount);

            textBoxBase.Text += "4\r\n";
            Assert.Equal(5, provider.LinesCount);

            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_IsScrollable_IsCorrect()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.True(provider.IsScrollable);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseAccessibleObject_Value_EqualsText()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            textBoxBase.Text = "Some test text";
            AccessibleObject accessibleObject = textBoxBase.AccessibilityObject;

            Assert.Equal(textBoxBase.Text, accessibleObject.Value);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_WindowExStyle_ReturnsCorrectValue()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);
            WS_EX actual = provider.WindowExStyle;

            Assert.Equal(WS_EX.CLIENTEDGE, actual);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetCaretRange_IsNotNull()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            UiaCore.ITextRangeProvider uiaTextRange = provider.GetCaretRange(out _);
            Assert.NotNull(uiaTextRange);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_IsReadingRTL_ReturnsCorrectValue(RightToLeft rightToLeft, bool expectedResult)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            textBoxBase.RightToLeft = rightToLeft;

            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.Equal(expectedResult, provider.IsReadingRTL);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseAccessibleObject_BoundingRectangle_IsCorrect(int width, int height)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase { Size = new Size(width, height) };
            textBoxBase.CreateControl();
            AccessibleObject accessibleObject = textBoxBase.AccessibilityObject;
            Rectangle        expected         = textBoxBase.RectangleToScreen(textBoxBase.ClientRectangle); // Forces Handle creating
            Rectangle        actual           = accessibleObject.BoundingRectangle;

            Assert.Equal(expected, actual);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_TextLength_ReturnsCorrectValue(string text)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase
                  {
                      Text = text
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.Equal(textBoxBase.Text.Length, provider.TextLength);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_EditStyle_ReturnsCorrectValue()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);
            ES actual = provider.EditStyle;

            Assert.True(actual.HasFlag(ES.LEFT));
            Assert.True(actual.HasFlag(ES.AUTOVSCROLL));
            Assert.True(actual.HasFlag(ES.AUTOHSCROLL));
            Assert.True(textBoxBase.IsHandleCreated);
        }
        [InlineData(30, 100, 6)] // Only 6 lines are placed at a height equal to 100
        public void TextBoxBaseUiaTextProvider_LinesPerPage_IsCorrect_with_handle(int width, int height, int lines)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase { Size = new Size(width, height) };
            textBoxBase.CreateControl();
            Assert.True(textBoxBase.IsHandleCreated);
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.Equal(1, provider.LinesPerPage);

            textBoxBase.Multiline = true;
            Assert.Equal(lines, provider.LinesPerPage);
        }
        public void TextBoxBaseUiaTextProvider_RangeFromPoint_DoesntThrowAnException(Point point)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            UiaTextRange textRangeProvider = provider.RangeFromPoint(point) as UiaTextRange;

            Assert.NotNull(textRangeProvider);

            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetVisibleRanges_ReturnsCorrectValue(Size size)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Text = "Some test text for testing",
                      Size = size
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.NotNull(provider.GetVisibleRanges());
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_Text_ReturnsCorrectValue(string text)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.Text = text;
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            textBoxBase.CreateControl();
            string expected = textBoxBase.Text;
            string actual   = provider.Text.Trim('\0');

            Assert.Equal(expected, actual);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetPositionFromCharForUpperRightCorner_ReturnsCorrectValue(Size size, string text, bool multiline, int charIndex, Point expectedPoint)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Size = size, Text = text, Multiline = multiline
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);
            Point actualPoint = provider.GetPositionFromCharForUpperRightCorner(charIndex, textBoxBase.Text);

            Assert.True(actualPoint.X >= expectedPoint.X - 1 || actualPoint.X <= expectedPoint.X + 1);
            Assert.True(actualPoint.Y >= expectedPoint.Y - 1 || actualPoint.Y <= expectedPoint.Y + 1);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetLineFromCharIndex_ReturnsCorrectValue(Size size, bool multiline, int charIndex, int expectedLine)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Size = size, Multiline = multiline
                  };
            textBoxBase.CreateControl();
            textBoxBase.Text = "Some test text for testing GetLineFromCharIndex method";
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);
            int actualLine = provider.GetLineFromCharIndex(charIndex);

            Assert.Equal(expectedLine, actualLine);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetFormattingRectangle_ReturnsCorrectValue(bool multiline, Size size, Rectangle expectedRectangle)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Size = size, Multiline = multiline
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Rectangle providerRectangle = provider.BoundingRectangle;

            Assert.Equal(expectedRectangle, providerRectangle);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_GetLogfont_ReturnsCorrectValue()
        {
            using (new NoAssertContext())
            {
                using TextBoxBase textBoxBase = new SubTextBoxBase();
                textBoxBase.CreateControl();
                TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

                LOGFONTW expected = LOGFONTW.FromFont(textBoxBase.Font);
                LOGFONTW actual   = provider.Logfont;
                Assert.False(string.IsNullOrEmpty(actual.FaceName.ToString()));
                Assert.Equal(expected, actual);
                Assert.True(textBoxBase.IsHandleCreated);
            }
        }
        public void TextBoxBaseUiaTextProvider_LineScroll_ReturnCorrectValue(int expectedLine)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase
                  {
                      Multiline = true,
                      Text      = "Some long long test text for testing GetFirstVisibleLine method",
                      Size      = new Size(50, 100)
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.True(provider.LineScroll(0, expectedLine));
            Assert.Equal(expectedLine, provider.FirstVisibleLine);
            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseAccessibleObject_ControlType_IsExpected_IfAccessibleRoleIsDefault(bool createControl, AccessibleRole expectedRole, int expectedType)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            // AccessibleRole is not set = Default

            if (createControl)
            {
                textBoxBase.CreateControl();
            }

            AccessibleObject accessibleObject = textBoxBase.AccessibilityObject;
            object           actual           = accessibleObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId);

            Assert.Equal(expectedRole, accessibleObject.Role);
            Assert.Equal((UiaCore.UIA)expectedType, actual);
            Assert.Equal(createControl, textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_FirstVisibleLine_Get_ReturnsCorrectValue()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.Multiline         = true;
            textBoxBase.Size = new Size(50, 100);
            textBoxBase.CreateControl();
            Assert.True(textBoxBase.IsHandleCreated);

            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            Assert.Equal(0, provider.FirstVisibleLine);

            provider.LineScroll(0, 2);
            Assert.Equal(0, provider.FirstVisibleLine);

            textBoxBase.Text = "Some long long test text for testing GetFirstVisibleLine method";
            provider.LineScroll(0, 2);
            Assert.Equal(2, provider.FirstVisibleLine);
        }
        public void TextBoxBaseUiaTextProvider_SetSelection_GetSelection_ReturnCorrectValue(int start, int end)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            textBoxBase.CreateControl();
            textBoxBase.Text = "Some test text for testing";
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            provider.SetSelection(start, end);
            UiaCore.ITextRangeProvider[] selection = provider.GetSelection();
            Assert.NotNull(selection);

            UiaTextRange textRange = selection[0] as UiaTextRange;

            Assert.NotNull(textRange);

            Assert.Equal(start, textRange.Start);
            Assert.Equal(end, textRange.End);

            Assert.True(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_SetSelection_DoesntSelectText_IfIncorrectArguments(int start, int end)
        {
            using (new NoAssertContext())
            {
                using TextBoxBase textBoxBase = new SubTextBoxBase();
                textBoxBase.CreateControl();
                textBoxBase.Text = "Some test text for testing";
                TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);
                provider.SetSelection(start, end);
                UiaCore.ITextRangeProvider[] selection = provider.GetSelection();
                Assert.NotNull(selection);

                UiaTextRange textRange = selection[0] as UiaTextRange;
                Assert.NotNull(textRange);

                Assert.Equal(0, textRange.Start);
                Assert.Equal(0, textRange.End);

                Assert.True(textBoxBase.IsHandleCreated);
            }
        }
        public void TextBoxBaseUiaTextProvider_GetVisibleRangePoints_ForSinglelineTextBox_ReturnsCorrectValue(Size size, int expectedStart, int expectedEnd)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Multiline = false,
                      Text      = "Some test text for testing",
                      Size      = size
                  };
            textBoxBase.CreateControl();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            provider.GetVisibleRangePoints(out int providerVisibleStart, out int providerVisibleEnd);

            Assert.True(providerVisibleStart >= 0);
            Assert.True(providerVisibleStart < textBoxBase.Text.Length);
            Assert.True(providerVisibleEnd >= 0);
            Assert.True(providerVisibleEnd <= textBoxBase.Text.Length);

            Assert.Equal(expectedStart, providerVisibleStart);
            Assert.Equal(expectedEnd, providerVisibleEnd);
            Assert.True(textBoxBase.IsHandleCreated);
        }