Mocking generic method

2 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 26 Apr 2013 Link to this post


    First of all, I'm newbie with Just Mock and after a few weeks working with it I think you are doing a great job. So, congratulations!!

    Maybe this question is already answered but, if so, I didn't find it. I'd like to intercept a call to a generi method similar to:
    public  class MyClass
        public void MyMethod<T>()

    Now I want to arrange a MyClass instance so I can assert that the method has been call only once for an specific type and never for any other type. I'm tryig to do something similar to:
    var service = Mock.Create<MyClass>();
     Mock.Arrange(() => service.MyMethod<T>()).OccursNever();

    So I can assert the generic method is never called
  2. Kaloyan
    Kaloyan avatar
    871 posts

    Posted 26 Apr 2013 Link to this post

    Hi Dani,

    Thank you for the nice words.

    Currently, arranging against generic methods can be achieved only if you are passing a certain constraint, like this:
    Mock.Arrange(() => service.MyMethod<string>()).OccursNever();
    However, I find your idea very good. Please, vote for its implementation in our Ideas and Feedback portal.

    We are granting you some Telerik points for bringing this to us.

    Please, do not hesitate to contact us once again if you need further assistance with JustMock.

    Kind regards,
    the Telerik team
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
Back to Top