public void RemoveValidItemShouldRemoveItTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); timeZoneService.Add(GetMockTimeZone(2)); timeZoneService.Add(GetMockTimeZone(3)); Assert.IsNotNull(timeZoneService.GetByID(1)); timeZoneService.Remove(1); Assert.IsNull(timeZoneService.GetByID(1)); }
public void GetByIDInvalidIDTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); var item = timeZoneService.GetByID(2); Assert.IsNull(item); }
public void GetByIDValidIDTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); var item = timeZoneService.GetByID(1); Assert.IsNotNull(item); Assert.AreEqual(item.ID, 1); }
public void UpdateValidItemTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); var item = GetMockTimeZone(1); timeZoneService.Add(item); item.Name = "updated"; timeZoneService.Update(item); Assert.AreEqual(item.Name, timeZoneService.GetByID(1).Name); }
// GET api/<controller>/5 public IHttpActionResult Get(int id) { try { var timeZoneService = new TimeZoneService(new TimeZoneRepository()); TimeZoneDTO item = timeZoneService.GetByID(id); if (!User.IsInRole("Admin") && (item.Owner != User.Identity.Name)) { return(Unauthorized()); } return(Ok(item)); } catch (Exception e) { return(InternalServerError(e)); } }
// DELETE api/<controller>/5 public IHttpActionResult Delete(int id) { try { var timeZoneService = new TimeZoneService(new TimeZoneRepository()); TimeZoneDTO timeZone = timeZoneService.GetByID(id); if (!User.IsInRole("Admin") && (timeZone.Owner != User.Identity.Name)) { return(Unauthorized()); } timeZoneService.Remove(id); return(Ok(HttpStatusCode.NoContent)); } catch (Exception e) { return(InternalServerError(e)); } }
// PUT api/<controller>/5 public IHttpActionResult Put(int id, [FromBody] TimeZoneDTO item) { try { var timeZoneService = new TimeZoneService(new TimeZoneRepository()); TimeZoneDTO timeZone = timeZoneService.GetByID(id); if (!User.IsInRole("Admin") && (item.Owner != User.Identity.Name)) { return(Unauthorized()); } item.ID = id; timeZoneService.Update(item); return(Ok(HttpStatusCode.NoContent)); } catch (Exception e) { return(InternalServerError(e)); } }