Telerik Forums
JustMock Forum
4 answers
39 views

Hi,

I have been using Justmock for years now without any problem. But lately we started running as our normal users and not as local administrators on our PC's.

When installing Justmock I'm using an elevated admin account and it seems to complete without any errors, afterwards I'm starting VS19 as my normal user and are presented with the dialog shown in the attached file.

The log shows that the assembly could not be found or loaded, when looking in the folder specified in the error, I do not have an <extensions> folder at the location. So I assume that installing the product with my administrator access does not work for my normal user, what to do? 

The activity log shows the following error:

690 ERROR CreateInstance failed for package [JustMockPackage]Source: 'mscorlib' Description: Filen eller assemblyen 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll' eller en af dens afhængigheder kunne ikke indlæses. Den angivne fil blev ikke fundet. System.IO.FileNotFoundException: Filen eller assemblyen 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll' eller en af dens afhængigheder kunne ikke indlæses. Den angivne fil blev ikke fundet. File name: 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll'at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName) WRN: Logføring af assemblybinding er deaktiveret. Logføring af assemblybindingsfejl aktiveres ved at angive registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) til 1. Bemærk! Ydeevnen forringes ved logføring af assemblybindingsfejl. Denne funktion deaktiveres ved at fjerne registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog].  {0A72E70C-4C0C-4EF0-8212-59ACF681F885} 80004005 - E_FAIL VisualStudio 2020/11/05 06:41:35.043 

 

Mihail
Telerik team
 answered on 23 Nov 2020
1 answer
31 views

Hello!

I have an interesting problem I am trying to solve unit testing Sitecore. I have wrapped myController to get to a dynamic accessor and I am getting an exception way down in the mscorplib System.DefaultBinder. Looking for leads on what I am missing on my setup?

Exception: 

System.ArgumentException: Array may not be empty.
Parameter name: match

 

Code:

    var controllerAccessor = Mock.NonPublic.Wrap(_myController);

 

    Mock.NonPublic.Arrange<IMyParameters>(controllerAccessor.GetRenderingParameters<IMyParameters>()).Returns(_myParameters);

 

Stack trace:

   at System.DefaultBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, Object& state)
   at Telerik.JustMock.Core.MockingUtil.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo culture, String[] names, Object& state)
   at Telerik.JustMock.PrivateAccessor.ResolveProperty(Type type, String name, Boolean ignoreCase, Object[] indexArgs, Boolean hasInstance, Object setterValue, Boolean getter)
   at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.DoBindGetMember(Type returnType, String memberName, Boolean ignoreCase)
   at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
   at System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)

at <my code line Mock.NonPublic.Arrange<IMyParameters>(controllerAccessor.GetRenderingParameters<IMyParameters>()).Returns(_myParameters)> 

 

System.DefaultBinder code snippet:

// Decompiled with JetBrains decompiler
// Type: System.DefaultBinder
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: CACD6C6A-C61D-45CD-B58B-92E86EE53F52
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;

namespace System
{
  [Serializable]
  internal class DefaultBinder : Binder
  {
    [SecuritySafeCritical]
    public override MethodBase BindToMethod(
      BindingFlags bindingAttr,
      MethodBase[] match,
      ref object[] args,
      ParameterModifier[] modifiers,
      CultureInfo cultureInfo,
      string[] names,
      out object state)
    {
      MethodBase[] methodBaseArray = match != null && match.Length != 0 ? (MethodBase[]) match.Clone() : throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof (match));

etc etc 

}

Ivo
Telerik team
 answered on 20 Nov 2020
4 answers
75 views
Is there a way to mock non virtual public/protected methods? I see it's possible for private but not for protected and public.
Ivo
Telerik team
 answered on 16 Nov 2020
7 answers
312 views
In a couple of my tests, I want to prove that the calling code can handle a null being returned, but whenever I tell the Returns method to return null, I get an instance of the returned type.

So for example lets says I have a method signature like:

public interface ExampleInterface
{
IList<IBob> GetMeAllTheBobs(ISomeParameter someParameter)
}

When I mock like so:

var stubExampleClass = Mock.Create<IExampleClass>();
Mock.Arrange(() => stubExampleClass.GetMeAllThyeBobs(Arg.Any<ISomeParameter>()).Returns(null);

I will get an instance of IList<IBob> back instead of null.

Any suggestions?
Ivo
Telerik team
 answered on 06 Oct 2020
3 answers
35 views
Visual Studio Professional 2019 16.6.5
JustMock 2020.2.616.1
.Net Core 3.1

How can I mock an interface with default implementations? The following test fails:

using Telerik.JustMock;
using Xunit;
 
namespace XUnitTestProject1
{
    public interface IMyInterface
    {
        bool SomeCheck() => false;
    }
 
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            var mock = Mock.Create<IMyInterface>();
            Mock.Arrange(() => mock.SomeCheck()).Returns(true);
 
            Assert.True(mock.SomeCheck());
        }
    }
}

Ivo
Telerik team
 answered on 21 Sep 2020
2 answers
15 views
Was looking for ways to pull the lambda expressions I mock up....this way I could reuse them during the assertion portion of my test.

