Should be able to arrange against non-public methods taking ref or out arguments as parameter.
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); }
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.
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); }
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
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.
1. Load the attached project in Visual Studio 2013. 2. Update the NuGet packages (NUnit). 3. Update the reference to JustMock to point to the correct path to a retail version of Telerik.JustMock.dll. 4. Run tests in NUnit runner (or any other runner that will run them in the same process/sequentially. 5. --> Notice that the first TestCase will pass, the second will fail. 6. Run the two test cases separately. 7. --> Notice that they both pass. 8. Remove the reference to Telerik.JustMock.dll. 9. Use NuGet to get the latest JustMock Lite. 10. Run the tests again. 11. --> Notice that they both pass. This appears to be a bug with JustMock (retail) 2013.3.1119.2. The bug does not reproduce when using JustMock Lite from NuGet. If you drop into a debugger and step through both tests in a row you see the following behavior: 1. When the first test is started (after SetUp has been called) FlagA is correctly set to true and FlagB is defaulted to false. 2. When you step over the Mock.Arrange, FlagA is still true and FlagB is set to the value of input (order of running tests doesn't appear to matter, second always fails). 3. When the second test starts (after SetUp has been called again) Flag A is correctly set to true and FlagB is defaulted to false. 4. When you step over the Mock.Arrange, FlagB is set to the value of input but FlagA has been reverted to default! If you add several other properties to the interface they will all be reset to default (no matter how many you arrange) when the second test executes the Mock.Arrange. This bug reproduces without the JustMock profiler attached, and also with the profiler attached. The version of JustMock Lite that was tested against is 2014.1.1217.4. When I run the Telerik Control Panel I am not prompted to update my version of JustMock beyond 2013.3.1119.2 (perhaps this bug is already fixed and I just need to figure out how to upgrade).
If possible, update Microsoft.Practices.ServiceLocation to 1.2 or change NuGet package to > 1.0 instead of = 1.0.
Remove obfuscation of exceptions thrown by JustMock, because they can cause failing builds on Jenkins
I'd like to be able to intercept and arrange access to fields on any class. public class Dependency { public int A; } .. var dep = new Dependency(); Mock.Arrange(() => dep.A).Returns(5); Mock.ArrangeSet(() => dep.A = Arg.AnyInt).DoInstead(...);
Does Telerik JustMock work for Windows 8.1 environment? We have a solution targeting Windows 8.1. I haven't been able to use Telerik JustMock. Is there any workaround to make it work or some planned release for this framework. Best regards, Sebas
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?
I want to check the order of methode calls but InSequence() does not work for it.
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.
I have logging class which are using everywhere. I want to Mock this class for all tests. And i tried to use AssemblyInitialize but got problem. I have simulated this problem with JustMock.ElevatedExamples.AdvancedUsage examples: 1) Add BaseTest class [TestClass] public class BaseTest { [AssemblyInitialize()] public static void AssemblyInit(TestContext context) { Mock.SetupStatic(typeof(Common1), StaticConstructor.Mocked); // Arranging: When the static(Foo.FooProp_GET) property is called, it should return expected. var fakeUsed = Mock.Create<LogWriter1>(Constructor.Mocked); Mock.Arrange(() => Common1.Log).Returns(fakeUsed); } [AssemblyCleanup] public static void Cleanup() { //clean up stuff here } } public static class Common1 { static Common1() { Log = new LogWriter1(); } public static LogWriter1 Log { get; set; } } public class LogWriter1 { } 2) When run test from VS - all ok 3) When run from command line it is not working. Show Message box "Process Starts Now". SET JUSTMOCK_INSTANCE=1 SET COR_ENABLE_PROFILING=1 SET COR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0} "C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMockRunner.exe" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:"D:\test\CSExamples\JustMock.ElevatedExamples\bin\Debug\JustMock.ElevatedExamples.dll" How i can mock logger for all test? It is static public property. I use MS Test + VS 2015.
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'.
I am using Visual Studio 2015, Crystal Reports 12.0.2. When running from Visual Studio in debug mode or not, the application hangs on the statement "new ReportDocument()". ReportDocument is a class defined in CrystalReports. When I disabled the JustMock Profiler, this statement no longer hung. Just FYI. Hopefully others will see this.
Asynchronous test execution might be run in a separate thread (it depends of the environment and it is completely transparent) which causes arrangements to lose their context. That is why the expected mocked return value for DateTime.UtcNow calls the original code and finally the test fails.