该文档建议 NancyFx 帮助我完成 json 请求正文的 WRT 反序列化,但我不确定如何。请参阅下面的测试以演示:
[TestFixture]
public class ScratchNancy
{
[Test]
public void RootTest()
{
var result = new Browser(new DefaultNancyBootstrapper()).Post(
"/",
with =>
{
with.HttpRequest();
with.JsonBody(JsonConvert.SerializeObject(new DTO {Name = "Dto", Value = 9}));
});
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
public class RootModule : NancyModule
{
public RootModule()
{
Post["/"] = Root;
}
private Response Root(dynamic o)
{
DTO dto = null;//how do I get the dto from the body of the request without reading the stream and deserializing myself?
return HttpStatusCode.OK;
}
}
public class DTO
{
public string Name { get; set; }
public int Value { get; set; }
}
}