Zaz.Server.Advanced.Service.CommandsService.PostLegacy C# (CSharp) Метод

PostLegacy() приватный Метод

private PostLegacy ( HttpRequestMessage req ) : HttpResponseMessage
req HttpRequestMessage
Результат HttpResponseMessage
        public HttpResponseMessage PostLegacy(HttpRequestMessage req)
        {
            var body = req.Content.ReadAsStringAsync().Result;
            var form = ParseQueryString(body);

            if (!form.ContainsKey("Zaz-Command-Id"))
            {
                throw ExceptionsFactory.CreateApiException("Required value 'Zaz-Command-Id' was not found.");
            }

            var cmdKey = form["Zaz-Command-Id"];
            var cmdType = _resolver.ResolveCommandType(cmdKey);

            var cmd = BindFormToCommand(form, cmdType);

            return _runner.RunCommand(cmdKey, cmd, new string[0]);
        }

Usage Example

 public void Given_service_by_default()
 {
     _broker = new CommandBrokerStub();
     var service = new CommandsService(new ServerContext(broker: _broker));
     var cmdKey = typeof (FooCommand).FullName;
     var cmdContent = new StringContent("Zaz-Command-Id=" + cmdKey + "&Value1=Foo");
     cmdContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
     var cmdMessage = new HttpRequestMessage
         {
             Content = cmdContent
         };
     _result = service.PostLegacy(cmdMessage);
 }