removing dependancy of a private function inside a public function using Rhino Mocks

Posted by L G on Stack Overflow See other posts from Stack Overflow or by L G
Published on 2010-05-02T07:35:18Z Indexed on 2010/05/02 7:37 UTC
Read the original article Hit count: 181

Filed under:
|

Hi All, I am new to mocking, and have started with Rhino Mocks. My scenario is like this..in my class library i have a public function and inside it i have a private function call, which gets output from a service.I want to remove the private function dependency.

public class Employee
    {        
        public virtual string GetFullName(string firstName, string lastName)
        {
            string middleName = GetMiddleName();
            return string.Format("{0} {2} {1}", firstName, lastName,middleName );
        }

        private virtual string GetMiddleName()
        {
            // Some call to Service

            return "George";
        }
    }

This is not my real scenario though, i just wanted to know how to remove dependency of GetMiddleName() function and i need to return some default value while unit testing.

Note : I won't be able to change the private function here..or include Interface..Keeping the functions as such, is there any way to mock this.Thank

© Stack Overflow or respective owner

Related posts about rhino

Related posts about mock