Пример #1
0
        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_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_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 TextBoxBaseUiaTextProvider_GetVisibleRangePoints_ReturnsZeros_WithoutHandle(Size size, int expectedStart, int expectedEnd)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Size = size
                  };
            textBoxBase.Text = "Some test text for testing";
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

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

            Assert.Equal(0, providerVisibleStart);
            Assert.Equal(0, providerVisibleEnd);
            Assert.False(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_GetLineIndex_ReturnsMinusOne_WithoutHandle(Size size, bool multiline, int lineIndex, int expectedIndex)
        {
            using SubTextBoxBase textBoxBase = new SubTextBoxBase()
                  {
                      Size      = size,
                      Multiline = multiline,
                      Text      = "Some test text for testing GetLineIndex method"
                  };
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            int actualIndex = provider.GetLineIndex(lineIndex);

            Assert.Equal(-1, actualIndex);
            Assert.False(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_LineScroll_DoesntWork_WitoutHandle(int expectedLine)
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase
                  {
                      Multiline = true,
                      Size      = new Size(50, 100)
                  };
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            textBoxBase.Text = "Some long long test text for testing GetFirstVisibleLine method";

            Assert.False(provider.LineScroll(0, expectedLine));
            Assert.Equal(-1, provider.FirstVisibleLine);
            Assert.False(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_LineCount_Get_ReturnsMinusOne_WithoutHandle()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            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(-1, provider.LinesCount);

            Assert.False(textBoxBase.IsHandleCreated);
        }
        public void TextBoxBaseUiaTextProvider_FirstVisibleLine_Get_ReturnsMinuOne_WithoutHandle()
        {
            using TextBoxBase textBoxBase = new SubTextBoxBase();
            TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase);

            int line = provider.FirstVisibleLine;

            Assert.Equal(-1, line);

            textBoxBase.Multiline = true;
            textBoxBase.Size      = new Size(30, 100);

            line = provider.FirstVisibleLine;
            Assert.Equal(-1, line);
            Assert.False(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);
        }
Пример #16
0
        private void SendCtrlBackspace(SubTextBoxBase tb)
        {
            var message = new Message();

            tb.ProcessCmdKey(ref message, Keys.Control | Keys.Back);
        }