public void GetAll_SuccessfulWithFullInformation() { //Using dataset to insert // Moq.Language.Flow.IReturnsResult<DbSet<Category>> returnsResult = dbCategory.Setup(x => x.Add(It.IsAny<Category>())).Returns(category); Mock <DbSet <Category> > mockDbSetCategory = CreateCategoryDbSet(); Mock <ApplicationDbContext> mockDbContext = new Mock <ApplicationDbContext>(); mockDbContext.Setup(x => x.Category).Returns(mockDbSetCategory.Object); // mockDbContext.Setup(x => x.Set<Category>()).Returns(mockDbSetCategory.Object); CategoryRespository categoryRespository = new CategoryRespository(mockDbContext.Object); var lstCategory = categoryRespository.GetAll(); // Both must return the same value Assert.True(lstCategory.ToList().Count == 2); }
public IActionResult Index() { return(View(_categoryRespository.GetAll())); }