Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar24-Apr-09 2:47
Nitin Jenekar24-Apr-09 2:47 
AnswerRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar20-May-09 0:35
Nitin Jenekar20-May-09 0:35 
QuestionERROR_FILE_NOT_FOUND while using GetUrlCacheEntryInfo() ? Pin
svt gdwl23-Apr-09 0:57
svt gdwl23-Apr-09 0:57 
QuestionNetwork Authority Pin
Programm3r22-Apr-09 23:50
Programm3r22-Apr-09 23:50 
Questionvsts 2008 unit testing Pin
BabyOreo22-Apr-09 22:44
BabyOreo22-Apr-09 22:44 
AnswerRe: vsts 2008 unit testing Pin
smurariu23-Apr-09 3:46
smurariu23-Apr-09 3:46 
GeneralRe: vsts 2008 unit testing [modified] Pin
BabyOreo23-Apr-09 21:04
BabyOreo23-Apr-09 21:04 
GeneralRe: vsts 2008 unit testing Pin
smurariu24-Apr-09 4:11
smurariu24-Apr-09 4:11 
User interface testing is a thorny subject to say the least. If you really want real in depth testing of your user interface then my advice to you is to head for model view controller pattern. That pattern's main goal is the separation of concerns between the three entities that give it its name.

More generally speaking you don't need a method to return some value in order to unit test it.


One possible way of asserting a result in your case would be to make a simple unit test that says if input key char is 13 then make sure that after the txtDate_KeyPress is called the txtMiles has focus.

then another unit test would asset that if the key char is between this and that, e.handled is true. or false.

the way you have it set up:

[Test Method]
public void txtDate_KeyPressTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
KeyPressEventArgs e = null; // TODO: Initialize to an appropriate value
target.txtDate_KeyPress(sender, e);
}


i would do something like this:

[Test Method]
public void txtDate_KeyPressTest_Enter()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)13);

//Act
target.txtDate_KeyPress(sender, args);

//Assert
Assert.IsTrue(target.txtMiles.Focused);

}

[Test Method]
public void txtDate_KeyPressTest_Number()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)50);

//Act
target.txtDate_KeyPress(sender, args);

//Assert
Assert.IsFalse(args.Handled);
}

...



etc.


also, consider using Char.IsDigit(e.KeyChar) instead of e.KeyChar >= '0' && e.KeyChar <= '9'. it's a bit more clear

Regards
GeneralRe: vsts 2008 unit testing Pin
BabyOreo26-Apr-09 22:47
BabyOreo26-Apr-09 22:47 
GeneralRe: vsts 2008 unit testing Pin
smurariu27-Apr-09 6:09
smurariu27-Apr-09 6:09 
GeneralRe: vsts 2008 unit testing Pin
BabyOreo28-Apr-09 17:35
BabyOreo28-Apr-09 17:35 
QuestionMachineKey configuration + Password recovery Pin
bonkers12322-Apr-09 22:38
bonkers12322-Apr-09 22:38 
AnswerRe: MachineKey configuration + Password recovery Pin
bonkers12322-Apr-09 23:32
bonkers12322-Apr-09 23:32 
Question[Message Deleted] Pin
mostafatajamolian22-Apr-09 22:36
mostafatajamolian22-Apr-09 22:36 
AnswerRe: replace text Pin
Eddy Vluggen22-Apr-09 22:47
professionalEddy Vluggen22-Apr-09 22:47 
AnswerRe: replace text Pin
Rob Philpott22-Apr-09 22:48
Rob Philpott22-Apr-09 22:48 
AnswerRe: replace text Pin
musefan22-Apr-09 23:33
musefan22-Apr-09 23:33 
AnswerRe: replace text Pin
OriginalGriff23-Apr-09 2:06
mveOriginalGriff23-Apr-09 2:06 
GeneralRe: replace text Pin
Eddy Vluggen23-Apr-09 6:19
professionalEddy Vluggen23-Apr-09 6:19 
JokeRe: replace text Pin
Guffa23-Apr-09 6:33
Guffa23-Apr-09 6:33 
GeneralRe: replace text Pin
OriginalGriff23-Apr-09 8:13
mveOriginalGriff23-Apr-09 8:13 
QuestionReading Data from Excel spreadsheet, unusual problem Pin
Member 436780422-Apr-09 22:15
Member 436780422-Apr-09 22:15 
AnswerRe: Reading Data from Excel spreadsheet, unusual problem Pin
Mycroft Holmes22-Apr-09 22:31
professionalMycroft Holmes22-Apr-09 22:31 
AnswerRe: Reading Data from Excel spreadsheet, unusual problem Pin
Natza Mitzi22-Apr-09 23:19
Natza Mitzi22-Apr-09 23:19 
Questionwhat does this error mean Pin
benson.misi22-Apr-09 21:45
benson.misi22-Apr-09 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.