The threading model of UI apps differs from the test host and this might become a source of issues like the following: System.InvalidOperationException: "The calling thread must be STA, because many UI components require this". The request is about extending JustMock with some helpers that can be used to solve this issue easily.
Allow the developer to create custom behaviors and use them in an arrangement. Something like the following:
Mock.Arrange(() => foo.CalcData(Arg.AnyInt, Arg.AnyInt), new IBehavior[]
{
new LogInvocation(),
new ReturnBaseOrDefaultValue(),
});
The new public API should allow the developer to access the invocations for a particular arrangement. Something like the following:
IEnumerable<IInvocaiton> invocations = foo.GetInvocationsFor((x) => x.CalcData(2, 2));
Implement a new public API that will allow the developer to iterate over all invocations of mock arrangements. Something like the following:
IEnumerable<IInvocaiton> invocations = Mock.Invocations;
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;
}