Skip to content

Instantly share code, notes, and snippets.

@fmork
Created January 22, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmork/4594951 to your computer and use it in GitHub Desktop.
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" …
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