public void SlotStorageOperations() { // Arrange TimeModel timeService = TimeModel.getService(); DateTime start = DateTime.Today; DateTime end = DateTime.Now; string desc = "A daily dummy job"; string project = "Test"; Slot createdSlot = new Slot(start, end, desc, project); // Act timeService.InsertSlot(createdSlot); long id = timeService.GetSlotIdByData(start, end, desc, project); Slot foundSlot = timeService.GetSlotByID(id); // Assert Assert.AreEqual(createdSlot, foundSlot); // Act createdSlot.Description = "An updated activity description"; timeService.UpdateSlot(createdSlot); foundSlot = timeService.GetSlotByID(id); // Assert Assert.AreEqual(foundSlot.Description, createdSlot.Description); // Act timeService.DeleteSlot(id); foundSlot = timeService.GetSlotByID(id); long noId = timeService.GetSlotIdByData(createdSlot.Start, createdSlot.End, createdSlot.Description, createdSlot.Project); // Assert Assert.IsNull(foundSlot); Assert.AreEqual(noId, TimeModel.NON_VALUE); }
public HttpResponseMessage Post(FormDataCollection formData) { DateTime start, end; long id; bool success = true; success &= DateTime.TryParse(formData["Start"], out start); success &= DateTime.TryParse(formData["End"], out end); if (!success) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (start > end) { DateTime tmp = end; end = start; start = tmp; } string description = formData["Description"]; string project = formData["Project"].Trim().Length == 0 ? UNSPECIFIED_PROJECT : formData["Project"]; TimeModel timeService = TimeModel.getService(); Slot storedSlot = null; if (Int64.TryParse(formData["ID"], out id)) { storedSlot = timeService.GetSlotByID(id); } if (storedSlot != null) { success = timeService.UpdateSlot(new Slot(id, start, end, description, project)); return(new HttpResponseMessage(success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError)); } else { success = timeService.InsertSlot(new Slot(start, end, description, project)); return(new HttpResponseMessage(success ? HttpStatusCode.Created : HttpStatusCode.InternalServerError)); } }