Mocking generic method

4 posts, 0 answers
  1. Daní
    Daní avatar
    314 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
    880 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. Mark
    Mark avatar
    3 posts
    Member since:
    Jan 2015

    Posted 03 Nov 2017 in reply to Kaloyan Link to this post

    Did this ever get implemented in Just Mock?

    it would make my life so much easier.

  4. Kaloyan
    Kaloyan avatar
    880 posts

    Posted 09 Nov 2017 Link to this post

    Hi Mark,

    I am afraid that this is still an unsupported scenario in JustMock. 

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top