public IActionResult GetByName(string name) { try { return(Ok(_citiesService.GetByName(name))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void ReturnNull_WhenNameIsNull() { // Arrange var repoMock = new Mock <IEfRepository <City> >(); var dbContextMock = new Mock <ISaveContext>(); CitiesService citiesService = new CitiesService(repoMock.Object, dbContextMock.Object); // Act City city = citiesService.GetByName(null); // Assert Assert.IsNull(city); }
public void ReturnNull_WhenThereIsNoModelWithThePassedName() { // Arrange var repoMock = new Mock <IEfRepository <City> >(); var dbContextMock = new Mock <ISaveContext>(); repoMock.Setup(m => m.Add(new City() { Name = "PeshoCity" })); CitiesService citiesService = new CitiesService(repoMock.Object, dbContextMock.Object); // Act City city = citiesService.GetByName("Pesho"); // Assert Assert.IsNull(city); }