c# - How to create a fake FtpWebResponse -



c# - How to create a fake FtpWebResponse -

i trying false ftpwebrequest.getresponse() integration test, without using server. have been trying simple homecoming false ftpwebresponse but, not allowed access constructor ftpwebresponse because internal.

here code:

production code:

using (ftpwebresponse response = (ftpwebresponse) ftpwebrequest.getresponse()) { ftpresponse = new ftpresponse(response.statusdescription, false); }

test false trying utilize homecoming false ftpwebresponse:

shimftpwebrequest.allinstances.getresponse = request => { ftpwebresponse ftpwebresponse= new ftpwebresponse(/*parameters*/); // not allowed because internal ftpwebresponse.statusdescription="blah blah blah"; homecoming ftpwebresponse; };

in end, want homecoming false ftpwebresponse assertion in test. ideas? thanks

found answer. if shim ftpwebresponse, allow constructor:

ftpresponse response; using (shimscontext.create()) { shimftpwebrequest.allinstances.getresponse = request => new shimftpwebresponse(); shimftpwebresponse.allinstances.statusdescriptionget = getdescritpion => "226 transfer complete."; _ftpconnection.put(_filecontent); response = new ftpresponse("226 transfer complete.", false); } assert.areequal(response.message, "226 transfer complete."); assert.isfalse(response.haserror);

c# ftpwebrequest microsoft-fakes ftpwebresponse

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -