Telerik Forums
JustMock Forum
19 answers
189 views
Hello,

I want to mock a large interface (~630 methods). The following line takes several minutes and several GBytes of memory:

Dim mJob As IJobInterface = Mock.Create(Of IJobInterface)()

Am I doing something wrong or is there another way to mock that object. I need this mock for every unit test so I need a faster way to do this.

Cheers
Stefan
Telerik team
 answered on 11 Feb 2014
10 answers
441 views
I'm trying to get JustMock working in an MSBuild unit test task. I keep getting the dreaded 'Profiler must be enabled' error.

It works in Visual Studio 2012 using the ReSharper test runner. xUnit.net is used as unit testing framework. I'm calling a .msbuild file, which looks like this:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMock.targets" />
 
    <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\packages\xunit.runners.1.9.1\tools\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
 
    <Target Name="Build">
        <JustMockStart />
        <xunit Assembly="bin\Release\WebshopNG.Tests.dll" />
        <JustMockStop />
    </Target>
</Project>

Superfluously, before calling msbuild.exe I set the following environment variables:

COR_ENABLE_PROFILING=0x1
COR_PROFILER={b7abe522-a68f-44f2-925b-81e7488e9ec0}

I keep getting the following error in the event log:

.NET Runtime version 4.0.30319.17929 - Loading profiler failed.  COR_PROFILER is set to an invalid CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'.  HRESULT: 0x800401f3.  Process ID (decimal): 5576.  Message ID: [0x2502].

I've tried re-registering the Telerik.CodeWeaver.Profiler.dlls, but that did nothing. Googling the error yields nothing concrete, so I'm at a loss where to start.
Kaloyan
Telerik team
 answered on 30 Jan 2014
1 answer
160 views
How can i set a behavior like strict to a special or all MockContainer's instances?

Kaloyan
Telerik team
 answered on 24 Jan 2014
1 answer
181 views
I asked this question on Stack Overflow initially, but I will come to the forums as SO is getting pretty noisy these days.

http://stackoverflow.com/questions/21268065/trying-to-unit-test-an-event-with-justmock (has example code)

Basically, all I want to do is be able to say '.DoNothing()' on an event.   Is this possible?  Is my syntax just bad?  Any tricks to get around it?

Thanks,
-Steve
Stefan
Telerik team
 answered on 22 Jan 2014
2 answers
546 views
I tried the following:

Mock.NonPublic.Arrange(StaticClass, "PrivatedMethod", Arg.IsAny<object>()).CallOriginal();

But as the Static class cannot be instantiated, I have to pass the class, never a variable and Arrange Syntax is not happy about it at all.

Is this intentional? I mean, Justmock does not tolerate mocking private method of static classes at all?

I've found two workarounds:
- Make the method public for temporary testing purposes.
- Make the static class singleton for temporary testing purposes.

This two workarounds are just fine for temporary testing but I cannot modify the class structure.

Any suggestion is welcomed.
David
Top achievements
Rank 1
 answered on 15 Jan 2014
1 answer
115 views
Hi, 

I am trying to Mock a static method from a class that is static too,

This static method calls another statics method of the same class,

example:

public static string MethodStaticA()
{
     
    return MethodStaticB();
}
public static string MethodStaticB()
{
    //Make something
}


For some reason when I try to Mock method A like this:

Mock.SetupStatic(typeof(MfsUtils));

Mock.Arrange(() => MfsUtils.MethodStaticA()).Returns("MyString");

I can see in the logs that actually is calling to MethodStaticB() and I do not want to call it

How can we properly  mock this??
Kaloyan
Telerik team
 answered on 08 Jan 2014
0 answers
109 views
  • Parallel test execution fails with NCrunch
    • At this stage JustMock does not support parallel test execution via NCrunch. To execute JustMock tests with NCrunch set the Allow Parallel Test Execution option to false within the solution or disable parallel execution on a global level by setting the Max number of processing threads setting to 1.
  • Debugging Azure application fails if IntelliTrace 2012 and JustMock are linked
    • Possible workaround is to clear the link between both the profilers from the JustMock Configuration window. More details here.
  • "Unable to obtain public key for StrongNameKeyPair" exception in non-elevated tests
    • Such exception may occur if the Crypto\RSA folder does not have Read & execute or List folder contents permissions. To fix this you need to set them manually. To find the folder use this path - %appdata%\Microsoft\Crypto\rsa. More details here.  
Telerik Admin
Top achievements
Rank 1
Iron
 asked on 02 Jan 2014
3 answers
140 views

I thought that MustBeCalled would fail on the Assert in the following situation but the test passes (note, no call is made to the "MustBeCalled" method). 

 

Public Class Foo

    Public Shared Sub Bar()

       Debug.Print("Wahoo!")

    End Sub

End Class

 <TestMethod()> _

 Public Sub Foo_Test()

     Mock.SetupStatic(GetType(Foo), Behavior.Strict)

     Mock.Arrange(Sub() Foo.Bar()).MustBeCalled()

     Mock.Assert(GetType(Foo))

 End Sub

 
I am using version 2013.3.1119.2 of JustMock in Visual Studio 2012 and I have verified that the Profiler is enabled. If I don't arrange the Foo.Bar call, the test fails, as expected because the behavior is set to Strict. Is there another way to do the Arrange or Assert so that this works as expected? 

Stefan
Telerik team
 answered on 01 Jan 2014
4 answers
243 views
An assertion on a mock where you use Args.Ignore() seems to ignore the extra "Occurs.Never()" condition i.e.

// Both of these pass
Mock.Assert(() => mock.Foo(null, null), Args.Ignore(), Occurs.Never());
Mock.Assert(() => mock.Foo(null, null), Args.Ignore());

If you remove the Args.Ignore() and explicitly specify the arguments, Occurs.Never() starts to actually be evaluated.
Kaloyan
Telerik team
 answered on 11 Dec 2013
1 answer
61 views

I have tried to use Just Mock with link expression that uses Update All and a Set statement but I keep getting the following error:

Source instance must be an OpenAccess LINQ expression, not an 'System.Linq.EnumerableQuery`1[[IveyCore.Member.MemberLogin, IveyCore, Version=2013.7.18.1916, Culture=neutral, PublicKeyToken=null]]'.

are there any examples of doing this?




Kaloyan
Telerik team
 answered on 06 Dec 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?