Given: public abstract class Foo { } [Test] public void test_foo() { Mock.Create<Foo>(Behavior.Strict, Constructor.Mocked); } An exception is thrown at runtime saying "Abstract Type is not Accessible for Inheritance". This doesn't lead you to the actual problem which is that I accidentally swapped the Behavior and the Constructor in the parameter order. The same problem can occur if you attempt to call a constructor on an abstract object with the wrong number of parameters like so: public abstract class Foo { public Foo(int a, string b) { } } [Test] public void test_foo() { Mock.Create<Foo>(1, "foo", null); } This seems to be a problem with the compiler choosing the wrong overload to call and unfortunately there aren't a lot of solutions without changing the Create API. Perhaps having an alternative to Mock.Create that is more explicit that we can use to avoid typos leading to exceptions that are difficult to make sense of or a hint in the exception message that suggests what the root cause might be?
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 }
Hi there, I'm a developer on OzCode, a Visual Studio extension ( www.oz-code.com ). We've received some complaints from customers that OzCode is incompatible with JustCode. I installed JustMock, and saw that when Visual Studio starts up, JustMock it seems to be causing a crash in a child process that OzCode spawns off of devenv.exe, which is called 'BugAidMetadataLoader.exe': The exception in this process is: Additional information: Could not load type 'Telerik.JustMock.Profiler' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. I would guess that JustMock is unintentionally causing the process to be loaded with a CLR Profiler attached and injecting code into it, and the injected code causes the crash. Could you please provide some advice on how to avoid this, or possibly provide a fix? Thank you very much, - Omer Raviv, OzCode
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.
JustMock should work in multi-threaded scenarios.
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.
Make Justmock full edition as easy to use as the lite edition. For my team to use Justmock in Visual Studio and have unit tests run in the build system outside of VS, it is not practical to have justmock "installed" on everyone's machine. the process environment variables that need to be set is also not practically due to our custom build system; the process to start VS on our dev's enlistments is complicated and tightly controlled. Also, the profiler interferes with VS Code Coverage and we shouldn't have to use another UI to add the profiler, as that has to be done on every machine. We have to resort to just using JustMock Lite.
I have a unit test where I assert that a certain action will call a method on a mock dependency object by using Mock.Assert(). I want to ensure that the action I take calls the method on the mock object exactly once. The problem is that the setup of the unit test creates a scenario where the method of the mock object will also be called, so when I assert that the call to the mock object happened just once it fails because it has actually been called more than once. Is there a way to "reset" the call tracking of methods on mock objects? I basically want to tell JustMock that at a certain point, whatever calls have happened to my mock objects should be discarded and the call counter should basically start at 0 again.
I'm getting this argument exception: System.ArgumentException : The type or method has 3 generic parameter(s), but 2 generic argument(s) were provided. A generic argument must be provided for each generic parameter. at System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters) at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation) at ..(Type , MethodBase , BindingFlags ) at ..(Type , MethodBase ) at ..Create(Object , MethodInfo , Boolean ) at ..( ) at ..(Expression`1 ) at Telerik.JustMock.Mock..( ) at ..[,]( , Func`2 ) at Telerik.JustMock.Mock.Arrange[TResult](Expression`1 expression) Heres an example of a failing test: [Test] public void GenericTestCanMockTwoGenericMethods() { var mocked = Mock.Create<GenericTest>(); IEnumerable<EVENT_CODE> n = null; Mock.Arrange(() => mocked.Query<EVENT_CODE, ALARM_CODE>(Arg.AnyString, Arg.IsAny<object>())).Returns(n).MustBeCalled(); } public interface GenericTest { IEnumerable<T1> Query<T1, T2>(string arg1, params object[] args); IEnumerable<T1> Query<T1, T2, T3>(string arg1, params object[] args); }
I'd like to intercept a call to a generic method similar to: public class MyClass { public void MyMethod<T>() { // } } Now I want to arrange a MyClass instance so I can assert that the method has been call only once for an specific type and never for any other type. I'm tryig to do something similar to: var service = Mock.Create<MyClass>(); Mock.Arrange(() => service.MyMethod<T>()).OccursNever(); So I can assert the generic method is never called.
Using InOrder() in the arrange sometimes may be not appropriate. I would like to be able to do this in the assert. Instead of having the following workflow: //Arrange (initial conditions) // setup expected results (ordering) // Act // Assert , I will have this: //Arrange //Act // Assert (expected results in order)
"After struggling with TypeMock for an hour, I gave #JustMock a try and it works great! Thanks." https://twitter.com/JohnFecko/status/316211813761040384
JustMock should be able to mock in WP8 assemblies.
I have installed the trial version of JustMock to evaluate it. I have been trying to mock the static calls of Azure RoleEnvironment class, but the SetupStatic does not work. It seems to be calling the original method. Please see my simple test below: [Test] public void VerifyRoleEnvironment() { bool expected = true; Mock.SetupStatic(typeof(RoleEnvironment), StaticConstructor.Mocked); Mock.Arrange(() => RoleEnvironment.IsAvailable).Returns(true); Assert.AreEqual(expected, RoleEnvironment.IsAvailable); }
Please allow automocking support for classes with multiple constructors. This is important for projects not using DI containers but using dependency injection. A classic example is ASP.NET MVC and ASP.NET Web API where standard routing requires a constructor with no parameters. When using DI via constructors but without containers, the overloaded ctor specifies services/repositories and the default ctor passes the default services/repositories.
JustMock should be able to mock private methods in Silverlight.
Since JustMock Q1 2013 Mock.DoNotUseProfiler() is marked as an obsolete method and I cannot compile my test project. Revert it back.
By default JustMock matches the mock parameters via Object.ReferenceEquals(...). It would be nice to match the mock parameters via Object.Equals(...) as well. http://www.telerik.com/community/forums/justmock/general-discussions/parameter-matching.aspx
I use NCrunch, a popular test runner. But it cannot seem to activate the JustMock profiler properly. So tests that require use of the JustMock profiler do not work properly.
Should be able to arrange against non-public methods taking ref or out arguments as parameter.