Created
January 22, 2013 14:18
-
-
Save fmork/4594951 to your computer and use it in GitHub Desktop.
I have this process which can be started and stopped. When started it will periodically perform some task, for which it will need to use an instance of another type that is created using some input, so it takes factory method as constructor input and it should invoke the factory each time it performs the task. In the test setting "periodically" …
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
public void Start_InvokesFactoryMethod() | |
{ | |
// Arrange | |
// set up mocks and stuff needed (removed for brevity) | |
bool testTimedOut; | |
using (AutoResetEvent waitHandle = new AutoResetEvent(false)) | |
{ | |
Func<ISomeResource, IMyObject> myObjectProvider = resource => | |
{ | |
waitHandle.Set(); | |
return new Mock<IMyObject>(); | |
}; | |
TypeThatIsTested instance = new TypeThatIsTested(myObjectProvider); | |
// Act | |
instance.Start(); | |
testTimedOut = !waitHandle.WaitOne(TimeSpan.FromSeconds(2)); | |
} | |
// Assert | |
Assert.IsFalse(testTimedOut, "Test timed out"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment