I am trying to mock a WCF Client Proxy with Rhino Mock but I am not having much luck.
var ServiceMock = MockRepository.GeneratePartialMock<ServiceClient>();
ServiceMock.Expect(p => p.Publish("")).IgnoreArguments().Return("Worked");
This is how I have been trying to mock the proxy out. It is a normal set up through a constructor.
This does not seem to mock the ServiceClient can anyone help?
This will help you to use Rhino mocks with WCF
http://kashfarooq.wordpress.com/2008/11/29/mocking-wcf-services-with-rhinomocks/ and http://ayende.com/blog/2095/wcf-mocking-and-ioc-oh-my
Should be able to do something like this:
[TestClass]
public class MyTestClass{
private IService _service;
[TestInitialize]
public void Setup(){
_service = MockRepository.GenerateStrictMock<IService, ICommunicationObject>();
}
[TestMethod]
public void TestWhatsGoingOn(){
_service.Expect(.....).Return(.....);
//This will test the close is called too (hence the ICommunicationObject above)
((ICommunicationObject)_service).Expect(r => r.Close());
}
[TestCleanup]
public void CleanItUp{
_service.VerifyAllExpectations();
}
This means you can test the close method is called too (as expected)
I think you need to generate a strict mock not a partial...
Also of course, if you want to assert that the .Abort() call is made during exception handling and the like - you can do so with:
((ICommunicationObject)_service).Expect(r => r.Abort());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.