Telerik Forums
JustMock Forum
1 answer
155 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
169 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
520 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
110 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
101 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
128 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
230 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
56 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
5 answers
121 views
public interface IFoo
{
    IBar GetBar(string x);
}
public interface IBar
{
    void DoBar(int x);
}
 
public class Tests
{
    [Fact]
    public void First()
    {
        var foo = Mock.Create<IFoo>();
 
        foo.GetBar("a").DoBar(1);
 
        Mock.Assert(() => foo.GetBar("b").DoBar(1));
    }
}

The above test passes, although it should fail.
Kaloyan
Telerik team
 answered on 06 Dec 2013
1 answer
99 views
I would like to use the JustMock Lite Nuget package for my solution as it makes dependency management easier. I also have the paid version so I can enable elevated mode.

My question is, if I install the full version onto my build server, but have the projects themselves referencing the JustMockLite Nuget package, will elevated mode still work?

Thanks.
Stefan
Telerik team
 answered on 03 Dec 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?