Hi, Since I upgraded my JustMock I was unable to debug ASP.NET projects. I accidentally found a resolution to the problem here: http://stackoverflow.com/questions/19415275/asp-net-mvc4-code-not-running "If you are using Telerik JustMock as a mocking framework and have recently updated it to the 2013 Q3 version, it causes this exact problem. I was able to resolve this issue by uninstalling the mocking framework and installing the 2013 Q2 version." So I uninstalled JustMock and everything came to normal. Regards, Ovidiu
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!
Having the following COM interop class
[ClassInterface(ClassInterfaceType.None)]
[Guid("86332C4E-0BDE-46EC-94C5-0A946C33C682")]
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
public class MyComObjectClass : IMyComObject, MyComObject
{
public MyComObjectClass();
[DispId(1)]
public virtual string Echo(string message);
}
and the sample class that uses it:
public class MyComObjectClassProxy
{
public string Echo(string message)
{
IMyComObject itf = null;
try
{
itf = new MyComObjectClass();
return itf.Echo(message);
}
finally
{
if (itf != null)
{
Marshal.ReleaseComObject(itf);
}
}
}
}
When I try to call the arranged constructor I am getting an error "Cannot create instances of type requiring managed activation", the unit test code:
[TestMethod]
public void TestMethod1()
{
var mock = Mock.Create<MyComObjectClass>();
Mock.Arrange(() => new MyComObjectClass()).Returns(mock);
var sut = new MyComObjectClassProxy();
var actual = sut.Echo("Message");
Assert.AreEqual(string.Empty, actual);
}
When a breakpoint is added inside an async test that uses JustMock the debugger is failing to hit it.
To reproduce the issue follow the next steps:
1. Open the attached project
2. Create a breakpoint at the first arrangement in the async test method.
3. Start debugging the async test
Result: the breakpoint is not hit.
The issue is observed for both .NET Core and .NET Framework.
The internal (non-public) events are not handled properly by JustMock, there is no indication for error, Raise arrangement simply does not working as expected. The following sample reproduces the issue:
namespace TestExample
{
public class ClassWithEvents
{
internal event EventHandler<EventArgs> InternalEventToTest;
}
[TestClass()]
public class EventTests
{
[TestMethod]
public void ClassWithEvents_InternalEventTest()
{
//Arrange
bool eventRaised = false;
ClassWithEvents classWithEvents = Mock.Create<ClassWithEvents>();
classWithEvents.InternalEventToTest += (object sender, EventArgs e) =>
{
eventRaised = true;
};
// Act
Mock.Raise(() => classWithEvents.InternalEventToTest += null, new EventArgs());
// Assert
Assert.IsTrue(eventRaised);
}
}
}
if you use the C# using declaration and have JustMock advanced (elevated) mode enabled, the runtime will throw an InvalidProgramException.
Find below the sample code that demonstrates the issue:
public class TestClass : IDisposable
{
public void Dispose()
{
}
}
[TestClass]
public class Fixture
{
public interface ITest { }
[TestMethod]
public async Task Test()
{
ITest mock = Mock.Create<ITest>();
using TestClass test = new();
}
}
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.
Integration with Visual Studio Enterprise Code Coverage does not work if the project refers Microsoft.NET.Test.Sdk package version 16.3 (and above). The test run fails with exception:
Telerik.JustMock.Core.ElevatedMockingException : Cannot mock '<type to mock goes here>'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\amd64\covrun64.dll (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Restart the test runner and, if necessary, Visual Studio after linking.
With R3 2023 (2023.3.1011.155) JustMock introduces a new functionality that might lead to a huge performance drop and event to unexpected failures. Currently, the issue could be suppressed by setting up an environment variable JUSTMOCK_NEWOBJ_INTERCEPTION_ON_OVERWRITE_ENABLED to 0 (the default value is 1), but a more reliable and independent solution should be found.
Since JustMock Q1 2013 Mock.DoNotUseProfiler() is marked as an obsolete method and I cannot compile my test project. Revert it back.
using NUnit.Framework; using Telerik.JustMock; namespace Example { public class MyClass { public MyClass(int a = 5) { } } [TestFixture] public class TestMyClass { [Test] public void test_MyClass() { Mock.Create<MyClass>(Behavior.CallOriginal); } } } Telerik.JustMock.MockException : Can not instantiate proxy of class: Example.MyClass. Could not find a parameterless constructor. at Telerik.JustMock.Core.MocksRepository.Create(Type type, MockCreationSettings settings) at Telerik.JustMock.MockBuilder.Create(MocksRepository repository, Type type, Object[] constructorArgs, Nullable`1 behavior, Type[] additionalMockedInterfaces, Nullable`1 mockConstructorCall, IEnumerable`1 additionalProxyTypeAttributes, List`1 supplementaryBehaviors, List`1 fallbackBehaviors, List`1 mixins) at Telerik.JustMock.Mock.<>c__DisplayClass5b`1.<Create>b__5a() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction) at Telerik.JustMock.Mock.Create[T](Behavior behavior, Object[] args) at Example.TestMyClass.test_MyClass() in c:\users\micah\Documents\Source\Test\Test\Class1.cs:line 17#0 This appears to be related to the recent fix for "Improve exception message for Mock.Create". Without Behavior.CallOriginal it works. Supplying a parameter also works.
Tests fail when run with vstest.console.exe but pass when run from VS2015. Findings: The problematic scenario includes reference to Microsoft.WindowsAzure.ServiceRuntime.dll and usage of the RoleEnvironment class. When the RoleEnvironment class is used in a test project without JustMock and runned from vstest.console the exception will be thrown as well. Here is the exact exception: System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. ---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain. ---> System.Runtime.InteropServices.COMException: Invalid operation. (Exception from HRESULT: 0x80131022) Stack Trace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at <CrtImplementationDetails>.GetDefaultDomain() at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) --- End of inner exception stack trace --- at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) at .cctor() --- End of inner exception stack trace --- at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() --- End of inner exception stack trace --- at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable() Workaround: the vstest.console.exe could be started with parameter /InIsolation, which runs the tests in an isolated process. Here is the link to the command line options: https://msdn.microsoft.com/en-us/library/jj155796.aspx