Esempio n. 1
0
        public async System.Threading.Tasks.Task GetCategoriesAsync_NotInCache_GetCategoriesFromDatabase()
        {
            //Arrange
            NorthwindDbContext stubNorthwindDBContext = StubDbContext.GetContextWithData();
            FakeCache          fakeCache    = new FakeCache(false);
            MockLogger         mockLogger   = new MockLogger();
            NorthwindDAL       northwindDAL = new NorthwindDAL(stubNorthwindDBContext, fakeCache, mockLogger);

            //Act
            IList <Category> Categories = await northwindDAL.GetCategoriesAsync();

            //Assert
            Assert.IsTrue(mockLogger.DidLog("##Start## GetCategories from database."));
        }
Esempio n. 2
0
        public async System.Threading.Tasks.Task GetCategoriesAsync_InCache_GetCategoriesFromCacheAsync()
        {
            //Arrange
            NorthwindDbContext stubNorthwindDBContext = StubDbContext.GetContextWithData();
            FakeCache          fakeCache = new FakeCache(true);
            //fakeCache.Set("", "categories");
            MockLogger mockLogger = new MockLogger();

            NorthwindDAL northwindDAL = new NorthwindDAL(stubNorthwindDBContext, fakeCache, mockLogger);

            //Act
            IList <Category> Categories = await northwindDAL.GetCategoriesAsync();

            //Assert
            //Assert.IsNotNull(Categories);
            Assert.IsTrue(mockLogger.DidLog("##Start## GetCategories from cache."));
        }
Esempio n. 3
0
        //[ResponseCache(CacheProfileName = "Public5Minutes")]
        //public IActionResult Index()
        public async Task <IActionResult> Index()
        {
            // controller gets the model and passes it to the view
            var model = new HomeIndexViewModel
            {
                VisitorCount = (new Random()).Next(101, 1001),
                //Categories = db.Categories.ToList(),
                //Categories = _db.Categories.OrderBy(c => c.CategoryName).ToList(),
                //Categories = await db.Categories.OrderBy(c => c.CategoryName).ToListAsync(),
                Categories = await _NorthwindDAL.GetCategoriesAsync(),
                //Products = db.Products.ToList()
                //Products = _db.Products.OrderBy(p => p.ProductName).ToList()
                //Products = await db.Products.OrderBy(p => p.ProductName).ToListAsync()
                Products = await _NorthwindDAL.GetProductsAsync()
            };

            return(View(model)); // pass model to view

            //return View();
        }