Skip to content

Instantly share code, notes, and snippets.

@laurentkempe
Created November 20, 2012 10:07
Show Gist options
  • Save laurentkempe/4117094 to your computer and use it in GitHub Desktop.
Save laurentkempe/4117094 to your computer and use it in GitHub Desktop.
Using Thread.Sleep() in unit test! A good idea?
[Test]
public void Execute_ImportSuccessFulWithoutModifiedText_ExpectNoModelChangedMessageSent()
{
//Arrange
var importCommand = makeImportAllTextsCommand(new ImportStatistics {ImportedCount = 0});
var messageSent = false;
Messenger.Default.Register<ModelChangedMessage>(this, message => messageSent = true);
//Act
importCommand.Execute(null);
importCommand.TaskSUT.Wait();
//Assert
Assert.That(messageSent, Is.False);
}
private static ImportAllTextsCommandSUT makeImportAllTextsCommand(ImportStatistics importStatisticsToReturn)
{
var fileDialog = MockRepository.GenerateStub<IFileDialog>();
fileDialog.Stub(dialog => dialog.ShowOpenFileDialog(null)).IgnoreArguments().Return("c:\texts.xlsx");
var excelService = MockRepository.GenerateStub<IExcelService>();
excelService
.Stub(service => service.Import("c:\texts.xlsx"))
.IgnoreArguments()
.Return(importStatisticsToReturn);
var importCommand = new ImportAllTextsCommandSUT(excelService, fileDialog);
return importCommand;
}
private class ImportAllTextsCommandSUT : ImportAllTextsCommand
{
public ImportAllTextsCommandSUT(IExcelService excelService, IFileDialog fileDialog) : base(excelService, fileDialog)
{
}
public Task TaskSUT
{
get { return Task; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment