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!
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();
}
}
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);
}
}
}
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.
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);
}
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.
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.
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
We are trying to run unit tests via xUnit and mocking method occurence using JustMockLite. Method under arrange is creating a underlying Task however, once in a while test fails with following error
build 11-May-2021 14:36:09 Telerik.JustMock.Xunit.AssertFailedException : Multiple assertion failures: build 11-May-2021 14:36:09 1. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0 build 11-May-2021 14:36:09 Arrange expression: x => x.CallAsync(IsAny(), IsAny()) build 11-May-2021 14:36:09 2. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0 build 11-May-2021 14:36:09 Arrange expression: x => x.NotifyAsync(IsAny()) build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 ---- Telerik.JustMock.Diagnostics.DebugViewDetailsException : State: build 11-May-2021 14:36:09 Elevated mocking: disabled build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 Arrangements and expectations: build 11-May-2021 14:36:09 Arrangement (id=0) x => x.Load(IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [1, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=1) x => x.InitializePolicy(IsAny(), IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [1, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=2) x => x.RequestBulkSync(IsAny(), IsAny(), IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [any, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=3) x => x.CallAsync(IsAny(), IsAny()): build 11-May-2021 14:36:09 Unmet: Occurences must be in [1, 1]; calls so far: 0. build 11-May-2021 14:36:09 Arrangement (id=4) x => x.NotifyAsync(IsAny()): build 11-May-2021 14:36:09 Unmet: Occurences must be in [1, 1]; calls so far: 0. build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 Invocations:
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.