try to Mock setUtcOffset method . But after await Request.Content.ReadAsMultipartAsync... Mock doesnot work . Please tell how it'll fix ??
[TestMethod]
public async Task TestUploadEntity()
{
IContainer container = (IContainer)TestContext.Properties["IContainer"];
BaseApiController apicontroller = container.Resolve<
BaseApiController
>();
Mock.NonPublic.Arrange(apicontroller, "setUtcOffset").IgnoreArguments().IgnoreInstance();
var config = new HttpConfiguration();
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "Mobile" } });
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
formDataContent.Add(new StringContent(Guid.NewGuid().ToString()), name: "EntityID");
controller.Request = request;
controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
var result = await controller.addUpdateMessage();
}
[HttpPost]
public async Task<
string
> addUpdateMessage()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
var provider = await Request.Content.ReadAsMultipartAsync<
InMemoryMultipartFormDataStreamProvider
>(new InMemoryMultipartFormDataStreamProvider());
setUtcOffset();
return "Success";
}