public void GetAllCities_Should_BeCalledOnce_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <City> >(); var cityService = new CityServices(mockedRepository.Object); cityService.GetAllCities(); mockedRepository.Verify(rep => rep.All(), Times.Once); }
public void GetAllCities_Should_ThrowArgumentNullException_IfPassedAdvertsAreNull() { var mockedRepository = new Mock <IRepository <City> >(); var cityService = new CityServices(mockedRepository.Object); IEnumerable <City> expectedCitiesResult = null; mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable()); Assert.Throws <ArgumentNullException>(() => cityService.GetAllCities()); }
public void GetAllCities_Should_ReturnEmptyCollection_IfThereAreNoCitiesAdded() { var mockedRepository = new Mock <IRepository <City> >(); var cityService = new CityServices(mockedRepository.Object); IEnumerable <City> expectedCitiesResult = new List <City>(); mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable()); Assert.IsEmpty(cityService.GetAllCities()); }
public void GetAllCities_Should_DoItsJobCorrectly_IfCalled() { var mockedRepository = new Mock <IRepository <City> >(); var cityService = new CityServices(mockedRepository.Object); IEnumerable <City> expectedCitiesResult = new List <City>() { new City(), new City() }; mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable()); Assert.AreEqual(cityService.GetAllCities(), expectedCitiesResult); }