// GET api/<controller> public IHttpActionResult Get() { try { IEnumerable <TimeZoneDTO> items = new List <TimeZoneDTO>(); var timeZoneService = new TimeZoneService(new TimeZoneRepository()); if (User.IsInRole("Admin")) { items = timeZoneService.GetAll(); } else if (User.IsInRole("User")) { items = timeZoneService.GetByOwner(User.Identity.Name); } else { return(InternalServerError()); } return(Ok(items)); } catch (Exception e) { return(InternalServerError(e)); } }
public void GetByOwnerWithNoRecordsShouldReturnEmptyTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); timeZoneService.Add(GetMockTimeZone(2)); timeZoneService.Add(GetMockTimeZone(3)); Assert.AreEqual(timeZoneService.GetByOwner("abc").Count(), 0); }
public void GetByOwnerWithMultipleRecordsShouldReturnAllTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); timeZoneService.Add(GetMockTimeZone(2)); timeZoneService.Add(GetMockTimeZone(3)); timeZoneService.Add(GetMockTimeZone(4, "anotherOwner")); Assert.AreEqual(timeZoneService.GetByOwner("Owner").Count(), 3); }