public async Task getCitiesList_ReturnsNull() { string cacheKey = "cities"; Mock <ICarDataCache> _ICarDataCache = new Mock <ICarDataCache>(); _ICarDataCache.Setup(cache => cache.getCities_Cache(cacheKey)).ThrowsAsync(new Exception()); carDetailsService carDetailsService = new carDetailsService(_ICarDataCache.Object); var result = await carDetailsService.getCitiesList(new newcity(), It.IsAny <ServerCallContext>()); Assert.Null(result); }
public async Task getCitiesList_ReturnsResult() { string cacheKey = "cities"; ListCities CitiesModel = new ListCities(); List <dbCity> locationList = new List <dbCity>(); locationList.Add(new dbCity { City = "Ajmer" }); CitiesModel.DbCity.AddRange(locationList); Mock <ICarDataCache> _ICarDataCache = new Mock <ICarDataCache>(); _ICarDataCache.Setup(cache => cache.getCities_Cache(cacheKey)).ReturnsAsync(CitiesModel); carDetailsService carDetailsService = new carDetailsService(_ICarDataCache.Object); var result = await carDetailsService.getCitiesList(new newcity(), It.IsAny <ServerCallContext>()); Assert.Equal(result, CitiesModel); }