Hello,
lets say you needed your own Mutex class that accepts a WaitOne and
ReleaseMutex call.
Would you test it to make sure it works? As you have to use threads
you can never be sure that a passed test passed luckily or not.
The test class thought about looks like this:
[TestClass]
public class MutexWrapperTests
{
public interface ITwoMethods
{
void Open();
void Close();
}
[TestMethod]
public void MutexLockingObjectsCorrectly()
{
object lockingObject = new object();
var mocks = new MockRepository();
var criticalResource = mocks.DynamicMock<ITwoMethods>();
var uut = new MutexWrapper(lockingObject);
const int runs = 10;
const int threadCount = 15;
using (mocks.Ordered())
{
for (int x = 0; x < threadCount; x++)
{
for (int i = 0; i < runs; i++)
{
criticalResource.Open();
criticalResource.Close();
}
}
}
mocks.ReplayAll();
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++)
{
threads[i] = new Thread(
() =>
{
for (int x = 0; x < runs; x++)
{
uut.WaitOne();
criticalResource.Open();
criticalResource.Close();
uut.ReleaseMutex();
}
});
}
Array.ForEach(threads, t => t.Start());
Array.ForEach(threads, t => t.Join());
mocks.VerifyAll();
}
}
Do you think that is a little bit too much?
Kevin
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.