public async Task OnRequestAsyncTest() { var apiAction = new DefaultApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")); var context = new TestRequestContext(apiAction, new { name = "laojiu", birthDay = DateTime.Parse("2010-10-10") }); context.HttpContext.RequestMessage.RequestUri = new Uri("http://www.webapi.com/"); context.HttpContext.RequestMessage.Method = HttpMethod.Post; var attr = new PathQueryAttribute(); await attr.OnRequestAsync(new ApiParameterContext(context, 0)); var birthday = KeyValueSerializer.Serialize("time", DateTime.Parse("2010-10-10"), null)[0].Value; var target = new Uri("http://www.webapi.com?name=laojiu&birthDay=" + Uri.EscapeDataString(birthday)); Assert.True(context.HttpContext.RequestMessage.RequestUri == target); }
public async Task OnRequestAsyncTest() { var apiAction = new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")); var context = new TestRequestContext(apiAction, new { name = "laojiu", birthDay = DateTime.Parse("2010-10-10") }); context.HttpContext.RequestMessage.RequestUri = new Uri("http://www.webapi.com/"); context.HttpContext.RequestMessage.Method = HttpMethod.Post; var attr = new PathQueryAttribute(); await attr.OnRequestAsync(new ApiParameterContext(context, 0)); var birthday = context.HttpContext.Services.GetService <IKeyValueFormatter>().Serialize("time", DateTime.Parse("2010-10-10"), null)[0].Value; var target = new Uri("http://www.webapi.com?name=laojiu&birthDay=" + HttpUtility.UrlEncode(birthday, Encoding.GetEncoding(attr.Encoding))); Assert.True(context.HttpContext.RequestMessage.RequestUri == target); }