i using rhino mocks stub out functionality of soap endpoint , part works. but, interface quite quirky , struggling following work (i have renamed classes simplicity)
public interface iwebservice { void copyfile(request request); } public interface iservice { void copyfile(string filename, byte[] data); } public class request { public string filename { get; set; } public byte[] data { get; set; } } public class service : iservice { iwebservice _service; public service(iwebservice service) { _service = service; } public void copyfile(string filename, byte[] data) { _service.copyfile(new request() {filename = filename,data = data }); } }
now, in test have this
[testcase] public void testfilecopyfailsiffilenameismissing() { iwebservice servicemock = mockrepository.generatemock<iwebservice>(); servicemock.expect(x => x.copyfile(arg<request>.is.equal(new request() { filename = arg<string>.is.null, data = arg<byte[]>.is.anything }))).throw(new exception()); service service = new service(servicemock); service.copyfile(null, new byte[] { }); }
which throws exception: exception of type 'system.invalidoperationexception' occurred in rhino.mocks.dll not handled in user code
additional information: use arg within mock method call while recording. 1 arguments expected, 3 have been defined.
i have tried possibilities in world on one, cant right. if dont use arg , use
expect(null, new byte[]{});
it pass no matter what
i suggest use whencalled
, in method check request
object.
bool iscorrectparam = false; iwebservice servicemock = mockrepository.generatemock<iwebservice>(); servicemock.expect(x => x.copyfile(null)) .ignorearguments() .whencalled(x => { request req = x.arguments[0] request; if (req.data.count() == 0 && req.filename == null) { iscorrectparam = true; } }); service service = new service(servicemock); service.copyfile(null, new byte[] { }); assert.istrue(iscorrectparam);
Comments
Post a Comment