public void ChangeProductDescription_Should_Persist_Product_In_Repository()
        {
            //var product = new Product("frytki", "slone dobre i ziemniaczane", 2, 3, 4, 5, 1, new Category());
            //var prod = _sut.CreateProduct(product);

            //prod.Description = "ziemniaczane i bardzo dobre";
            //prod.Name = "fryteczki";

            //var result = _sut.UpdateProduct(prod.Id.Value, prod);

            //product.Name = "fryteczki";
            //product.Description = "ziemniaczane i bardzo dobre";

            //A.CallTo(() => _repository.Persist(product)).MustHaveHappened();
            //A.CallTo(() => _repository.GetById(result.Id.Value).Name).Equals(product.Name);
            //A.CallTo(() => _repository.GetById(result.Id.Value).Description).Equals(product.Description);

            var product = new Product("name", "descr", 1, 2, 3, 4, 1, new Category());
            var expected_product = _sut.CreateProduct(product);

            A.CallTo(() => _repository.Persist(product)).Returns(expected_product);

            var not_changed_product = _sut.ChangeProductDescription(1, "name", "descr");

            A.CallTo(() => _repository.GetById(1)).MustHaveHappened();
            A.CallTo(() => _repository.Persist(not_changed_product)).Returns(expected_product);
            //Assert.That(not_changed_product, Is.EqualTo(expected_product));

            var changed_product = _sut.ChangeProductDescription(1, "different-name", "descr");

            A.CallTo(() => _repository.GetById(1)).MustHaveHappened();
            Assert.That(changed_product, Is.Not.EqualTo(expected_product));
        }
        public void DeleteProduct_Should_Delete_Product_From_Database()
        {
            var product = new Product("Pralko-suszarka", "pierze i suszy", 2, 3, 4, 5, 6, new Category());

            var result_product = _sut.CreateProduct(product);

            A.CallTo(() => _repository.Persist(product)).Returns(result_product);
            A.CallTo(() => _repository.GetById(1)).Returns(result_product);

            var result = _repository.GetById(1);

            Assert.That(result, Is.EqualTo(result_product));

            _sut.DeleteProduct(1);

            A.CallTo(() => _repository.Delete(result_product)).MustHaveHappened();
            A.CallTo(() => _repository.GetById(1)).Returns(null);

            //var result = _repository.GetById(1);
            var result2 = _repository.GetById(1);

            //A.CallTo(() => _repository.GetById(1)).Equals(null);

            Assert.That(result2, Is.EqualTo(null));
            //Assert.That(result, Is.EqualTo(result_product));
        }
        public void CreateProduct_Should_Persist_Product_In_Database()
        {
            var product = new Product("nazwa", "super", 2, 3, 4, 5, 6, new Category());

            var result = _sut.CreateProduct(product);

            A.CallTo(() => _repository.Persist(product)).MustHaveHappened();
        }
        public void GetProductById_Should_Return_Product()
        {
            var category = new Category();
            var product = new Product("Overlord", "o nekromancie", 1, 2, 3, 4, 5, category);
            var create = _sut.CreateProduct(product);

            A.CallTo(() => _repository.Persist(A<Product>._)).Returns(product);
            A.CallTo(() => _repository.GetById(A<int>._)).Returns(product);

            var result = _sut.GetProductById(2);

            Assert.That(result, Is.EqualTo(product));
        }
        public void ChangeProductCategory_Should_Return_Category()
        {
            //            var product = new Product("frytki", "slone dobre i ziemniaczane", 2, 3, 4, 5, 1, new Category());
            //            var category1 = new Category("nazwa1", "smak", "kolor", "cena", "dostepnosc", "wyglad");
            //            //var category2 = new Category("nazwa2", "smakowitosc", "barwa", "jakosc", "swiezosc", "prezentacja");
            //            //product.Category = category1;
            //            var prod = _sut.CreateProduct(product);
            //            prod.CategoryId = category1.Id;
            //            var result = _sut.UpdateProduct(prod.Id.Value, prod);

            //            A.CallTo(() => _repository.Persist(product)).MustHaveHappened();
            //            A.CallTo(() => _repository.GetById(result.Id.Value).CategoryId).Equals(category1.Id);

            var expected = new Product();
            A.CallTo(() => _repository.Persist(A<Product>._)).Returns(expected);
            var result = _sut.ChangeProductCategory(1, new Category());

            Assert.That(result, Is.EqualTo(expected));
        }
 public Product UpdateProduct(int product_id, Product updated_product)
 {
     updated_product.Id = product_id;
     updated_product.AddDate = DateTime.Now;
     return _repository.Persist(updated_product);
 }
 public Product CreateProduct(Product product)
 {
     product.AddDate = DateTime.Now;
     return _repository.Persist(product);
 }
        public IHttpActionResult PutProduct(int id, [FromBody] ProductCreateModel param)
        {
            var product = new Product(param.Name, param.Description, param.CategoryId);
            var updated_category = _productService.UpdateProduct(id, product);

            return CreatedAtRoute("GetProductById", new { id = product.Id }, product);
        }