How to return null when accessing a moq object?
===

I am using Moq library for unit testing. Now what i want is that when I access my object for the first time it should return null, and when i access this on second time it should return something else.

here is my code

    var mock = new Mock<IMyClass>();
    mock.Setup(?????);
    mock.Setup(?????);
    
    var actual = target.Method(mock.object);





in my method i am first checking that whether mock object is null or not, if it is null then do initialize it and then do some calls on it.

    bool Method(IMyClass myObj)
    {
        if (myObj != null)
            return true;
        else
        {
            myObj = new MyClass();
            bool result = myObj.SomeFunctionReturningBool();
            return result;
        }
    }


what to do setup for mock object,


Also i need to know how to mock this line

    bool result = myObj.SomeFunctionReturningBool();

