Telerik Forums
JustMock Forum
3 answers
309 views

We use the commercial version of JustMock and are working on a new prototype. Along the way, somehow, my Mock.Arranges for one test class have stopped working.

These are tests for our Azure KeyVault Wrapper and are super simple.

            IKeyVault keyVault;

            [SetUp]
            public void SetUp()
            {
                var keyVaultClient = Mock.Create<IKeyVaultClient>();
                Mock.Arrange(() => keyVaultClient.GetSecretAsync("http://www.myKeyStore.com/Key1", new CancellationToken()))
                    .Returns(Task.FromResult(new SecretBundle { Value = "Secret1" }));

                Mock.Arrange(() => keyVaultClient.GetSecretAsync("http://www.myKeyStore.com/Key2", new CancellationToken()))
                    .Returns(Task.FromResult(default(SecretBundle)));

                keyVault = new KeyVault(keyVaultClient);
            }

            [Test]
            public async Task NewSecret_ShouldSucceed()
            {
                var secret = await keyVault.GetSecretAsync("Key1");

                Assert.AreEqual("Secret1", secret);
            }

            [Test]
            public async Task ShouldReturnNull_GetSecretAsync()
            {
                var secret = await keyVault.GetSecretAsync("Key2");

                Assert.AreEqual(null, secret);
            }

Both tests are returning SecretBundle objects with all default fields which seems to be an implementation from JustMock (not default(SecretBundle)). Neither have the correct values. The Arrange is simply not working.

I suspect this has something to do with references no longer being updated from Lite to Commercial, but I have no idea how to update them. The Update Reference button in the JustMock menu doesn't seem to do anything. 

Any help on how to troubleshoot would be much appreciated. We plan to depend heavily on JustMock for testing this project. Note that these tests, in their current form, were working just fine and the underlying code hasn't changed.

-Geoff

Ivo
Telerik team
 answered on 27 Jul 2018
5 answers
422 views

Not sure if this is an XUnit.Net or JustMock (or both) issue.  I have several tests on a solution that run and show passed but grayed out after a test run or build.  VS2017 shows "Unexpected error detected.  Check the Tests Output Pane for details.   The Test Output pane has a dump (see below).  The tests when run individually seem to pass and generate no errors, only when "Run All Tests" or as a result of a Build (run all tests after build set) do you see several tests grayed out.  It's always the same four tests.  Three have JustMock objects, one does not.

VS2017 Enterprise 15.2 (26430.12)

JustMock 2017.2.5303.3 (internal build to fix the 2017 profiler item)

This might be an internal build issue which is why I'm not logging it as a ticket, but thought I'd throw this in here to let you know about it.  

 

