JustMock should be able to mock private methods in Silverlight.
We have some mission critical code that catches all exceptions and recovers from them in various ways. I would like to be able to use Mock.Create<MyClass>(Behavior.Strict) so that I can know that none of the methods on MyClass are being called besides the ones I explicitly Mock.Arrange. However, this results in the methods throwing exceptions which are then caught by my application and recovered from so I never see them. I would like something like this, but where I didn't have to manually arrange every method on the class and instead have some Behavior that I could give to Mock.Create that would result in all of the arranges being auto-generated. I could then manually arrange anything I didn't want to have OccursNever on, just like you can override the exceptions thrown by Behavior.Strict. class MyClass { public void Method1() { } public void Method2() { } public void Method3() { } } class ClassUnderTest { public void DoSomething(MyClass myClass) { myClass.Method3(); } } [Test] void MyClass_methods_are_never_called() { // ARRANGE var myClass = Mock.Create<MyClass>(); Mock.Arrange(() => myClass.Method1()).OccursNever(); Mock.Arrange(() => myClass.Method2()).OccursNever(); Mock.Arrange(() => myClass.Method3()).OccursNever(); // ACT var classUnderTest = new ClassUnderTest(); classUnderTest.DoSomething(myClass); // ASSERT Mock.Assert(myClass); // this will fail }
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.
I want to be able to arrange the return value of `new` expressions, like Mock.Arrange(() => new FileInfo()).Returns(mockFileInfo). Then, I expect that `new FileInfo()` will always return my mock instance.
It would be good if we could use named parameters inside Mock.Arrange method.
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.
We're developing .net 5/core services, using Rider IDE and MacOS.
Please:
1. Add support to run JustMock under MacOS (profiler need to be supported, enabled issue, etc.), or if already supported, please provide instructions of how to activate it per test, for example using NUnit.
2. Add integration with Rider so all the process will be much easier.
I'd like to be able to make recursive arrangements like Mock.Arrange(() => a.B.C.D).Returns(5) and to simultaneously specify that this arrangement should work on any instance, not just 'a'. If I simply use IgnoreInstance() in this case it will make an arrangement for the instance on which 'D' is called and not 'B' - so it doesn't work as I want it to. What I'd like to do is simply state Mock.Arrange(() => Arg.IsAny<IFoo>().B.C.D).Returns(5) - in other words "Arrange for any object of type IFoo, when ".B.C.D" is called on it, that the value of D is 5.
I'm a user that is refactoring a legacy system which has a certain component to which I do not have the source. It uses COM interop heavily. I would like to be able to future-mock instances of RCW's so that I can write tests for that component.
Integrate with Simple Injector: https://simpleinjector.org/index.html similar to https://www.nuget.org/packages/JustMock.Unity and https://www.nuget.org/packages/JustMock.Mef/
eg // Act testSUT.Execute(1); // Assert myMockThing.Assert(x => x.Foo, Occurs.Once(), "calling Execute() with 1 should execute Foo due to blah");
My team and I have spotted some odd behaviour with the latest version of JustMock (2015.3.929.5) when targeting a Windows Store app. If we create a mock for an object in a helper method, the mock fails when making assertions for calls to the mock. The following code illustrates the issue: [TestMethod] public void ThisWillFail() { var subject = CreateSubject(); subject.DoSomething(); subject.Assert(s => s.DoSomething(), Occurs.Once()); } [TestMethod] public void ThisWillPass() { var subject = Mock.Create<ISubject>(); subject.DoSomething(); subject.Assert(s => s.DoSomething(), Occurs.Once()); } public interface ISubject { void DoSomething(); } private static ISubject CreateSubject() { return Mock.Create<ISubject>(); } In this code, the first test will fail but the second test will pass. The only difference is that, in the first test, we're setting up the mock in a helper method. We have a "Unit Test Library (.NET for Windows Store apps)" referencing the Telerik.JustMock assembly. I have attached a simple project containing this implementation. It's worth noting that the same code passes in a regular .NET class library; it only fails in a "Unit Test Library (.NET for Windows Store apps)". It's also worth noting that this worked under an older version of the assembly (2014.3.1021.2). Any help would be appreciated, as we currently have around 3,000 tests and a good proportion of them set up their mocks using a helper method in this way. Regards William Cowell
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.