Hi Ravi
The code should work unless val3 and val4 get call on a different instance of MyObj in that case you should create another mock and set expectation on it.
The following test will fail:
Mock configMock = MockManager.Mock(typeof(MyObj));
configMock.ExpectGetAlways("val1", "1");
configMock.ExpectGetAlways("val2", "2");
configMock.ExpectGetAlways("val3", "3");
configMock.ExpectGetAlways("val4", "4");
MyObj myObj = new MyObj();
Assert.AreEqual("1", myObj.val1);
Assert.AreEqual("2", myObj.val2);
MyObj myObj2 = new MyObj();
Assert.AreEqual("3", myObj2.val3);
Assert.AreEqual("4", myObj2.val4);
Another option is to use Mock.MockAll.
Use MockAll only if you need to set the same behavior on all instances of a class.
Finally I would advise you to use the newer Arrange Act Assert API.
here is the same test using the AAA API:
var fake = Isolate.Fake.Instance<MyObj>();
// use Isolate.Swap.AllInstances<MyObj>();
// incase you want to the same behavior on all instances.
Isolate.Swap.NextInstance<MyObj>().With(fake);
Isolate.WhenCalled(() => fake.val1).WillReturn("1");
Isolate.WhenCalled(() => fake.val2).WillReturn("2");
Isolate.WhenCalled(() => fake.val3).WillReturn("3");
Isolate.WhenCalled(() => fake.val4).WillReturn("4");
MyObj myObj = new MyObj();
Assert.AreEqual("1", myObj.val1);
Assert.AreEqual("2", myObj.val2);
Assert.AreEqual("3", myObj.val3);
Assert.AreEqual("4", myObj.val4);
As you can see the fakes are strongly type and not string base as in the older reflective mocks API.
This can save you from errors that comes from mismatching methods names and of course let you refactor your code easily.