예제 #1
0
        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>();
        }
예제 #2
0
        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());
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 public ActionResult Index()
 {
     return(View(categoryLogic.GetCategories()));
 }
예제 #5
0
 public ActionResult CategoryList()
 {
     return(View(CategoryLogic.GetCategories()));
 }