However when I pass the value in via a variable I get a test exception:
Telerik.JustMock.Core.MockException: The arranged function is not set up to return a value of type Account


Here is a sanitized version of what I'm trying to do?


public Interface IAccountManagement{
   public Account GetAccount(string acctId);
}
........

public void MyTest()
{
   IAccountManagement actMgrMock = Mock.Create<IAccountManagement>();
   Account acct = TestHelpers.AutoGenerateAccount;  //generate an acct object with Ploeh.AutoFixture

   Expression<Action> GetAccount = () => actMgrMock.GetAccount(Arg.IsAny<string>());

  //Mock.Arrange(GetAccount).Returns(e);   //<------this call will not work when I invoke the test?

  Mock.Arrange(() => actMgrMock.GetAccount(Arg.IsAny<string>())).Returns(e); //  This one works?

  // invoke
  
  //Assert
  //Mock.Assert(GetAccount,Occurs.Once());

}
  


Ivo
Telerik team
 answered on 21 Sep 2020
4 answers
37 views

Both Azure Storage Emulator and JustMock use port 10001 and 10002 as default ports.

Is it possible to change the ports JustMock uses?

Mark
Top achievements
Rank 1
 answered on 13 Aug 2020
2 answers
116 views

Visual Studio Professional 2019 - version 16.6.3

JustMock 2019.1.115.2 (Commercial version)

My solution has 3000+ unit tests and suddenly, 1000+ tests failed with the error :

 Message: 
    Test method Cloee2.Ws.UnitTests.Services.Business.TestConditionsAdmissionSe2.GetClasseGeneriqueNulle threw exception: 
    Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'Ch.Ne.Ceg.Cloee2.Services.CrudCloee2Helper'. The profiler must be enabled to mock, arrange or execute the specified target.
  Stack Trace: 
    ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
    MocksRepository.InterceptStatics(Type type, MockCreationSettings settings, Boolean mockStaticConstructor)
    MocksRepository.ConvertExpressionToCallPattern(Expression expr, CallPattern callPattern)
    MocksRepository.Arrange[TMethodMock](Expression expr, Func`1 methodMockFactory)
    ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
    TestConditionsAdmissionSe2._arrangeSearchFormations() line 523
    TestConditionsAdmissionSe2._mockGetClasseGenerique() line 913
    TestConditionsAdmissionSe2.GetClasseGeneriqueNulle() line 987

They pass in debug, but not in run.

I try to clear bin and obj folder of my solution, but nothing to do.

Any idea ?

Ivo
Telerik team
 answered on 08 Jul 2020
5 answers
73 views

Hi,

I'm using JustMock to mock SharePoint objects in some Unit Tests. When I run Unit Tests (I use ReSharper as test runner) and the JustMock profiler is enabled, the unit tests are much slower. Normally, one Unit test runs within seconds. With the JustMock profiler enabled, I have to wait several minutes. Is there something I can do to accelerate this?

 

Thank you very much!

 

Mihail
Telerik team
 answered on 12 Jun 2020
9 answers
897 views
I have the following in a test (my first ever JustMock test, I might add)...

var template = Mock.Create<MessageType>
Mock.Arrange(() => template.Subject).Returns("This template has Zero tokens.");
Mock.Arrange(() => template.Body).Returns("This template has {{number}} of {{tokens}}.");


The class being Mocked looks like this ...

public class MessageType : BaseBusinessEntity
{
    public string Body { get; set;}
    public int DigestsToBeIncludedOn { get; set; }
    public Guid MessageReference { get; set; }
    public int MessageTypeId { get; set; }
    public string Name { get; set; }
    public int PredefinedRecipients { get; set; }
    public string Subject { get; set; }
}

When I attempt to run the test I get ...

> Error Message: Test method
> Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens
> threw exception:  Telerik.JustMock.Core.ElevatedMockingException:
> Cannot mock 'System.String get_Subject()'. The profiler must be
> enabled to mock, arrange or execute the specified target. Stacktrace: 
> at
> Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo
> member)  at
> Telerik.JustMock.Core.MocksRepository.CheckMethodInterceptorAvailable(IMatcher
> instanceMatcher, MethodBase method)  at
> Telerik.JustMock.Core.MocksRepository.AddArrange(IMethodMock
> methodMock)  at
> Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression
> expr, Func`1 methodMockFactory)  at
> Telerik.JustMock.Mock.<>c__DisplayClass8`1.<Arrange>b__6()  at
> Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1
> guardedAction)  at Telerik.JustMock.Mock.Arrange[TResult](Expression`1
> expression)  at
> Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens()
> in
> c:\Genesis\Development\Genesis.Service.Implementation.Tests\DigestFixture.cs:line
> 46

Can anyone point out what I've done wrong?
Rafael
Top achievements
Rank 2
 answered on 18 May 2020
Narrow your results
Selected tags
Tags
+? more
Top users last month
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Liu
Top achievements
Rank 1
Iron
Alex
Top achievements
Rank 1
Veteran
Iron
Iron
George C.
Top achievements
Rank 2
Iron
Veteran
Top users last month
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Liu
Top achievements
Rank 1
Iron
Alex
Top achievements
Rank 1
Veteran
Iron
Iron
George C.
Top achievements
Rank 2
Iron
Veteran