There is a different behaviour when mocking the same method using the following two Arrange overrides: public static FuncExpectation<TResult> Arrange<TResult>(Expression<Func<TResult>> expression); public static FuncExpectation<TResult> Arrange<T, TResult>(T obj, Func<T, TResult> func); Repro project attached. Steps to reproduce: 1. Open attached solution 2. In Tests.cs, run JustMockArrangeQueryableTest - it passes 3. Run JustMockArrangeQueryableTest2 - it fails with a invalid cast exception on the Residents collection.
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.
Mocking an async calls alse triggers hidden mocking of the return type. Depending of the type it might cause unexpected behavior or exception.
A class property get wrongly mocked when used as parameter for arranging other class methods. The following sample demonstrates the scenario: class Foo { public string Prop{ get; set; } public void Bar(string val) { } } [TestMethod] public void Sample() { var sut = Mock.Create<Foo>(Behavior.CallOriginal); Mock.Arrange(() => sut.Bar(sut.Prop)).DoNothing(); }
Types that implement ISerializable can't be mocked anymore with the 2019.1.115.2 version resulting in System.ArgumentException. The issue is a regression compared to older versions of JustMock.
Example of such type is System.Reflection.Assembly.
The main point behind this request is to add new command line option to JustMockRunner in order to enable profiler without need for being registered, more details about this feature can be found on MSDN at https://msdn.microsoft.com/en-us/library/ee471451(v=vs.100).aspx
If there are more that one mock objects existing in the test, Mock.Assert wrongly succeeds while evaluating arrangements for each mock, but not the very first one. This is a regression compared to an older version from 2012. The following sample demonstrates the case: public interface IFoo { void Bar(); } [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { var bar = Mock.Create<IFoo>(); Mock.Arrange(() => bar.Bar()).OccursOnce(); var foo = Mock.Create<IFoo>(); Mock.Arrange(() => foo.Bar()).OccursOnce(); Mock.Assert(foo); // Would wrongly succeed Mock.Assert(bar); // Would fail as expected } }
Creating a share link with Visual Studio Live Share does not work if you have the JustMock profiler enabled. We specifically have to disable the JustMock profiler in order for VS Live Share to create sharing links. This has been reproduced by several different members of our team. Could this please be looked into? Thanks!
When using Mock.CreateLike<> we've found that trying to directly mock anything lower than two layers down on a concrete class (e.g. x => x.Layer1.Layer2.Property == "test") throws a NullReferenceException unless the profiler is enabled. It wasn't clear in the exception or the documentation relating to this method that the real issue was the profiler being disabled, and only by trial and error did we find the solution.
If I define a fluent API, I might have an interface such as this: public interface IRegistrar { IRegistrar UsingThis(object someThing); IRegistrar UsingThat<TThatThing>() } If I create a mock of this using the default Behaviour.RecursiveLoose and make no arrangements, calls to the methods will return new mocks of the type, rather than the same instance that was called. It would be nice to have a behaviour type that can return the same instance (in this case the mocked instance) without having to define a stub for each method call. My code under test might look like: IRegistrar reg; reg .UsingThis(new object()) .UsingThat<int>(); Currently, a test on the second call will fail if written against the mock assigned to 'reg'.
this nuts, forcing me to answer a dialog for JustMock and JustTrace to turn off sending usage to Telerik. Very poor UX. Stop doing this.
Resharper 10 code coverage have tests failing when arrange to have JustMock to return values from methods called under test. Perhaps one tool too many manipulating .NET objects behind-the-scenes at a time?