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,