Telerik Forums
JustMock Forum
10 answers
223 views
Hi,

I've need to mock some calls made on a concrete object.

In the beta it was working fine, but I've now upgraded to RTM and the code I wrote to mock out the call is no longer being mocked.  I'm mocking the object like so:

MyConcreteObject stubConcreteObject = Mock.Create<MyConcreteObject>(Behavior.Strict);

And arranging like so:

Mock.Arrange(() => stubConcreteObject.ContainsSomthing(Arg.IsAny<ISomething>())).Returns(true);

But when I run my code (I've tried with the explicit behaviour being set and not setting it), it always goes into the actual code.  This was working in the beta, but appears to be broken now.

Thanks,
John
Ricky
Telerik team
 answered on 29 Jul 2010
1 answer
99 views
I've had to downgrade back to the previous Beta, and now when ever I try doing anything with a mocked concrete I get the MockException "Opps , there were some error intercepting target call."

I've checked the registry, and no lingering JustMock references that I can see in there.  I've also deleted EVERY JustMock dll I can find, but to no avail.

StackTrace:

   at Telerik.JustMock.Expectations.Expectation.(Invocation invocation)
   at Telerik.JustMock.Expectations.Expectation.Process(Invocation invocation)
   at Telerik.JustMock.Mock...( x)
   at ..[TDelgate,TReturn](† instruction, Func2`2 function)
   at Telerik.JustMock.Mock.Arrange(Expression`1 expression)
   at MYTEST in Tests.cs:line 301

What am I missing?
Imaji
Top achievements
Rank 1
 answered on 28 Jul 2010
3 answers
108 views
Hi,

I try to use the mocking framework with visual basic and I try to figure it out what is the best manner to fake a method.

When I try to fake a function, the syntaxe is very nice like this:

      <Test()> _
      Public Sub TestDelete()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(Function() fileManager.Delete(Arg.AnyString)).Returns(False)

         Assert.IsTrue(fileManager.Delete(""))
      End Sub

As you can see, the keyword "Function()" is use and when I call the "Delete" function of the FileManager, I have a full support with intellisense to define possibles values of each arguments.

The problem is when I try to fake a method because I don't know how to call Arrange correctly except with the keyword "AddressOf". The problem with "AddressOf" is that I don't have a full support with intellisense and i'm limited with 9 parameters.

      <Test()> _
      Public Sub TestCreate()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(AddressOf fileManager.Create, Arg.AnyString)

         Mock.Assert(AddressOf fileManager.Create, Arg.AnyString, Occurs.Once)
      End Sub

I have full of legacy applications where many methods have more then 9 parameters. Any ways, I don't have full support with Intellisense.

I want to be able to fake a method like this:

      <Test()> _
      Public Sub TestCreate()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(function() fileManager.Create(Arg.AnyString))

         Mock.Assert(function() fileManager.Create(Arg.AnyString) Occurs.Once)
      End Sub

Is there any way to fake method like a function with Visual Basic... with the "Function()" keyword?

Thank you very much
Ricky
Telerik team
 answered on 23 Jul 2010
7 answers
207 views
I'm working on a test case against a static method that makes a few calls on an object, and I'm trying to make those calls do nothing.  The issue I'm having is that this:

TransactionHeaderViewModel

 

ticket = Mock.Create<TransactionHeaderViewModel>();

 


fails with the following:
Test method POSUnitTests.TransactionServiceTest.SaveTransactionTest threw exception:  System.NullReferenceException: Object reference not set to an instance of an object..

Telerik.JustMock.DynamicProxy.MethodInvocation.Continue() in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\MethodInvocation.cs: line 150
Intercept(IInvocation invocation) in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Interceptors\ProxyInterceptor.cs: line 35
TransactionHeaderViewModel_Proxy_a39192a5eca04cbbb79efb55f2387785.GetHashCode(MethodInvocation , Int32 , Boolean )
TransactionHeaderViewModel_Proxy_a39192a5eca04cbbb79efb55f2387785.GetHashCode()
get_Instance() in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\MockObject.cs: line 44
Telerik.JustMock.Mock.Create(Type target, BehaviorMode mode, Object[] args) in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs: line 354
Telerik.JustMock.Mock.Create(Type target, Object[] args) in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs: line 339
Telerik.JustMock.Mock.Create[T]() in c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs: line 328
POSUnitTests.TransactionServiceTest.SaveTransactionTest() in c:\tfs\Point of Sale\POSApp\Main\Source\POSUnitTests\TransactionServiceTest.cs: line 151


If I just do a TransactionHeaderViewModel ticket = new TransactionHeaderViewModel(); instead, then the calls to Mock.Arrange(() => ticket.SetLineNumbers()).DoNothing(); don't actually work, when debugging the test case you can see that the actual code is called.  I also tried making SetLineNumbers() a virtual, but that caused the "Opps" error.

I thought that it was having an issue with what the constructor was doing, so I commented out everything in the constructor, but still get the same error (in fact, the error above is from that simplified case).

Any thoughts, or is this something that's already fixed in the current builds?  I'm on the 528.5 beta release.


Thanks,
     Justin
Ricky
Telerik team
 answered on 19 Jul 2010
2 answers
53 views
A feature I would really like to see to assist with using JustMock is a way of setting up unit tests far more easily.

In my situation I am dealing with calls from a silverlight client that are passing collections of objects created originally by linq to sql. All the examples show using JustMock for testing of very simple methods - currency conversion etc. While I realise there is no limit to the complexity of what can be setup, it is very difficult to set these types of parameters up by hand.

What I would really like is a way to hit a breakpoint in my code, and then be able to select "JustMock This" off a menu somehow.

This would clone the current arguments into a repeatable test.  I wouldnt care if the clone was done in code, or the arguments were persisted in some way. I just dont want to have to recreate them all by hand.

It would open the door not just to simplified set up of unit tests, it would also be a powerful debugging tool as well, as sometimes the operations to get to a bug can be complex, and it is a real pain to keep going through the motions just to get back to the same method again.

If there is a way of doing all this with the existing product, please let me know how. If not, what do you think of this as a feature?

Tom
Tom
Top achievements
Rank 1
 answered on 13 Jul 2010
2 answers
107 views
Is it possible to mock non-public members using JustMock?

public class Foo
{
     private int Bar() { get; set; } // Can this be mocked?
}
Nick
Top achievements
Rank 1
 answered on 05 Jul 2010
2 answers
133 views
I'm trying to mock out a call that takes in nullable GUIDs, unfortunately when I try arranging the call:

Mock.Arrange(() => myStubInstance.DoSomthing(Arg.Any<Nullable<GUID>>()) or
Mock.Arrange(() => myStubInstance.DoSomthing(Arg.Any<GUID?>())

I get a null reference exception being thrown.  I then tried change the Arrange to use just GUID as the Arg type which works, but when the call is made in the code under test with a null value, the null reference is thrown again.

How can I get around this?

Ta,
J
Imaji
Top achievements
Rank 1
 answered on 02 Jul 2010
2 answers
119 views
Hi,

Is there any specific syntax I should be mocking Extension Methods?

Currently I'm trying to mock that an extension method called AddToRegion on RegionManager from PRISM is mocked.  The code looks a bit like this:

var stubRegionManager = Mock.Create<IRegionManager>();

Mock.Arrange(() => stubRegionManager.AddToRegion(Arg.Any<string>(), Arg.Any<object>()).Returns(stubRegionManager);

Then I inject regionManager into the class in question.  The problem is the method isn't mocked and the original is called.

Any ideas?

Cheers,
John
Chris
Telerik team
 answered on 01 Jul 2010
1 answer
161 views
Hi,

I'm not sure if I'm setting this one up properly:

Mock

 

 

.SetupStatic(typeof(System.Web.Security.Membership));

 

 

 

 

 

I get the following exception message:

"The type 'System.Web.Security.MembershipCreateStatus&' may not be used as a type argument."

I'm trying to verify that Membership.CreateUser is being called inside a method.

Thanks,

Joe

Ricky
Telerik team
 answered on 24 Jun 2010
1 answer
111 views
The following test in VS 2010:

            ICustomer cust = Mock.Create<ICustomer>();  
 
            Order ord = new Order(cust);  
 
            Mock.Assert(() => cust.GetAddress(), Occurs.Once());  
 
            ord.GetCustomerAddress(); 

Where Customer is this:

namespace MockTest  
{  
    public class Customer : MockTest.ICustomer  
    {  
        public string GetAddress()  
        {  
            return "some address";  
        }  
    }  

And Order is this:

namespace MockTest  
{  
    public class Order  
    {  
        ICustomer m_cust;  
 
        public Order(ICustomer cust)  
        {  
            m_cust = cust;  
        }  
 
        public string GetCustomerAddress()  
        {  
            return m_cust.GetAddress();  
        }  
    }  

Results in a MockAssertionException with the following message:

Exepcted call on the mock should be once.But was 0 times.

As you can see in the GetCustomerAddress implementation of Order, the code does indeed call GetAddress on the ICustomer instance.  Additionally, message formatting and spelling is incorrect.

Joe
Ricky
Telerik team
 answered on 14 Jun 2010
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?