public async Task getModelsList_ReturnsNull() { int companyId = 1; string cacheKey = "CompanyModel_" + companyId; Mock <ICarDataCache> _ICarDataCache = new Mock <ICarDataCache>(); _ICarDataCache.Setup(cache => cache.getModelsDetails_Cache(companyId, cacheKey)).ThrowsAsync(new Exception()); carDetailsService carDetailsService = new carDetailsService(_ICarDataCache.Object); var result = await carDetailsService.getModelsList(new compId { CompanyId = companyId }, It.IsAny <ServerCallContext>()); Assert.Null(result); }
public async Task getModelsList_ReturnsModels() { int companyId = 1; string cacheKey = "CompanyModel_" + companyId; ListModels models = new ListModels(); List <dbModels> m = new List <dbModels>(); m.Add(new dbModels { ModelId = 1, ModelName = "X1", Rating = 5, ImageUrl = "https://imgd.aeplcdn.com" }); models.DbModels.AddRange(m); Mock <ICarDataCache> _ICarDataCache = new Mock <ICarDataCache>(); _ICarDataCache.Setup(cache => cache.getModelsDetails_Cache(companyId, cacheKey)).ReturnsAsync(models); carDetailsService carDetailsService = new carDetailsService(_ICarDataCache.Object); var result = await carDetailsService.getModelsList(new compId { CompanyId = companyId }, It.IsAny <ServerCallContext>()); Assert.Equal(result, models); }