Пример #1
0
        public ActionResult Create(ProductDTO item)
        {
            if (!ModelState.IsValid) return View("Create");

            m_service.Add(item);

            return RedirectToAction("Index");
        }
Пример #2
0
        public void Update(ProductDTO product)
        {
            Product entity = m_context.Set<Product>().Find(product.Id);
            if (entity == null)
                throw new InvalidOperationException("Entity not found during Edit operation");

            m_context.Entry(entity).CurrentValues.SetValues(product);
            m_context.SaveChanges();
        }
Пример #3
0
        public ActionResult Edit(int id, ProductDTO product)
        {
            if (!ModelState.IsValid) return View("Edit");
            try
            {
                m_service.Update(product);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #4
0
        public void DetailsTest()
        {
            var expected = new ProductDTO
            {
                BarCode = "11215156",
                InStock = 21,
                Name = "Аспирин",
                Id = 1
            };
            ServiceMock.Setup(it => it.Find(1)).Returns(expected);

            var result = ProductController.Details(1);

            var model = (result as ViewResult).Model as ProductDTO;

            Assert.AreEqual(expected, model);
        }
Пример #5
0
        public void CreateProduct()
        {
            var mockSet = new Mock<DbSet<Product>>();

            var mockContext = new Mock<DAL.IDbContext>();
            mockContext.Setup(m => m.Set<Product>()).Returns(mockSet.Object);

            var service = new ProductService(mockContext.Object);
            var product = new ProductDTO
            {
                BarCode = "11215156",
                InStock = 21,
                Name = "Аспирин"
            };
            service.Add(product);

            mockSet.Verify(m => m.Add(It.IsAny<Product>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Пример #6
0
 public void Add(ProductDTO product)
 {
     m_context.Set<Product>().Add(Mapper.Map<Product>(product));
     m_context.SaveChanges();
 }