Arrange variables inside Private method

3 posts, 1 answers
  1. Sagar
    Sagar avatar
    11 posts
    Member since:
    May 2014

    Posted 05 Mar 2015 Link to this post

    Hi,
      I am facing trouble, while Arranging value of a variable inside a Private Method. Below is a sample code snippet for the scenario that i am working on, which has a Private static method. In method "SomeMethod", i want to arrange the call "someObject.MethodReturnsTrueOrFalse(someValue)".
      Can anybody give me resolution on the same?

    public class SomeClass
    {
       
     private static void SomeMethod()
     {
    int someValue = 10;
    Foo someObject = new Foo();
            var result = someObject.MethodReturnsTrueOrFalse(someValue);
            if(result)
    {
    //do some operation
    }
     }
    }
    Thanks In advance :)

    Sagar





  2. Answer
    Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 05 Mar 2015 Link to this post

    Hello Sagar,

    Future mocking will come handy in this situation:
    Mock.Arrange(() => Arg.IsAny<Foo>().MethodReturnsTrueOrFalse(Arg.AnyInt)).Returns(true);

    If MethodReturnsTrueOrFalse is itself private, then you'll need to go through the non-public mocking API.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Sagar
    Sagar avatar
    11 posts
    Member since:
    May 2014

    Posted 05 Mar 2015 in reply to Stefan Link to this post

    Thanks Stefan, that solves my query.

    Thank you,
    Sagar
Back to Top