TextTextBox.cs


You might note an inconsistency in the coding style here. I used bool rather than Boolean. It would be better to be consistent, but in this case I fell short of that goal. You ll probably find other examples as you go through the book. They re part of my learning process, and I ll point them out when I notice them.

Also notice the commented-out code here. It s the result of an attempt to write a test that I later decided was a dead end. I should have had the courage to delete the code, but I must have decided to keep it in case I needed it. As far as I can tell from here, I never needed it. You can draw the obvious lesson from that and delete such things. Trust your code manager to keep a copy, or print the code and keep a big stack of paper in your bottom desk drawer .

 using System; 
using System.Windows.Forms;
using NUnit.Framework;
namespace Notepad
{
[TestFixture] public class TestTextBoxEvent : Assertion {
bool changed;
[SetUp] public void ClearChanged() {
changed = false;
}
[Test] public void CheckEvent() {
TestableTextBox text = new TestableTextBox();
text.Text = "some text";
Assert(!changed);
text.TextChanged += new EventHandler(Text_Changed);
text.Text = "more text";
Assert(changed);
}
// [Test] public void HookForm () {
// TestableTextBox text = new TestableTextBox();
// text.TextChanged += new EventHandler(Text_Changed);
// XMLNotepad xn = new XMLNotepad();
// xn.textbox = text;
// text.Text = "some text";
// xn.PutText();
// AssertEquals("hello", text.Lines[0]);
// Assert("changed flag", changed);
// }
void Text_Changed(object source, EventArgs args) {
changed = true;
}
}
}



Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net