internal City GetById(int id) { var data = _repo.GetById(id); if (data == null) { throw new Exception("Invalid Id"); } return(data); }
public ActionResult <City> GetById(Guid id) { var city = _cities.GetById(id); if (city == null) { return(NotFound()); } return(Ok(city)); }
public ActionResult <string> Get(Guid id) { var poi = repository.GetById(id); if (poi != null) { var city = citiesRepository.GetById(poi.CityId); if (city != null) { return(Ok(poi)); } else { return(NotFound()); } } else { return(NotFound()); } }
public void GetById_ReturnsCorrectData() { // arrange var model = new CityModel { Id = 1, Name = "1" }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetById <CityModel, int>(It.IsAny <int>())) .Returns(model); var repository = new CitiesRepository( dataStoreMock.Object ); // act var item = repository.GetById(1); // assert Assert.AreEqual(1, item.Id); }
public void GetById_CallsDataStore() { // arrange var model = new CityModel { Id = 1, Name = "1" }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetById <CityModel, int>(It.IsAny <int>())) .Returns(model); var repository = new CitiesRepository( dataStoreMock.Object ); // act repository.GetById(1); // assert dataStoreMock.Verify(mock => mock.GetById <CityModel, int>(It.Is <int>(item => item == 1)), Times.Once()); }