Exemplo n.º 1
0
        public void FindByIdTest()
        {
            ProductPhotoRepository repository = new ProductPhotoRepository();
            var photos = repository.FindById(2);

            Assert.IsTrue(photos.Count() > 0);
        }
        public ProductList FindByName(string ProductName)
        {
            string[] sizes = new[] { "XS", "S", "M", "L", "XL", "XXL" };
            ProductPhotoRepository productPhotoRepository = new ProductPhotoRepository();
            var items = repository.FindByName(ProductName).ToList();

            items = items.Where((x) => x.Downtime == null).ToList();
            ProductList productList = new ProductList()
            {
                ProductName    = items[0].ProductName,
                UnitPrice      = decimal.Round(items[0].UnitPrice),
                ProductDetails = items[0].ProductDetails,
                Size           = items.Select(x => x.Size).Distinct().OrderBy(x => sizes.Contains(x)?"0":"1").ThenBy(x => Array.IndexOf(sizes, x)).ThenBy(x => x).ToList(),
                Color          = items.Select(x => x.Color).Distinct().ToList(),
            };

            productList.PhotoPath = new List <string>();
            foreach (var item in items)
            {
                foreach (var photo in productPhotoRepository.FindById(item.ProductID))
                {
                    if (productList.PhotoPath.Any((x) => x == photo.PhotoPath) == false)
                    {
                        productList.PhotoPath.Add(photo.PhotoPath);
                    }
                }
            }
            return(productList);
        }
Exemplo n.º 3
0
        public void DeleteTest()
        {
            ProductPhotoRepository repository = new ProductPhotoRepository();
            ProductPhoto           model      = new ProductPhoto
            {
                PhotoID = 2
            };

            repository.Delete(model);
            var photos = repository.FindById(1);

            Assert.IsTrue(photos.Count() > 0);
        }
Exemplo n.º 4
0
        public void CreateTest()
        {
            ProductPhotoRepository repository = new ProductPhotoRepository();
            ProductPhoto           model      = new ProductPhoto
            {
                ProductID = 1,
                PhotoPath = "url"
            };

            repository.Create(model);
            var photos = repository.FindById(1);

            Assert.IsTrue(photos.Count() == 4);
        }
Exemplo n.º 5
0
        public void UpdateTest()
        {
            ProductPhotoRepository repository = new ProductPhotoRepository();
            ProductPhoto           model      = new ProductPhoto
            {
                PhotoID   = 1,
                ProductID = 1,
                PhotoPath = "a"
            };

            repository.Update(model);
            var photos = repository.FindById(1);

            Assert.IsTrue(photos.Count() > 0);
        }
Exemplo n.º 6
0
 public IEnumerable <ProductPhoto> FindById(int ProductID)
 {
     return(repository.FindById(ProductID));
 }