public void RepositoryBase_GetById_Overload_Checks_Cache_If_Cacheable_And_Scoped() { // Arrange var cacheKey = CachingProvider.GetCacheKey(string.Format(Constants.CACHE_CatsKey + "_" + Constants.CACHE_ScopeModule + "_{0}", Constants.MODULE_ValidId)); var mockHostController = MockComponentProvider.CreateNew <IHostController>(); mockHostController.Setup(h => h.GetString("PerformanceSetting")).Returns("3"); var mockCache = MockComponentProvider.CreateDataCacheProvider(); mockCache.Setup(c => c.GetItem(cacheKey)).Returns(new List <CacheableCat>()); var mockRepository = new Mock <RepositoryBase <CacheableCat> >(); // Act var cat = mockRepository.Object.GetById(Constants.PETAPOCO_ValidCatId, Constants.MODULE_ValidId); // Assert mockCache.Verify(c => c.GetItem(cacheKey)); }
public void RepositoryBase_Get_Does_Not_Call_GetAllInternal_If_Cacheable_And_Cache_Valid() { //Arrange var mockHostController = MockComponentProvider.CreateNew <IHostController>(); mockHostController.Setup(h => h.GetString("PerformanceSetting")).Returns("3"); var mockCache = MockComponentProvider.CreateDataCacheProvider(); mockCache.Setup(c => c.GetItem(CachingProvider.GetCacheKey(Constants.CACHE_DogsKey))).Returns(new List <CacheableDog>()); var mockRepository = new Mock <RepositoryBase <CacheableDog> >(); mockRepository.Protected().Setup("GetInternal"); //Act var list = mockRepository.Object.Get(); //Assert mockRepository.Protected().Verify("GetInternal", Times.Never()); }
public void PortalGroupController_GetPortalGroups_Returns_List_Of_PortalGroups() { //Arrange var mockCache = MockComponentProvider.CreateNew <CachingProvider>(); mockCache.Setup(c => c.GetItem(CachingProvider.GetCacheKey(DataCache.PortalGroupsCacheKey))).Returns(null); Mock <IDataService> mockDataService = new Mock <IDataService>(); mockDataService.Setup(ds => ds.GetPortalGroups()).Returns(CreateValidPortalGroupsReader(Constants.PORTALGROUP_ValidPortalGroupCount, Constants.USER_ValidId)); var mockPortalController = new Mock <IPortalController>(); var controller = new PortalGroupController(mockDataService.Object, mockPortalController.Object); //Act IEnumerable <PortalGroupInfo> portalGroups = controller.GetPortalGroups(); //Assert Assert.AreEqual(Constants.PORTALGROUP_ValidPortalGroupCount, portalGroups.Count()); }
public void RepositoryBase_Get_Overload_Does_Not_Call_GetAllByScopeInternal_If_Cacheable_And_Cache_Valid() { // Arrange var cacheKey = CachingProvider.GetCacheKey(string.Format(Constants.CACHE_CatsKey + "_" + Constants.CACHE_ScopeModule + "_{0}", Constants.MODULE_ValidId)); var mockHostController = MockComponentProvider.CreateNew <IHostController>(); mockHostController.Setup(h => h.GetString("PerformanceSetting")).Returns("3"); var mockCache = MockComponentProvider.CreateDataCacheProvider(); mockCache.Setup(c => c.GetItem(cacheKey)).Returns(new List <CacheableCat>()); var mockRepository = new Mock <RepositoryBase <CacheableCat> >(); mockRepository.Protected().Setup <IEnumerable <CacheableCat> >("GetByScopeInternal", ItExpr.IsAny <object>()); // Act var list = mockRepository.Object.Get <int>(Constants.MODULE_ValidId); // Assert mockRepository.Protected().Verify <IEnumerable <CacheableCat> >("GetByScopeInternal", Times.Never(), ItExpr.IsAny <object>()); }
private static string GetDnnCacheKey(string CacheKey) { return(CachingProvider.GetCacheKey(CacheKey)); }