views:

59

answers:

1

Any idea how we can assert a mock object was called when it is being accessed inside Parallel.ForEach via a closure? I assume that because each invocation is on a different thread that Rhino Mocks loses track of the object?

Pseudocode:

var someStub = MockRepository.GenerateStub()

Parallel.Foreach(collectionOfInts, anInt => someStub.DoSomething(anInt))

someStub.AssertWasCalled(s => s.DoSomething, Repeat.Five.Times)

This test will return an expectation violation, expecting the stub to be called 5 times but being actually called 0 times.

Any ideas how we can tell the lambdas to keep track of the thread-local stub object?

A: 

Ok well as a temporary measure, we've just abstracted the call to Parallel.ForEach away into another class...

jacko
In a way I suppose this is the right answer, otherwise we're just unit testing the Parallel Tasks Library, right?
jacko