public async Task UpdateProduct_ShouldChangeProductIntoDb()
        {
            Product testProduct;
            var     product = new Repository.Product
            {
                Name          = "testName",
                Description   = "testDesc",
                Price         = 356,
                DeliveryPrice = 13
            };

            product.Id = await _productRepository.CreateProduct(product);

            testProduct = product;

            testProduct.Name        = Guid.NewGuid().ToString();
            testProduct.Description = DateTime.Now.ToString();

            var response = await _productController.Update(testProduct);

            var responseGet = await _productController.GetProduct(testProduct.Id);

            ObjectContent content = responseGet.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(testProduct.Name, ((Product)content.Value).Name);
            Assert.AreEqual(testProduct.Description, ((Product)content.Value).Description);
        }
        public async Task GetProductOption_ShouldReturnOneOptionById()
        {
            var product = new Repository.Product
            {
                Name          = "Samsung Note3 Mobile",
                Description   = "testDesc",
                Price         = 356,
                DeliveryPrice = 13
            };

            product.Id = await _productRepository.CreateProduct(product);

            var option = new Repository.ProductOption
            {
                Name        = "White",
                Description = "White Samsung Note3 Mobile",
                ProductId   = product.Id
            };

            option.Id = await _productRepository.CreateProductOption(option);

            var response = await _productController.GetOption(option.Id);

            ObjectContent content = response.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(option.Name, ((ProductOption)content.Value).Name);
            Assert.AreEqual(option.Description, ((ProductOption)content.Value).Description);
        }
        public async Task DeleteProduct_ShouldRemoveProductFromDb()
        {
            string  name = Guid.NewGuid().ToString();
            Product testProduct;

            var product = new Repository.Product
            {
                Name          = name,
                Description   = "testDesc",
                Price         = 356,
                DeliveryPrice = 13
            };

            product.Id = await _productRepository.CreateProduct(product);

            testProduct = product;

            var beforeDeletingResult = await _productRepository.GetProductById(testProduct.Id);

            Assert.IsNotNull(beforeDeletingResult);

            var response = await _productController.Delete(testProduct.Id);

            var responseSearch = await _productController.SearchByName(name);

            ObjectContent content = responseSearch.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(0, ((List <Product>)content.Value).Count);
        }
        public async Task GetProductById_ShouldReturnOneSpecificProduct()
        {
            var products = await _productRepository.GetAllProducts();

            var testProduct = products[0];

            if (testProduct == null)
            {
                var product = new Repository.Product
                {
                    Name          = "testName",
                    Description   = "testDesc",
                    Price         = 356,
                    DeliveryPrice = 13
                };
                await _productRepository.CreateProduct(product);

                testProduct = product;
            }

            var response = await _productController.GetProduct(testProduct.Id);

            ObjectContent content = response.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(testProduct.Id, ((Product)content.Value).Id);
        }
        public async Task SearchProductByName_ShouldReturnProductsContainTheName()
        {
            string name     = "Samsung";
            var    products = await _productRepository.SearchProductsByName(name);

            if (products == null || products.Count == 0)
            {
                var product = new Repository.Product
                {
                    Name          = "Samsung Note3 Mobile",
                    Description   = "testDesc",
                    Price         = 356,
                    DeliveryPrice = 13
                };
                await _productRepository.CreateProduct(product);

                products[0] = product;
            }

            var response = await _productController.SearchByName(name);

            ObjectContent content = response.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(products.Count, ((List <Product>)content.Value).Count);
        }
 public void Add(Product entity)
 {
     using (var db = new BatikStoreEntities())
     {
         db.Products.AddObject(entity);
         db.SaveChanges();
     }
 }
