public void AddMultipleItemsTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); timeZoneService.Add(GetMockTimeZone(2)); timeZoneService.Add(GetMockTimeZone(3)); Assert.AreEqual(timeZoneService.GetAll().Count(), 3); }
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); }
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 GetAllOnNonEmptyRepositoryShouldReturnNonEmptyTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); var allItems = timeZoneService.GetAll(); Assert.AreEqual(allItems.Count(), 1); }
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); }
// POST api/<controller> public IHttpActionResult Post([FromBody] TimeZoneDTO item) { try { var timeZoneService = new TimeZoneService(new TimeZoneRepository()); item.Owner = User.Identity.Name; return(Ok(timeZoneService.Add(item))); } catch (Exception e) { return(InternalServerError(e)); } }