Telerik Forums
JustMock Forum
12 answers
122 views

The current version of Telerik JustMock Lite does not appear to be supported on the Windows 10 UWP (RTM) platform.

(1) Can you confirm if there is active work underway for JustMock Lite to support this platform?
(2) Can you provide an indication of the estimated release date? I’ll need to make a call to determine if we need to switch to a different mocking framework depending on these timelines.

Background info
Note that UWP (Universal Windows Platform) was referred to as UAP (Universal App Platform) before RTM was released. UWP is the correct term to use for the platform going forwards. Initial project development was on a Windows 10 Universal App (UAP) project in Visual Studio 2015 RC 14.0.22823.1 (Windows 8.1 OS). We can confirm that the mocking behaviour was working with these pre-release tools. After upgrading Windows and Visual Studio from Technical Preview (UAP) to RTM (UWP), we now experience warnings during build output and any tests with mocking behaviour no longer run (throws exception).

Product versions
Microsoft Windows 10 Professional - 10.0.10240.16384 RTM x64 (2015/07/15)
Microsoft Visual Studio 2015 - 14.0.23107.10 RTM (2015/07/10)
Telerik JustMock Lite - 2015.2.715.1 (2015/07/15)

Sample code snippet

1.[TestMethod]
2.public void ExampleTest()
3.{
4.    // This line throws an exception.
5.    var mockLogger = Mock.Create<ILogger>(Behavior.Loose);
6.}

Sample build warning output
C:\Program Files (x86)\Telerik\JustMock Lite\Libraries\Telerik.JustMock.dll : warning MSB3817: The assembly "C:\Program Files (x86)\Telerik\JustMock Lite\Libraries\Telerik.JustMock.dll" does not have a NeutralResourcesLanguageAttribute on it. To be used in an app package, portable libraries must define a NeutralResourcesLanguageAttribute on their main assembly (ie, the one containing code, not a satellite assembly).

Sample debug console output
Exception thrown: 'System.IO.FileLoadException' in MyProj.Win10.Tests.exe
An exception of type 'System.IO.FileLoadException' occurred in MyProj.Win10.Tests.exe but was not handled in user code
Additional information: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
HResult: -2146234304
Source: Telerik.JustMock
Stacktrace: at Telerik.JustMock.Mock.Create[T](Behavior behavior), at MyProj.Win10.ExampleTest()

 

Your feedback would be much appreciated.​ 

Thanks,
Davide

Svetlozar
Telerik team
 answered on 17 May 2016
7 answers
86 views
Hi,

I want to use JustMock Lite on Windows 10 SDK Preview:  Unit Test App - UAP.

"Install-Package : Could not install package 'JustMock 2015.1.224.3'. You are trying to install this package into a project that targets '.NETCore,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author."

Does anybody manage to re-build JustMock and use it in Win 10 Preview?

Thanks for support



Iana Tsolova
Telerik team
 answered on 04 Nov 2015
5 answers
100 views

Let's say I have a class

 

class MyClass
{
    public virtual void MyFunc1( DateTime somedate)
    {}

    public virtual void MyFunc2( )
    {
       MyFunc1(SomeObject.SentDate)

    }

}

where SomeObject has a field called SentDate.

SomeObject is in a global scope and, for some reasons, I can't provide a value for it so will always be null when mocking.

I can arrange for MyFunc1() to do whatever I want but, when I call MyFunc2(), it will try to evaluate its parameter SomeOject.SentDate and, because SomeObject is null, this will fail with an exception.

Is there a way to skip the evaluation of SomeObject.SentDate parameter?

Stefan
Telerik team
 answered on 12 Aug 2015
5 answers
89 views

 I have this code:

<p>using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
using Telerik.JustMock.Core;
  
  namespace TestMock1
{
    [TestClass] public class UnitTest1 {
         
[TestMethod]
        public void TestMethod1()
        { var mock = Mock.Create<Cls1>(); Mock.Arrange(() => mock.Func1()).Returns(2);
              mock.Func2();
        }
    }
  public class Cls1 { public Cls1()
        {
  
        }
  internal virtual int Func1()
        { int x = 1; return x;
        }
  internal virtual int Func2()
        { return Func1();
        }
  
    }
  
  
}​</p>

Florian
Top achievements
Rank 1
 answered on 07 Aug 2015
3 answers
52 views

Currently we are using JustMock Lite with xUnit 1.9.2 and have test cases where we create reusable mocks for our test methods within the controller of a test class. My team bumped into an issue after performing an upgrade to version 2.0. It appears when using the constructor to mock a method from a class (for reuse in test methods) and then creating a second mocked function within the test method (which is a different method from the same class that was defined in the constructor) causes the mocked implementation of the method in the constructor to disappear.

Please see the test example below. In the test class MockIssueExample, I have test methods that verifies the return value from an interface method or virtual function. In version 1.9.2, the mocks defined in SetupMocks() returns the value of 5 within each of the test methods. When I upgrade to version 2.0, each of the mocked methods returns a value of 0 in the test method and causes my test to fail.

