public async void Create_and_update_entity_should_alter_url_and_add_three_urls_to_updatelog() { var result = await service.Create(testUrl1, new DateTime(2015, 01, 01)); var response = await service.GetEntity(result.Id); await service.Update(result.Id, null, testUrl2 + "?1", DateTime.UtcNow.AddDays(1)); await service.Update(result.Id, null, testUrl2 + "?2", DateTime.UtcNow.AddDays(1)); await service.Update(result.Id, null, testUrl2 + "?3", DateTime.UtcNow.AddDays(1)); response = await service.GetEntity(result.Id); }
private async Task InvokePut(IOwinContext context) { var id = context.Request.Path.Value.Substring(1); var accesstoken = context.Request.Query["accesstoken"]; if (string.IsNullOrWhiteSpace(id)) { context.Response.StatusCode = 404; await context.Response.WriteAsync("Missing ID"); } if (string.IsNullOrWhiteSpace(accesstoken)) { context.Response.StatusCode = 404; await context.Response.WriteAsync("Missing accesstoken"); } using (var reader = new JsonTextReader(new StreamReader(context.Request.Body, Encoding.UTF8))) { UrlEntityRequest request = new Newtonsoft.Json.JsonSerializer().Deserialize <UrlEntityRequest>(reader); try { await _service.Update(id, accesstoken, request); context.Response.StatusCode = 200; await context.Response.WriteAsync(string.Format("Url with ID: {0} is updated", id));; } catch (UnAuthorizedException e) { context.Response.StatusCode = 403; await context.Response.WriteAsync(e.Message); } catch (NotFoundException e) { context.Response.StatusCode = 404; context.Response.ReasonPhrase = e.Message; context.Response.ContentType = "text/html"; await context.Response.WriteAsync(File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/html/Notfound.html"))); } catch (Exception e) { context.Response.StatusCode = 500; await context.Response.WriteAsync("Server error" + (AppSettingsReader.Debug ? e.Message + Environment.NewLine + e.InnerException : "")); } } }