C# 8 introduces default interface method implementations. Attempt to mock such methods with JustMock in elevated mode fails. The following example illustrates the issue:
public interface IMyInterface
{
int IntProperty { get => 0; }
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var mock = Mock.Create<IMyInterface>();
Mock.Arrange(() => mock.IntProperty).Returns(1);
Assert.AreEqual(1, mock.IntProperty);
}
}
Currently, when the JustMock profiler is enabled it provides a performance hit on the test execution. This effect is expected because a profiler is involved.
What we can do is find a more optimized way of instrumenting the methods.
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;
}
Let's have the following class and unit test:
public delegate Task<int> SomeDelegate();
private async Task<int> DoSomeStuff()
{
await Task.Delay(100);
return 1;
}
}
// Assert
Mock.Assert(next);
Assert.AreEqual(3, sum);
}
JustMock public API lacks of convenient way to assert that particular task has been awaited. Potential workaround involves some "insider knowledge" that awaiting a Task internally results in a calls to some of its members.
Allow future mocking of an entire class, including a default of DoNothing() for all methods in the class, rather than requiring each method to be future mocked separately.
Currently, there is no out of the box support for passing "out" and "ref" parameters for nonpublic API.
Current behavior: Mock.Arrange(xxx).IgnoreInstance(); //mock all future instances of the type on which I set an expectation. Feature Request: Mock.Arrange(xxx).IgnoreInstance().Next(); //mock the next instance of the type on which I set an expectation. ...and even better... Mock.Arrange(xxx).IgnoreInstance().Skip(3).Next(); //mock the 4th instance of a type on which I set an expectation.