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); }
/// <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)); }
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); }