c# - write Rhino Mock Test cases for Web api -
hi have created webapi below. trying write rhino mocks below api have tried lot everytime failed
webapi client hit web api
[httppost] public actionresult testapi(string test) { using (var client = new httpclient()) { client.baseaddress = new uri("http://localhost:42327/"); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); httpresponsemessage response = client.getasync("api/home/test/test").result; if (response.issuccessstatuscode) { var result = response.content.readasstringasync().result; viewbag.valid = result; return view(); } else { var result = response.content.readasstringasync().result; viewbag.valid = result; return view(); } } } **webapi code** [route("api/{home}/{username}/{password}")] public httpresponsemessage get(string username, string password) { httpresponsemessage response; var display = userloginvalues().where(m => m.username == username && m.password == password).firstordefault(); if (display != null) { response = request.createresponse(httpstatuscode.ok); response.content = new stringcontent("xxxx.", encoding.unicode); } else { response = request.createresponse(httpstatuscode.notfound); response.content = new stringcontent("xxxx", encoding.unicode); } return response; } public static list<loginmodel> userloginvalues() { list<loginmodel> objmodel = new list<loginmodel>(); objmodel.add(new loginmodel { username = "test", password = "test" }); return objmodel; }
rhin mocks tried below dont know how proceed
mockrepository mocks = new mockrepository(); httpresponsemessage _respone; _respone = login.get("test", "test");
Comments
Post a Comment