A Bit More Cleanup


There were some helper methods that I modified, like this one:

 public void InsertPreTag() { 
InsertTags(Tags.Pre);
}

I d like to get rid of those, because they don t communicate much and they re complicating the interface to the TextModel. Let s see what s using these methods and what we can do about it. In this case, there s just one test:

 [Test] public void InsertPre() { 
model.SetLines (new String[1] {"<P></P>"});
model.SelectionStart = 7;
model.InsertPreTag();
AssertEquals("<pre></pre>", model.Lines[1]);
AssertEquals(14, model.SelectionStart);
model.InsertReturn();
AssertEquals("<pre>", model.Lines[1]);
AssertEquals("</pre>", model.Lines[2]);
AssertEquals(16, model.SelectionStart);
}

Simple enough. We can and should use our new method directly:

 [Test] public void InsertPre() { 
model.SetLines (new String[1] {"<P></P>"});
model.SelectionStart = 7;
model.InsertTags(TextModel.Tags.Pre);
AssertEquals("<pre></pre>", model.Lines[1]);
AssertEquals(14, model.SelectionStart);
model.InsertReturn();
AssertEquals("<pre>", model.Lines[1]);
AssertEquals("</pre>", model.Lines[2]);
AssertEquals(16, model.SelectionStart);
}

Let s remove the other helper methods similarly:

 public void InsertUnorderedList() { 
InsertTags(Tags.UnorderedList);
}
public void InsertListItemTag() {
InsertTags(Tags.ListItem);
}
public void InsertParagraphTag() {
InsertTags(Tags.Paragraph);
}

I do these each in the same way: I copy the operational line from the method, delete the method, compile, and see where the errors are. I paste the operational line over the offending call. A couple of the uses of the helpers were inside TextModel itself, and some were in the tests. It was a matter of a couple of minutes, with the help of the compiler. When everything compiled, the tests ran.




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