Пример #7
0
        public async Task <HttpResponseMessage> Create(Repository.Product product)
        {
            try
            {
                var newId = await _productRepository.CreateProduct(product);

                return(Request.CreateResponse(HttpStatusCode.OK, newId));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public async Task GetOptions_ShouldReturnAllOptionsByProductId()
        {
            string name     = "Samsung Note3 Mobile";
            var    products = await _productRepository.SearchProductsByName(name);

            Product testProduct;

            if (products == null || products.Count == 0)
            {
                var product = new Repository.Product
                {
                    Name          = name,
                    Description   = "testDesc",
                    Price         = 356,
                    DeliveryPrice = 13
                };

                product.Id = await _productRepository.CreateProduct(product);

                testProduct = product;
            }
            else
            {
                testProduct = products[0];
            }

            var productOption = new ProductOption
            {
                ProductId   = testProduct.Id,
                Name        = "test",
                Description = "test as well"
            };
            await _productRepository.CreateProductOption(productOption);


            var testProductOptions = await _productRepository.GetProductOptionsByProductId(testProduct.Id);

            var response = await _productController.GetOptions(testProduct.Id);

            ObjectContent content = response.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(testProductOptions.Count, ((List <ProductOption>)content.Value).Count);
        }
        public async Task CreateProduct_ShouldAddProductIntoDb()
        {
            string name    = Guid.NewGuid().ToString();
            var    product = new Repository.Product
            {
                Name          = name,
                Description   = "DESC",
                Price         = 333,
                DeliveryPrice = 11
            };
            await _productController.Create(product);

            var response = await _productController.SearchByName(name);

            ObjectContent content = response.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(name, ((List <Product>)content.Value)[0].Name);
        }
Пример #10
0
        public async Task <HttpResponseMessage> Update(Repository.Product product)
        {
            try
            {
                var existedProduct = await _productRepository.GetProductById(product.Id);

                if (existedProduct == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                await _productRepository.UpdateProduct(product);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public async Task DeleteProductOption_ShouldRemoveOptionFromDb()
        {
            ProductOption testProductOption;
            var           product = new Repository.Product
            {
                Name          = "testName",
                Description   = "testDesc",
                Price         = 356,
                DeliveryPrice = 13
            };

            product.Id = await _productRepository.CreateProduct(product);


            var productOption = new Repository.ProductOption
            {
                ProductId   = product.Id,
                Name        = "testOption",
                Description = "desc"
            };

            productOption.Id = await _productRepository.CreateProductOption(productOption);

            testProductOption = productOption;

            var beforeDeletingResponse = await _productController.GetOption(testProductOption.Id);

            ObjectContent content = beforeDeletingResponse.Content as ObjectContent;

            Assert.IsNotNull((ProductOption)content.Value);

            var response = await _productController.DeleteOption(testProductOption.Id);

            var responseGet = await _productController.GetOption(testProductOption.Id);

            content = responseGet.Content as ObjectContent;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNull((ProductOption)content.Value);
        }
Пример #12
0
 partial void UpdateProduct(Product instance);
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="number">Initial value of the Number property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="promoted">Initial value of the Promoted property.</param>
 /// <param name="dateEntered">Initial value of the DateEntered property.</param>
 public static Product CreateProduct(global::System.Int32 id, global::System.String name, global::System.String number, global::System.Decimal price, global::System.Boolean promoted, global::System.DateTime dateEntered)
 {
     Product product = new Product();
     product.Id = id;
     product.Name = name;
     product.Number = number;
     product.Price = price;
     product.Promoted = promoted;
     product.DateEntered = dateEntered;
     return product;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }
 public void Update(Product entity)
 {
     using (var db = new BatikStoreEntities())
     {
         var existing = db.Products.SingleOrDefault(c => c.Id == entity.Id);
         if (existing != null)
         {
             db.Products.ApplyCurrentValues(entity);
             db.SaveChanges();
         }
     }
 }
Пример #16
0
 partial void DeleteProduct(Product instance);
Пример #17
0
        static void work2()
        {
            Console.WriteLine("Start thread:{0}", Thread.CurrentThread.ManagedThreadId);
            //UnitOfWork uow = new UnitOfWork();
            //UnitOfWork.Begin("DBServer");
            //IProductRepository prodRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
            //IProductRepository prodRep = new ProductRepository("DBServer");
            //Console.WriteLine("ProductID : {0} ", prodRep.Single(x => string.IsNullOrEmpty( x.CUSTSN)).ProductID);
            //using (UnitOfWork uow = new UnitOfWork())
            //{
             IRepository<Product> prodRep = new Repository<Product>("HPIMES");
                //foreach (Product item in prodRep.Find(x => x.Model == "PCBE15YA837Y"))
                //{
                //    if (string.IsNullOrEmpty(item.CUSTSN))
                //    {
                //        item.CUSTSN = "";
                //    }
                //    Thread.Sleep(20);
                //    Console.WriteLine("thread:{0} ProductID:{1} CustomSN:{2}", Thread.CurrentThread.ManagedThreadId, item.ProductID, item.CUSTSN);
                //}

                Product p1 = new Product
                {
                    ProductID = "A35500006 ",
                    CUSTSN = "test1111",
                    Model = "PCBE15YA837Y",
                    PCBID = "",
                    Udt = DateTime.Now.AddDays(-1)
                };
                //prodRep.Delete(p);
                prodRep.Update(p1);
                
                //prodRep.Save();
                UnitOfWork.ThreadCommit();
                Console.WriteLine("Update!!");
            //}
            Console.WriteLine("End thread:{0}", Thread.CurrentThread.ManagedThreadId);
        }
Пример #18
0
 partial void InsertProduct(Product instance);