示例#1
0
        public async void Create_and_delete_entity_should_should_throw_exception_with_invalid_accesstoken()
        {
            var result = await service.Create(testUrl1, new DateTime(2015, 01, 01));


            var ex       = Assert.Throws <UnAuthorizedException>(async() => await service.Delete(result.Id, new RandomStringGenerator().GetRandomStringAlfa(12)));
            var response = await service.GetEntity(result.Id);

            Assert.IsNotNull(response);

            Console.WriteLine(ex);
        }
示例#2
0
        private async Task InvokeDelete(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");
            }

            try
            {
                await _service.Delete(id, accesstoken);

                context.Response.StatusCode = 200;
                await context.Response.WriteAsync(string.Format("Url with ID: {0} is deleted", 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 : ""));
            }
        }