public IHttpActionResult PutProductOption(Guid id, ProductOption productOption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productOption.Id)
            {
                return(BadRequest());
            }

            try
            {
                db.Update(id, productOption);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductOptionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void UpdateTest()
        {
            ProductOptionRepository repo = new ProductOptionRepository();

            ProductOption test = repo.GetByID(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9"));

            string description = test.Description;

            test.Description = "This has been changed by a unit test";

            repo.Update(test);

            ProductOption postUpdate = repo.GetByID(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9"));

            Assert.AreEqual(test.Description, postUpdate.Description);

            postUpdate.Description = description;

            repo.Update(postUpdate);
        }
        public void Update_update_specified_ProductOption_via_context()
        {
            //Arrange
            var repository = new ProductOptionRepository(_mapper, _mockContext,_logging);
            var productOptionToUpdate = new core.Models.ProductOption {  Id = new Guid("5c2996ab-54ad-4999-92d2-89245682d534"), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold Test Mock", Description = "Gold Apple iPhone 6S" };

            //Act 
            repository.Update(productOptionToUpdate);
            var updatedProductOption = repository.GetById(new Guid("5c2996ab-54ad-4999-92d2-89245682d534"));

            //Assert
            Assert.IsNotNull(updatedProductOption);
            Assert.AreEqual(updatedProductOption.Name, "Rose Gold Test Mock");
            Assert.AreEqual(updatedProductOption.Name, productOptionToUpdate.Name);
        }
Ejemplo n.º 4
0
        public void ProductOptionRepositoryUpdateTest()
        {
            //Arrange
            ProductOption productOption = new ProductOption
            {
                Id          = new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9"),
                ProductId   = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"),
                Name        = "HUAWEI",
                Description = "HUAWEI HONOR Updated"
            };

            //Action
            using (ProductOptionRepository productOptionRepository = new ProductOptionRepository())
            {
                //Assert
                Assert.AreEqual(1, productOptionRepository.Update(productOption.Id, productOption));
            }
        }