I'm working through Ron Jeffries's Extreme Programming Adventures in C#. His main example is a simple XML text editor. Given the age of the book (published in 2004), I suspected that a lot of his initial coding, finding what line the cursor is on and where the insertion point is, can be replaced with new TextBox methods or properties. I'm Visual Studio 2005. Trying to keep with the spirit of Agile development and XP, I wrote some tests first:
[Test]
public void TestGetFirstCharIndexOfCurrentLine() {
String[] newlines = new string[] { "<P>one</P>", "<P>two</P>" }; //TextLength == 20
notepad.txtbox.Lines = newlines;
Expect(notepad.txtbox.SelectionStart, EqualTo(20));
Expect(notepad.txtbox.GetFirstCharIndexOfCurrentLine(), EqualTo(11));
Expect(notepad.txtbox.GetLineFromCharIndex(11), EqualTo(1));
}
(I'm being lazy (erm... I mean I'm trying to save space). This code actually combines three tests that I actually run in separate methods.)
In any event, each of the tests fails. First, the txtbox.SelectionStart returns 0. This may be consistent with what the documentation suggests, but when I step through in debug, the value is 20. The other two tests yield similar results; a zero where I would expect a positive integer value. These latter two cases, in particular, do not comport with my reading of the documentation.
I would really appreciate a clue where I'm going wrong.
Thanks.