public HttpResponseMessage UpsertTodo(DAL.Todo todo) { var response = false; try { DAL.DAL d = new DAL.DAL(System.Configuration.ConfigurationManager.ConnectionStrings["DB"].ConnectionString); todo.UpdatedOn = DateTime.Now; if (todo.Id == 0) { todo.InsertedOn = DateTime.Now; response = d.InsertTodo(todo); } else { response = d.UpdateTodo(todo); } return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { //send email //appInsight.TrackError(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString())); } //return true; }
public HttpResponseMessage DeleteTodo(DAL.Todo todo) { try { DAL.DAL d = new DAL.DAL(System.Configuration.ConfigurationManager.ConnectionStrings["DB"].ConnectionString); var response = d.DeleteTodo(todo); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { //send email //appInsight.TrackError(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString())); } //return true; }
public async Task GetTodosWithData() { using (var testScope = TestWebAppFactory.Create()) { testScope.AddSeedEntities(TestColumns); testScope.AddSeedEntities(TestTodos); var client = testScope.CreateClient(); var response = await client.GetAsync("/api/todos"); response.EnsureSuccessStatusCode(); var actual = await response.Content.ReadFromJsonAsync <BLL.Todo[]>(); DAL.Todo[] actualEntities = new DAL.Todo[TestTodos.Length]; for (int i = 0; i < TestTodos.Length; i++) { actualEntities[i] = MapDtoToEntity(actual[i]); } Assert.IsNotNull(actual); CollectionAssert.AreEquivalent(TestTodos, actualEntities); } }