MegaPowerRockstar Posted October 14, 2016 Report Posted October 14, 2016 Hi, I need help in writing Moq unit test for the below criteria. For instance, i have a Person class/model. I need to save this object in database and return the same model back to the client as in HttpResponse type with statuscode success and content to be the object. I need to write moq unit test for this case. I am stuck in setting the HttpResponse Moq object for content. I am able to set the status. Could you please advise. Quote
MegaPowerRockstar Posted October 17, 2016 Author Report Posted October 17, 2016 No one has idea ?? Quote
afdbzindabad Posted October 17, 2016 Report Posted October 17, 2016 3 minutes ago, MegaPowerRockstar said: No one has idea ?? 3 minutes ago, MegaPowerRockstar said: No one has idea ?? u have to mock the saving call that's it . Pm me the code Var moqobj = ne moq<service> Moqobj.setup(x=>x.savingmethod())....... Quote
MegaPowerRockstar Posted October 17, 2016 Author Report Posted October 17, 2016 53 minutes ago, afdbzindabad said: u have to mock the saving call that's it . Pm me the code Var moqobj = ne moq<service> Moqobj.setup(x=>x.savingmethod())....... This is the below code i am trying to set the moq object var mockResponseMessage = new Mock<HttpResponseMessage>(); mockResponseMessage.Object.StatusCode = HttpStatusCode.OK; mockResponseMessage.Object.Content = ?? The below code is the one that i am using in the implementation Person objPerson = _response.Content.ReadAsAsync<Person>().Result; Quote
MegaPowerRockstar Posted October 18, 2016 Author Report Posted October 18, 2016 Never mind guys got the solution.. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.