Note: In each of the test methods I left a line of code that fixes the issue but it requires me to copy the mocked implementation from the constructor into the test method.Has something changed in 2.0 that's causing this scoping issue? Can we mock one function within a constructor and a second method within the actual test method without losing the mock implementation that what was defined in the constructor.

Please Advise. Thanks!

 public class MockIssueExample
{
private ITestMethods _testMethods;
private ClassUnderTest _classUnderTest;
private ClassTestMethods _classTestMethods;

public MockIssueExample()
{
SetupMocks();

_classUnderTest = new ClassUnderTest(_testMethods, _classTestMethods);
}

private void SetupMocks()
{
_testMethods = Mock.Create<ITestMethods>();
_classTestMethods = Mock.Create<ClassTestMethods>();

Mock.Arrange(() => _testMethods.FunctionReturnsInteger_1()).Returns(5);

Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_1()).Returns(5);
}

[Fact]
public void Virtual_function_1_should_return_the_mocked_value()
{
//Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_1()).Returns(5);
Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_2()).Returns(6);

int returnVal = _classUnderTest.GetValueReturnedFromVirtualFunction_1();

Assert.True(returnVal == 5);
}

[Fact]
public void Interface_function_1_should_return_the_mocked_value()
{
//Mock.Arrange(() => _testMethods.FunctionReturnsInteger_1()).Returns(5);
Mock.Arrange(() => _testMethods.FunctionReturnsInteger_2()).Returns(9);

int returnVal = _classUnderTest.GetValueReturnedFromInterfaceFunction_1();

Assert.True(returnVal == 5);
}
}

 

public interface ITestMethods
{
int FunctionReturnsInteger_1();
int FunctionReturnsInteger_2();
}

 

public class ClassTestMethods
{
public virtual int VirtualFunctionReturnsInteger_1()
{
return 1;
}

public virtual int VirtualFunctionReturnsInteger_2()
{
return 2;
}
}

public class ClassUnderTest
{
private readonly ITestMethods _testMethods;
private readonly ClassTestMethods _classTestMethods;

public ClassUnderTest(ITestMethods testMethods, ClassTestMethods classTestMethods)
{
_testMethods = testMethods;
_classTestMethods = classTestMethods;
}

public int GetValueReturnedFromVirtualFunction_1()
{
return _classTestMethods.VirtualFunctionReturnsInteger_1();
}

public int GetValueReturnedFromInterfaceFunction_1()
{
return _testMethods.FunctionReturnsInteger_1();
}
}

Stefan
Telerik team
 answered on 17 Jun 2015
2 answers
51 views
Hello, I grabbed this example from docs and added virtual modifier to ReturnFive function because free version can't mock not virtual members.
As far as I understand this modification shouldn't influence test results, though this test fails with  "Expected: 7  But was:  5"
I can't find any explicit statement in docs about future mock feature support in free version, so I'm not sure if it's my fault or this feature is just not available.
Any help would be appreciated.
       
public class UserData
        {
            public virtual int ReturnFive()
            {
                return 5;
            }
        }
        [Test]
        public void ShouldArrangeReturnForFutureUserDataInstances()
        {
            // Arrange
            var fakeUsed = Mock.Create<UserData>();
            Mock.Arrange(() => fakeUsed.ReturnFive()).IgnoreInstance().Returns(7);

            // Assert
            Assert.AreEqual(7, fakeUsed.ReturnFive());
            Assert.AreEqual(7, new UserData().ReturnFive());
        }
vsevolod
Top achievements
Rank 1
 answered on 04 Mar 2015
2 answers
439 views
I have been testing JustMock Lite as a replacement to RhinoMocks and converting some of our existing unit tests to learn the tool and asses if this is better.

I am using VB.NET, VS 2013 and .NET 4.

I came across this error after converting one particular unit test:

Result Message: System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
Result StackTrace:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.GetGenericArgumentsFor(MethodInfo genericMethod)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.InvocationTypeGenerator.GetCallbackMethod(AbstractTypeEmitter invocation)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.InvocationTypeGenerator.ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocation, ParameterInfo[] parameters, MethodEmitter invokeMethodOnTarget, Reference targetField)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.InvocationTypeGenerator.ImplemementInvokeMethodOnTarget(AbstractTypeEmitter invocation, ParameterInfo[] parameters, FieldReference targetField, MethodInfo callbackMethod)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.InvocationTypeGenerator.Generate(ClassEmitter class, ProxyGenerationOptions options, INamingScope namingScope)
at Telerik.JustMock.Core.Castle.DynamicProxy.Contributors.ClassProxyTargetContributor.BuildInvocationType(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options)
at Telerik.JustMock.Core.Castle.DynamicProxy.Contributors.ClassProxyTargetContributor.GetMethodGenerator(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
at Telerik.JustMock.Core.Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementMethod(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
at Telerik.JustMock.Core.Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1.<GenerateCode>b__0(String n, INamingScope s)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
at Telerik.JustMock.Core.Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
at Telerik.JustMock.Core.Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
at Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
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, Expression`1 interceptorFilter)
at Telerik.JustMock.Mock.<>c__DisplayClass78`1.<Create>b__77()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
at Telerik.JustMock.Mock.Create[T](Behavior behavior)
at ConsoleApplication1.TestClass1.Test() in Temporary Projects\ConsoleApplication1\Class1.vb:line 27


After some trial and error I found out what the issue is and the following code will reproduce the error. The issue is that the implementation of an interface function that has generics uses a different variable name for the types. In the example below the interface method has TParent and TChild but when implemented the generic types are called ParentT and ChildT.

Imports NUnit.Framework
Imports Telerik.JustMock

Public Class Class1
    Implements myInterface

    Public Function myMethod(Of ParentT, ChildT)(a As ParentT) As ChildT Implements myInterface.myMethod
        Return Nothing
    End Function
End Class

Public Interface myInterface
    Function myMethod(Of TParent, TChild)(a As TParent) As TChild
End Interface

<TestFixture> _
Public Class TestClass1
    <Test> Public Sub Test()
        Dim c As Class1
        c = Mock.Create(Of Class1)(Behavior.RecursiveLoose)
    End Sub
End Class


I assume this is a bug or do we need to be more careful in our coding? RhinoMocks is able to handle this okay.

Thanks,
Sameer
Stefan
Telerik team
 answered on 17 Feb 2015
5 answers
76 views
[TestFixture]
public class Class1
{
    public class Individual
    {
         
    }
    public class Family : Collection<Individual>
    {
         
    }
    public interface ITest
    {
        int Test(Family family);
    }
 
    [Test]
    public void Test()
    {
        var family1 = new Family();
        var family2 = new Family();
 
        var test = Mock.Create<ITest>();
        Mock.Arrange(() => test.Test(family1)).Returns(1).MustBeCalled();
        Mock.Arrange(() => test.Test(family2)).Returns(2).MustBeCalled();
 
        var result = test.Test(family1) + test.Test(family2);
 
        Mock.Assert(test);
    }
}
In the code as written I get an error:
Occurrence expectation failed. Expected at least 1 call. Calls so far: 0
Arrange expression: () => test.Test(family1).

However, when I change the code to not have Family based on Collection<Individual> it works.

This does not seem correct.  Is this a bug, or am I missing something on how JustMock is matching these parameters?

Eric Gurney
Stefan
Telerik team
 answered on 24 Jul 2014
5 answers
58 views
Greetings,

I downloaded JuckMocked, open the VB.NET solution, did a build and got a good deal of errors in various statements in regards to Lambda inline functions. Now I could go in and figure them out easily but I am not here for that but instead to evaluate this product hence my thread.

BTW: No issues with the C# solution.

Open with VS2012 Ultimate
Kaloyan
Telerik team
 answered on 18 Jul 2014
1 answer
84 views
I'm using Visual Studio 2013 MSTest
JustMock Lite 2014.2.609.3 (via NuGet)

I'm trying to move the "MustBeCalled" expectations to TestCleanup.
Here is an example of code.

01.[TestClass]
02.public class TestFixture
03.{
04.  private ICloneable _svc;
05. 
06.  [TestInitialize]
07.  public void TestSetup() { _svc = Mock.Create<ICloneable>(); }
08. 
09.  [TestCleanup]
10.  public void TestCleanup() { Mock.Assert(_svc); }
11. 
12.  [TestMethod]
13.  public void TryStuff()
14.  {
15.    // arrange
16.    _svc = Mock.Create<ICloneable>();
17.    Mock.Arrange(()=> _svc.Clone()).MustBeCalled();
18. 
19.    // act
20.    //_svc.Clone();
21. 
22.    // assert
23.  }
24.}

If I run the code as is, the test will pass (regardless if line 20 is commented or not).

This can be fixed by moving the Mock.Assert to line 22+ but ideally I would like to "auto call" Mock.Assert at the end of every test.  I thought that adding it to TestCleanup would work but it doesn't appear to do so.

It appears that prior to TestCleanup running, JustMock will clear out the expectations prior to running TestCleanup.
Is there anyway around this?

Why am I doing this?
Because I'd actually like to write tests like this.

01.public class TestFixture
02.{
03.  private List<object> _assertList = new List<object>();
04. 
05.  [TestCleanup]
06.  public void TestCleanup() { foreach (var svc in _assertList) { Mock.Assert(svc); } }
07.   
08.  private void CloneableMustBeCalled()
09.  {
10.    Mock.Arrange(() => _svc.Clone()).MustBeCalled();
11.    if (!_assertList.Contains(_svc)) { _assertList.Add(_svc); }
12.  }
13.}

Of course my actual test classes will be more complex. But this approach allows me to Mock out MustBeCalled expectations in a more readable manner.  Currently, the test author will have to remember to call Assert the _svc class (or _assertList) at the end of every TestMethod, but was hoping for a more maintainable solution.

Thanks
Stefan
Telerik team
 answered on 10 Jul 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?