Click here to Skip to main content
15,917,971 members
Home / Discussions / C#
   

C#

 
GeneralRe: Socket error on service stop [modified] Pin
Jacob D Dixon6-Nov-10 5:32
Jacob D Dixon6-Nov-10 5:32 
QuestionUnit testing Pin
Tichaona J5-Nov-10 7:51
Tichaona J5-Nov-10 7:51 
AnswerRe: Unit testing Pin
fjdiewornncalwe5-Nov-10 8:12
professionalfjdiewornncalwe5-Nov-10 8:12 
AnswerRe: Unit testing Pin
Dave Kreskowiak5-Nov-10 9:43
mveDave Kreskowiak5-Nov-10 9:43 
GeneralRe: Unit testing Pin
Tichaona J5-Nov-10 12:00
Tichaona J5-Nov-10 12:00 
GeneralRe: Unit testing Pin
Pete O'Hanlon5-Nov-10 12:07
mvePete O'Hanlon5-Nov-10 12:07 
GeneralRe: Unit testing Pin
Dave Kreskowiak5-Nov-10 14:08
mveDave Kreskowiak5-Nov-10 14:08 
AnswerRe: Unit testing Pin
David Ewen8-Nov-10 14:07
professionalDavid Ewen8-Nov-10 14:07 
As defined that method can not be unit tested as it requires user input (to select the file). But as you want an example on how to test a method that doesn't return a value it can be refactored slightly as below.

To test a method that returns void you test for the change in system state that the method call is meant to impose. In this case the listbox should contain 2 items after the call, granted testing if items were added to a listbox is of dubious benefit but this is just for illustrative purposes.

private void BtnLoad_Click(object sender, RoutedEventArgs e)
{
	//Declare a new file dialog box
	OpenFileDialog dlg = new OpenFileDialog();

	//Set properties for the dialog...
	dlg.Title = "Select one or more media files";
	dlg.Multiselect = IsEnabled;
	dlg.Filter = "Media files(*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv)|*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv|All files(*.*)|*.*";
	
	//The result of the open file dialog is either true or false (didn't work).
	Nullable<bool> result = dlg.ShowDialog();
	
	//If the result of the open file dialog was true then....
	if (result == true)
	{
		LoadFilesToListbox(dlg.FileNames);
	}
}

public void LoadFilesToListbox(string[] files)
{
	//Add each file into the list box
	foreach (string file in files)
	{
		lstBxList.Items.Add(file);
	}
}

[TestMethod]
public void TestLoadFilesToListbox()
{
	LoadFilesToListbox(new string[] { "file1.txt", file2.dat" });
	Assert.AreEqual(2, lstBxList.Items.Count);
}

QuestionBadly behaving COM object. Pin
jbradshaw5-Nov-10 3:12
jbradshaw5-Nov-10 3:12 
AnswerRe: Badly behaving COM object. Pin
OriginalGriff5-Nov-10 3:33
mveOriginalGriff5-Nov-10 3:33 
AnswerRe: Badly behaving COM object. Pin
Abhinav S5-Nov-10 3:36
Abhinav S5-Nov-10 3:36 
AnswerRe: Badly behaving COM object. Pin
_Erik_5-Nov-10 3:38
_Erik_5-Nov-10 3:38 
AnswerRe: Badly behaving COM object. Pin
Pete O'Hanlon5-Nov-10 3:43
mvePete O'Hanlon5-Nov-10 3:43 
QuestionWorking with own libaries Pin
neus835-Nov-10 2:28
neus835-Nov-10 2:28 
AnswerRe: Working with own libaries Pin
Abhinav S5-Nov-10 2:45
Abhinav S5-Nov-10 2:45 
AnswerRe: Working with own libaries Pin
Not Active5-Nov-10 2:47
mentorNot Active5-Nov-10 2:47 
AnswerRe: Working with own libaries Pin
_Erik_5-Nov-10 2:54
_Erik_5-Nov-10 2:54 
GeneralRe: Working with own libaries [modified] Pin
neus835-Nov-10 4:43
neus835-Nov-10 4:43 
GeneralRe: Working with own libaries Pin
_Erik_5-Nov-10 4:45
_Erik_5-Nov-10 4:45 
GeneralRe: Working with own libaries Pin
neus835-Nov-10 5:01
neus835-Nov-10 5:01 
JokeRe: Working with own libaries Pin
_Erik_5-Nov-10 5:06
_Erik_5-Nov-10 5:06 
GeneralRe: Working with own libaries Pin
Trollslayer6-Nov-10 1:07
mentorTrollslayer6-Nov-10 1:07 
QuestionExposing interfaces of a C# executable(.EXE) application Pin
Akt_4_U5-Nov-10 2:08
Akt_4_U5-Nov-10 2:08 
AnswerRe: Exposing interfaces of a C# executable(.EXE) application Pin
_Erik_5-Nov-10 2:16
_Erik_5-Nov-10 2:16 
GeneralRe: Exposing interfaces of a C# executable(.EXE) application Pin
Akt_4_U5-Nov-10 2:28
Akt_4_U5-Nov-10 2:28 

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.