Approved
Last Updated: 14 Feb 2019 08:30 by ADMIN
Kim
Created on: 09 Feb 2019 11:28
Type: Feature Request
0
Mock.Raise fails for mocks created on other threads

Hi I have encountered what I think is a bug.

I would expected the following unit test to pass. It does not.

The example is distilled from a more complex case.

Is it not supported to have other threads create mocks?

[Fact] public async Task Fails() { var iTask = Task.Run(() => Mock.Create<I>()); var i = await iTask; EA expectedArgs = new EA(); EA receivedArgs = null; i.Done += (sender, ea) => receivedArgs = ea;

i.Raise(x => x.Done += null, expectedArgs); Assert.Equal(expectedArgs, receivedArgs); } public class EA : EventArgs { } public interface I { event EventHandler<EA> Done; }


3 comments
ADMIN
Mihail
Posted on: 14 Feb 2019 08:30
Hi Kim,

Thank you for the additional information it was useful.

Regarding your comment about whether this issue is a bug or a feature, JustMock is currently designed to handle scenarios where the test method and the creation of the mock objects are done in the same thread. The arrangement and the actual work could be on another thread, but not the execution of the test method and the creation of the mock object. This is why in our understanding this is a feature request.

Regards,
Mihail
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Kim
Posted on: 12 Feb 2019 14:59

Hi Mihail,

Thanks for you reply. 

I'm using it for acceptance testing, which means the entire system except some system boundaries are instanciated and some parts of the system are created on other threads. I was using NSubstitute before where this worked, but had another unrelated motivation for going towards JustMock.

I'm not sure I would agree completely with classifying it as a new feature rather than a bug. The behavior is not consistent.

For example, it works to create a mock on another thread and then arrange it.

 

ADMIN
Mihail
Posted on: 12 Feb 2019 11:22
Hello Kim,

JustMock does not support creating the mock object in a different thread. This is why I will change the type of this item to feature request.
Could you provide more detailed information on why your scenario requires the mock objects to be created in a separate thread? I am asking this so we can have a better understanding of your case when we start implementing it.

  
Regards,
Mihail
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items