It should then work if you change it to ".Return("Stub")" What you have is expecting that you make the call to CallRealValue(), which is called by GetData(), but you're telling it to Return(string.Empty) instead, which, I believe, overrides the t.ReturnValue = dsc.CallStubValue().
You should also be able to do dsc.Stub(x => x.CallRealValue()).IgnoreArguments().Return("Stub") which will create a fake CallRealValue method that will return "Stub" regardless of the supplied Arguments -- the IgnoreArguments() part is optional, depending on what you want it to do. So try one (or both) of those and let me know if either work. On Tuesday, June 26, 2012 3:56:07 PM UTC-4, Tony wrote: > > Hello Adam, > > I tried without ".Return(string.Empty)" but it was giving me > 'InvalidOperationException' because it needed the return value. > > On Tuesday, June 26, 2012 3:39:43 PM UTC-4, Adam wrote: >> >> Doesn't it work if you take away ".Return(string.Empty)" at the end? >> >> On Tuesday, June 26, 2012 3:36:01 PM UTC-4, Tony wrote: >>> >>> Hi, >>> >>> I have question regarding stubbing WCF methods. >>> This example will show you what I am trying to do. >>> >>> I'm coding in C#, VS 2008, Rhino Mocks >>> >>> //WCF >>> >>> [ServiceContract] >>> public interface IDataService >>> { >>> [OperationContract] >>> string GetData(); >>> >>> [OperationContract] >>> string CallRealValue(); >>> >>> [OperationContract] >>> string CallStubValue(); >>> >>> } >>> >>> public class DataService : IDataService >>> { >>> public string GetData() >>> { >>> string result = CallRealValue(); >>> } >>> >>> public virtual string CallRealValue() >>> { >>> //doing something >>> return "Real"; >>> } >>> >>> public virtual string CallStubValue() >>> { >>> //doing something >>> return "Stub"; >>> } >>> } >>> >>> //In my console project, I have reference to the WCF so that I can >>> access their members [ServiceReferenceData] >>> >>> public class Test >>> { >>> public static void Main() >>> { >>> ServiceReferenceData.DataServiceClient dsc = >>> MockRepository.GeneratePartialMock<ServiceReferenceData.DataServiceClient>(); >>> >>> dsc.Expect(x => x.CallRealValue()) >>> .WhenCalled(t => t.ReturnValue = dsc.CallStubValue()) >>> .Return(string.Empty) >>> >>> >>> string result = dsc.GetData(); >>> >>> //After above statement 'result' variable should be 'Stub' >>> instead of null. I could not figured it out whats wrong with my syntex. >>> //However, I tried the same thing with the simpler example >>> that is not WCF service methods and whenever I call GetData() method, >>> //inside of that method it always goes to CallStubValue() >>> which was expected and I was getting the correct result back but for WCF >>> //service it does not working. >>> >>> } >>> >>> } >>> >>> Any help would be appreciated. >>> Thanks, >>> >> -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To view this discussion on the web visit https://groups.google.com/d/msg/rhinomocks/-/p1xyT80FKdcJ. To post to this group, send email to rhinomocks@googlegroups.com. To unsubscribe from this group, send email to rhinomocks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.