Created
November 20, 2012 10:07
-
-
Save laurentkempe/4117094 to your computer and use it in GitHub Desktop.
Using Thread.Sleep() in unit test! A good idea?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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