------ Run test started ------
[xUnit.net 00:00:00.2643557]   Discovering: UnitTests
[xUnit.net 00:00:01.0713800]   Discovered:  UnitTests
[xUnit.net 00:00:01.4834782]   Starting:    UnitTests
[xUnit.net 00:00:03.0127894]     [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:03.0171999]       System.ArgumentException : 'this' type cannot be an interface itself.
[xUnit.net 00:00:03.0198958]       Stack Trace:
[xUnit.net 00:00:03.0207009]        
[xUnit.net 00:00:03.0214322]         Server stack trace:
[xUnit.net 00:00:03.0221175]            at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle)
[xUnit.net 00:00:03.0227770]            at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
[xUnit.net 00:00:03.0232817]            at System.RuntimeType.GetInterfaceMap(Type ifaceType)
[xUnit.net 00:00:03.0239207]            at Telerik.JustMock.Core.MockingUtil.IsImplementedBy(MethodInfo interfaceMethod, MethodBase implMethod)
[xUnit.net 00:00:03.0243577]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.MatchTestClassDispose(MethodBase method, String[] testMethodAttributes)
[xUnit.net 00:00:03.0249418]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<>c__DisplayClass31.<SetupStandardHierarchicalTestStructure>b__1f(MethodBase method)
[xUnit.net 00:00:03.0255662]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<>c__DisplayClassa.<FindTestMethod>b__9(RepositoryOperationsBase repo)
[xUnit.net 00:00:03.0261179]            at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
[xUnit.net 00:00:03.0266557]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<FindTestMethod>b__8(MethodBase method)
[xUnit.net 00:00:03.0271733]            at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
[xUnit.net 00:00:03.0276714]            at System.Linq.Enumerable.<DistinctIterator>d__63`1.MoveNext()
[xUnit.net 00:00:03.0281930]            at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
[xUnit.net 00:00:03.0286994]            at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
[xUnit.net 00:00:03.0292425]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.FindTestMethod(Int32& repoIdx, RepositoryOperationsBase& entryOps)
[xUnit.net 00:00:03.0297270]            at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
[xUnit.net 00:00:03.0301511]            at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
[xUnit.net 00:00:03.0305562]            at Telerik.JustMock.Core.MocksRepository.GetMockMixin(Object obj, Type objType)
[xUnit.net 00:00:03.0309488]            at Telerik.JustMock.Core.Invocation..ctor(Object instance, MethodBase method, Object[] args)
[xUnit.net 00:00:03.0313652]            at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
[xUnit.net 00:00:03.0318462]            at System.MarshalByRefObject.GetIdentity(MarshalByRefObject obj, Boolean& fServer)
[xUnit.net 00:00:03.0323720]            at System.Runtime.Remoting.IdentityHolder.FindOrCreateServerIdentity(MarshalByRefObject obj, String objURI, Int32 flags)
[xUnit.net 00:00:03.0328321]            at System.Runtime.Remoting.RemotingServices.GetOrCreateIdentity(MarshalByRefObject Obj, String ObjURI, Boolean isInitializing)
[xUnit.net 00:00:03.0363414]            at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, Boolean updateChannelData, Boolean isInitializing)
[xUnit.net 00:00:03.0369562]            at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, Boolean updateChannelData)
[xUnit.net 00:00:03.0375367]            at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType)
[xUnit.net 00:00:03.0381086]            at System.Runtime.Remoting.Messaging.MessageSmuggler.FixupArg(Object arg, ArrayList& argsToSerialize)
[xUnit.net 00:00:03.0386417]            at System.Runtime.Remoting.Messaging.MessageSmuggler.FixupArgs(Object[] args, ArrayList& argsToSerialize)
[xUnit.net 00:00:03.0390906]            at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodCallMessage mcm)
[xUnit.net 00:00:03.0395394]            at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossible(IMessage msg)
[xUnit.net 00:00:03.0400477]            at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
[xUnit.net 00:00:03.0404910]        
[xUnit.net 00:00:03.0408806]         Exception rethrown at [0]:
[xUnit.net 00:00:03.0412930]            at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
[xUnit.net 00:00:03.0417710]            at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
[xUnit.net 00:00:03.0623429]     [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:03.0998317]     [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:04.3804395]   Finished:    UnitTests
========== Run test finished: 35 run (0:00:04.5228864) ==========
Mihail
Telerik team
 answered on 26 Jul 2018
5 answers
192 views

Hi,

I'm trying to generate a code coverage report using JetBrains dotCover and the JustMockRunner. I have the following batch file, which I plan to run on a schedule, which links dotCover, runs the coverage, and then unlinks dotCover.

1.start /wait "" "C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /link "dotCover"
2."dotCover.exe" cover "C:\Temp\Settings.xml"
3.start /wait "" "C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /unlink "dotCover"

 

The dotCover settings file has the following settings.

01.<?xml version="1.0" encoding="utf-8"?>
02.<AnalyseParams>
03.    <TargetExecutable>C:\JustMock\JustMockRunner.exe</TargetExecutable>
04.    <TargetArguments>"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" "C:\Temp\Release64\JustMock.Tests.dll" /noshadow /xml="C:\Temp\Coverage JustMock Test Results.xml"</TargetArguments>
05.    <Output>C:\Temp\Coverage Snapshot JustMock.dcvr</Output>
06.    <Scope>
07.        <ScopeEntry>C:\Temp\Release64\TestClass.dll</ScopeEntry>
08.    </Scope>
09.</AnalyseParams>

 

Everything seems to work correctly, with all tests passing, but I don't get any code coverage.

Have I missed something?

Mihail
Telerik team
 answered on 05 Jun 2018
1 answer
101 views

I'm attempting to update (not add) a record in a mocked DB and am not succeeding. I have a FakeDbEntries that is an IList<LogEntry>. I have Mocked my DbContext as

_mockLogRepo = Mock.Create<ILogRepo>();

_mockLogRepo.Arrange(m => m.LogEntries).ReturnsCollection(FakeDbEntries());

 

When I run the unit under test that calls the ILogRepo and does the update, the SaveChanges() never sticks.

Mihail
Telerik team
 answered on 08 May 2018
5 answers
184 views
I have installed JustMock free edition to work with some code another dev left behind him. No tests run, they all complain:
"There were some problems intercepting the mock call. Optionally, please make sure that you have turned on JustMock's profiler while mocking concrete members."

I need a DETAILED, PICTORIAL description of how to enable the profiler, because everything I see in these forums just says "oh, the solution is to enable the profiler." HOW? WHERE? I can read the message, but I see NOTHING that looks vaguely appropriate.

Is there supposed to be a JustMock menu? Button? Dancing bear? I've attached a screenshot, please diagnose what's going on. I've 

I've wasted an hour of time beating my head against this, and I'm extremely frustrated with it. Is the profiler not included with the Free edition?

Mihail
Telerik team
 answered on 26 Apr 2018
1 answer
114 views

There is one interface where when I try to mock it it throws an exceptions

System.IO.FileLoadException : Could not load file or assembly 'MyFramework, Version=2017.12.12.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required.

None of our projects are strong named, and my best guess is that it has something to do with the nature of the interface we're trying to mock. For simplicity sake I'll describe our project like this:

  • Processor --the project I'm actually testing
  • Processor.Tests --The project the tests are running from
  • MyFramework.Lib --The project that contains the interface (IMessageLogger) I'm trying to mock
  • MyFramework --internal dll that all projects reference

One of the methods in the IMessageLogger interface has an argument where the type is defined in the MyFramework project.

When I call Mock.Create<IMessageLogger>() I get the error above. My only thought is that because the Telerik.JustMock assembly is strong named, it is for some reason having trouble loading the MyFramework assemble even though it can miraculously load the MyFramework.Lib assembly.

I was wondering if there is any workaround I might be able to try so that I can mock this piece. I can live without mocking this specific interface, but I may not be so lucky with others...

Lyubomir Rusev
Telerik team
 answered on 04 Apr 2018
2 answers
145 views

Hello,

I'm trying to write a powershell script to run my tests, create code coverage using OpenCover and then generate a report using ReportGenerator.  However I'm running into the Profiler error:

The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
*  (from process environment)

 

This only happens when run from the powershell, if I run it from command line the tests run fine.  The command I am using is:

packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -mergebyhash -target:"%VS140COMNTOOLS%\..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"JustMockUnitTests\bin\x64\Debug\JustMockUnitTests.dll /InIsolation /platform:x64 /logger:trx /Parallel" -output:"OpenCover.xml"

 

Any thoughts would be much appreciated.

 

Thanks

-Steve

Steve
Top achievements
Rank 1
 answered on 18 Jan 2018
2 answers
68 views
Opened a question here regarding mocking the SQLConnection and looks like the post got removed. The question still comes up on search so what's going on admins?
Randy
Top achievements
Rank 1
 answered on 11 Jan 2018
1 answer
474 views

Is there any way to enable profiler in JetBrains Rider?

Mihail
Telerik team
 answered on 08 Jan 2018
6 answers
877 views

I have a scenario that I cannot seem to get working just like i would like.

 

I have been able to successfully write a test method against my private method just fine.

Now, I'm trying to write a test against my public method.  In the public method, i want to the call to the private method to be mocked and return a mocked value so the remainder code in my public method will handle that result.

However, when it comes time to execute the line of code in the public method that would call the private method, all that comes back is NULL.  I don't get my mocked value.

Here is my current test

var mockedClass = Mock.Create<JHADirectoryServiceAPI>(Constructor.Mocked);
 
var autoFix = new Fixture();
var otherPhoneDtoCollection_AM = autoFix.Create<IEnumerable<OtherPhoneDto>>();
  
var inst = new PrivateAccessor(mockedClass);
 
Mock.NonPublic.Arrange<IEnumerable<OtherPhoneDto>>(mockedClass, "GetOtherPhonesByOfficeID", Arg.AnyGuid)
                .DoInstead(()=> inst.CallMethod("GetOtherPhonesByOfficeID", Arg.AnyGuid)).ReturnsCollection(otherPhoneDtoCollection_AM);

Assume the below  code...

Public IEnumerable<Object> GetDetails(Guid value)
{
 
   //do some local stuff
    
   var result = GetOtherPhonesByOfficeID(value);
 
   //eval result
 
  return  myList
}
 
private  IEnumerable<OtherPhoneDto> GetOtherPhonesByOfficeID(Guid value)
{
  //Do some Stuff
 
  return myList;
}

Kammen
Telerik team
 answered on 24 Nov 2017
Narrow your results
Selected tags
Tags
+? more
Top users last month
Michael
Top achievements
Rank 2
Iron
Wilfred
Top achievements
Rank 1
Alexander
Top achievements
Rank 2
Iron
Iron
Matthew
Top achievements
Rank 1
Iron
ibra
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Michael
Top achievements
Rank 2
Iron
Wilfred
Top achievements
Rank 1
Alexander
Top achievements
Rank 2
Iron
Iron
Matthew
Top achievements
Rank 1
Iron
ibra
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?