public void GivenIHaveFollowingProducts(Table table)
 {
     table.CreateInstance<List<Product>>().ForEach(p =>
     {
         _product = p;
         WhenICallThePostMethod();
     });
 }
        public string Save(Product product)
        {
            if (product.ProductId.IsNullOrEmpty())
                product.ProductId = _guidWrapper.NewGuid();

            _productRepository.Save(product);

            return product.ProductId;
        }
        public void Remove(Product product)
        {
            if (!File.Exists(_xmlDataProductsFilePath))
                return;

            var products = GetAll();

            if (products.Any(p => p.ProductId == product.ProductId))
                products.Remove(products.Single(p => p.ProductId == product.ProductId));

            SaveProducts(products);
        }
        public void Save(Product product)
        {
            var products = new List<Product>();

            if (File.Exists(_xmlDataProductsFilePath))
                products = GetAll();

            if (products.Any(p => p.ProductId == product.ProductId))
                products.Remove(products.Single(p => p.ProductId == product.ProductId));

            products.Add(product);

            SaveProducts(products);
        }
        public HttpResponseMessage Put(Product editedProduct)
        {
            if (editedProduct == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {
                _productHandler.Save(editedProduct);
                return Request.CreateResponse(HttpStatusCode.OK, editedProduct);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
        }
        public void XmlFileExists_Add_FindByInvalidId_Remove()
        {
            var newId = new GuidWrapper().NewGuid();

            var product = new Product
            {
                ProductId = newId,
                Description = "New Product",
                GivenDays = 10,
                NecessaryAmount = 1
            };

            _productRepository.Save(product);

            var addedProduct = _productRepository.FindById("1");

            Assert.That(addedProduct, Is.Null);

            _productRepository.Remove(product);

            var removedProduct = _productRepository.FindById(newId);

            Assert.That(removedProduct, Is.Null);
        }
        public void XmlFileExists_Add_FindByValidId_Edit_Remove()
        {
            var newId = new GuidWrapper().NewGuid();

            var product = new Product
            {
                ProductId = newId,
                Description = "New Product",
                GivenDays = 10,
                NecessaryAmount = 1
            };

            _productRepository.Save(product);

            var addedProduct = _productRepository.FindById(newId);

            Assert.That(addedProduct, Is.Not.Null);
            Assert.That(addedProduct.ProductId, Is.EqualTo(newId));
            Assert.That(addedProduct.Description, Is.EqualTo("New Product"));
            Assert.That(addedProduct.GivenDays, Is.EqualTo(10));
            Assert.That(addedProduct.NecessaryAmount, Is.EqualTo(1));

            addedProduct.Description = "Edited Product";
            addedProduct.GivenDays = 20;
            addedProduct.NecessaryAmount = 2;

            _productRepository.Save(addedProduct);

            var editedProduct = _productRepository.FindById(newId);

            Assert.That(editedProduct, Is.Not.Null);
            Assert.That(editedProduct.ProductId, Is.EqualTo(newId));
            Assert.That(editedProduct.Description, Is.EqualTo("Edited Product"));
            Assert.That(editedProduct.GivenDays, Is.EqualTo(20));
            Assert.That(editedProduct.NecessaryAmount, Is.EqualTo(2));

            _productRepository.Remove(editedProduct);

            var removedProduct = _productRepository.FindById(newId);

            Assert.That(removedProduct, Is.Null);
        }
 public void GivenIWantToAddANewProductX(Table table)
 {
     _product = table.CreateInstance<Product>();
 }
 public void GivenIHaveAProductX(Table table)
 {
     _product = table.CreateInstance<Product>();
     WhenICallThePostMethod();
 }
 public void GivenIHaveANullProduct()
 {
     _product = null;
 }
        void PerformAssertionsOnProduct(Product returnedProduct, Product expectedProduct)
        {
            Assert.That(returnedProduct.ProductId, Is.Not.Null);
            Assert.That(returnedProduct.ProductId, Is.Not.Empty);
            Assert.That(returnedProduct.Description, Is.EqualTo(expectedProduct.Description));
            Assert.That(returnedProduct.NecessaryAmount, Is.EqualTo(expectedProduct.NecessaryAmount));
            Assert.That(returnedProduct.GivenDays, Is.EqualTo(expectedProduct.GivenDays));

            if (!expectedProduct.ProductId.IsNullOrEmpty())
                Assert.That(returnedProduct.ProductId, Is.EqualTo(expectedProduct.ProductId));
        }
        public void ThenTheResultShouldBeAResponseMessageWithStatusXAndContenWithProductY(HttpStatusCode status, Table table)
        {
            _product = table.CreateInstance<Product>();

            Product returnedProduct;

            ThenTheResultShouldBeAResponseMessageWithStatus(status);

            Assert.IsTrue(_response.TryGetContentValue(out returnedProduct));
            PerformAssertionsOnProduct(returnedProduct, _product);
        }
 public void Remove(Product product)
 {
     _productRepository.Remove(product);
 }