public void GetCategories_ListNotNull_ReturnTheList() { var categories = new List <Category>() { new Category() { CategoryId = 1 }, new Category() { CategoryId = 2 } }.AsQueryable(); var mockSet = new Mock <DbSet <Category> >(); mockSet.As <IQueryable <Category> >().Setup(m => m.Provider).Returns(categories.Provider); mockSet.As <IQueryable <Category> >().Setup(m => m.Expression).Returns(categories.Expression); mockSet.As <IQueryable <Category> >().Setup(m => m.ElementType).Returns(categories.ElementType); mockSet.As <IQueryable <Category> >().Setup(m => m.GetEnumerator()).Returns(categories.GetEnumerator()); var contextMock = new Mock <Entities>(); contextMock.Setup(p => p.Categories).Returns(mockSet.Object); var logic = new CategoryLogic(contextMock.Object); var result = logic.GetCategories(); result.Should().HaveCount(2); result.Should().AllBeOfType <Category>(); }
public void GetCategories_ListIsNull_ReturnNull() { var mockSet = new Mock <DbSet <Category> >(); var contextMock = new Mock <Entities>(); contextMock.Setup(p => p.Categories).Returns(mockSet.Object); var logic = new CategoryLogic(contextMock.Object); var result = logic.GetCategories(); contextMock.Verify(entities => entities.Categories, Times.Once()); }
private void FillDatagrid() { dgvCategoryDetails.Rows.Clear(); var categories = _categoryLogic.GetCategories(); foreach (var category in categories) { DataGridViewRow newRow = new DataGridViewRow(); newRow.CreateCells(dgvCategoryDetails); newRow.SetValues( category.Id, category.Description, !category.Disabled ); dgvCategoryDetails.Rows.Add(newRow); } }
public ActionResult Index() { return(View(categoryLogic.GetCategories())); }
public ActionResult CategoryList() { return(View(CategoryLogic.GetCategories())); }