c# - Async method not execute sometimes -


i have webapi controller async method post:

public class webapicontroller : apicontroller {  public async task<httpresponsemessage> post(httprequestmessage request)     {         try         {             string json = await request.content.readasstringasync();             var model = jsonconvert.deserializeobject<tmodel>(json);             var newentity = mapper.map<tentity>(model);             var newentityversion = mapper.map<tentityversion>(model);             var result = await currentrepository.addasync(newentity, newentityversion);              return createresponse(result, "defaultapipost");         }         catch (exception e)         {             logger.error("post in " + controllername, e);              return request.createerrorresponse(httpstatuscode.badrequest, e);         }     } } 

addasync method looks :

public virtual async task<tentity> addasync(tentity entity, tentityversion version) {  await databasecontext.savechangesasync();  return entity; } 

when call post method using httpclient can enter addasync method :

client.postasync(requesturi, content).result.content.readasstringasync().result; 

but when call post method using webapi controller explicit can not enter addasync method, jump on :/ :

 var product = fakeproduct();          var newentity = mapper.map<productentity>(product);         var newentityversion = mapper.map<productversionentity>(product);          productrepository.addasync(newentity, newentityversion).returns(task.fromresult<productentity>(newentity));           var content = jsonconvert.serializeobject(product);          var request = new httprequestmessage(httpmethod.post, "http://localhost:8888/api/product/")           {               content = new stringcontent(content),           };          var webapicontroller = fakewebapicontrollerwithpostroute();          var result = await webapicontroller.post(request);          assert.areequal(httpstatuscode.created, result.statuscode); 

any idea why method not executed ?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -