开发者

Mock Assertions on objects inside Parallel ForEach's?

开发者 https://www.devze.com 2022-12-30 20:11 出处:网络
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 开发者_运维知识

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消