예제 #1
0
        public ActionResult Add(Shoppinglist model)
        {
            var shoppinglist = new Shoppinglist();

            shoppinglist.Name = model.Name;
            _service.AddOrUpdate(shoppinglist);
            _service.Complete();

            return(RedirectToAction("Index", "Shoppinglists"));
        }
예제 #2
0
        public IHttpActionResult Add(ShoppinglistDto shoppinglistDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var shoppinglist = Mapper.Map <ShoppinglistDto, Shoppinglist>(shoppinglistDto);

            _service.AddOrUpdate(shoppinglist);

            shoppinglistDto.Id = shoppinglist.Id;
            _service.Complete();

            return(Created(new Uri(Request.RequestUri + "/" + shoppinglist.Id), shoppinglistDto));
        }
예제 #3
0
        public void AddOrUpdate_Product_Returns_True()
        {
            // Arrange
            var product = new Product {
                Mass = 50
            };
            var mockRepo = new Mock <IProductRepository>();

            mockRepo.Setup(m => m.AddOrUpdate(product))
            .Returns(
                true
                );
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(uow => uow.Products).Returns(mockRepo.Object);

            ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object);

            // Act
            var actual = service.AddOrUpdate(product);

            // Assert
            Assert.IsTrue(actual);
        }
예제 #4
0
        public void AddOrUpdate_Shoppinglist_Returns_True()
        {
            // Arrange
            var shoppinglist = new Shoppinglist {
                Name = "test"
            };
            var mockRepo = new Mock <IShoppinglistRepository>();

            mockRepo.Setup(m => m.AddOrUpdate(shoppinglist))
            .Returns(
                true
                );
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(uow => uow.Shoppinglists).Returns(mockRepo.Object);

            ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object);

            // Act
            var actual = service.AddOrUpdate(shoppinglist);

            // Assert
            Assert.IsTrue(actual);
        }