示例#1
0
        private void GoPost(HttpListenerContext context)
        {
            var data = utils.ReadPost(context.Request);
            IList <Endpoint> parsed;

            try {
                parsed = YamlParser.FromString(data);
            } catch {
                utils.SetStatus(context, HttpStatusCode.BadRequest);
                return;
            }

            if (parsed.Count != 1)
            {
                Unprocessable(context);
                return;
            }

            uint id;

            _endpointDb.Insert(parsed[0], out id);
            utils.AddLocationHeader(context, id);
            utils.SetStatus(context, HttpStatusCode.Created);
        }
示例#2
0
 /// <summary>
 /// Add a new endpoint configuration
 /// </summary>
 /// <param name="endpoint">The new endpoint data</param>
 /// <param name="id">The new generated id, for use with Replace/Delete</param>
 /// <returns>True if the operation succeeded</returns>
 public bool Add(Endpoint endpoint, out uint id)
 {
     return(_endpointDb.Insert(endpoint, out id));
 }
示例#3
0
        public void Find_ShouldRetreiveEndpoint_WhenMethodInList()
        {
            var inserted = new Endpoint {
                Request = new Request {
                    Url = "/phantom", Method = new List <string> {
                        "POST"
                    }
                }
            };
            var incoming = new Endpoint
            {
                Request = new Request {
                    Url = "/phantom", Method = new List <string> {
                        "POST"
                    }, Post = "A string!"
                }
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.NotNull(actual);
        }