public void Can_Retrieve_Image_Data()
        {
            var prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ThumbNailPhoto = new byte[] {},
                ThumbnailPhotoFileName = "image/png"
            };

            var mosk = new Mock<IProductRepository>();
            mosk.Setup(m => m.Products).Returns(new[]
            {
                new Product {ProductID = 1, Name = "P1"},
                prod,
                new Product {ProductID = 3, Name = "P3"}

            }.AsQueryable);

            var target = new ProductController(mosk.Object);
            var result = target.GetImage(2);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result,typeof(FileResult));
            Assert.AreEqual(prod.ThumbnailPhotoFileName,result.ContentType);
        }
Exemple #2
0
 public object Get(Product request)
 {
     ProductResponse response = new ProductResponse();
     response.MaterialTypes = Db.Select<MaterialType>();
     var materials = Db.Select<Material>();
     foreach (var materialType in response.MaterialTypes)
     {
         materialType.Materials = materials.Where(item => item.TypeID == materialType.ID).ToList();
     }
     response.Categories = Db.Select<Category>();
     response.Materials = materials;
     response.Goods = request.ID > 0 ? Db.SingleById<Goods>(request.ID) : new Goods() { Materials =new List<GoodsMaterial>()};
     foreach (var goodsMaterial in response.Goods.Materials)
     {
      var t=
             response.MaterialTypes.FirstOrDefault(
                 item => item.Materials.Any(m => m.ID == goodsMaterial.MaterialID));
         if (t!=null)
         {
             goodsMaterial.MaterialTypeName = t.Name;
             goodsMaterial.MaterialTypeID = t.ID;
         }
     }
     return response;
 }
Exemple #3
0
 public OrderItem(Product a_product, int a_quantity, decimal a_unitPrice, IDictionary<string, string> a_preferences)
 {
     Product = a_product;
     Quantity = a_quantity;
     UnitPrice = a_unitPrice;
     Preferences = a_preferences;
 }
Exemple #4
0
        public void CanStoreAProduct()
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<CoffeeShopContext>());
            long id;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var repository = new Repository<Product>(session);
                var product = new Product
                {
                    Name = "Coffee 1",
                    Price = 10.4m
                };

                repository.MakePersistent(product);
                id = product.Id;
                tx.Commit();
            }

            using (var session = m_sessionFactory.OpenSession())
            using (session.BeginTransaction())
            {
                var repository = new Repository<Product>(session);
                Product product = repository.GetById(id);

                product.Satisfy(p => p.Name == "Coffee 1" && p.Price == 10.4m);
            }
        }
Exemple #5
0
 public void addMenuProduct()
 {
     decimal expectedMenuProductPrice = 6;
     Product p = new Product { Description = "Latte" };
     Menu m = new Menu();
     MenuProduct mp =  m.AddMenuProduct(p, expectedMenuProductPrice);
     Assert.AreEqual(expectedMenuProductPrice, mp.Price);
 }
        public void SetUp()
        {
            _product = new Product("Test", "A product created during an intergration test", 19.99);
            _productRepository = ContainerSpecification.Resolve<IWritableRepository<Product>>();
            _database = ContainerSpecification.Resolve<MongoDatabase>();
            _collectionName = typeof (Product).Name.ToLower();

            _collection = _database.GetCollection<Product>(_collectionName);
        }
        public void GivenAProductWhenFindIsCalledThenTheExpectedProductShouldBeReturned()
        {
            var product = new Product("Test", "A product created during an intergration test", 19.99);
            _collection.Save(product);

            var persistedProduct = _productRepository.Find(product.Id);

            Assert.That(persistedProduct.Id, Is.EqualTo(product.Id));
        }
            public static int Save(IDomainAccess ds, ProductionDto.Product dto)
            {
                var p = new Product
                {
                    ProductName = dto.ProductName,
                    ProductCategory = ds.Load<ProductCategory>(dto.ProductCategoryId)
                };

                return (int)ds.Save(p);
            }
Exemple #9
0
        public static externalDTO.Product MapFromDomain(internalDTO.Product product)
        {
            var res = product == null ? null : new externalDTO.Product
            {
                Id          = product.Id,
                ProductName = product.ProductName.Translate(),
                ProductCode = product.ProductCode,
                Price       = product.Price
            };

            return(res);
        }
Exemple #10
0
 public Product AddProduct(decimal price, string description)
 {
     foreach (var p in Products)
         {
             if (p.Description.Equals(description))
             {
                 throw new BusinessRuleException("Product name must be unique");
             }
         }
     var product = new Product(this, price, description);
     this.Products.Add(product);
     return product;
 }
        public void GivenThreeProductsWhenTwoOfThoseProductsHaveCostHigherThanTwentyThenQueryingForProductsWithACostHigherThanTwentyShouldReturnTwoOfTheThreeProducts()
        {
            var productOne = new Product("Test", "A product created during an intergration test", 19.99);
            var productTwo = new Product("Test", "A product created during an intergration test", 100.00);
            var productThree = new Product("Test", "A product created during an intergration test", 20.01);

            _collection.Save(productOne);
            _collection.Save(productTwo);
            _collection.Save(productThree);

            var highPricedProducts = _productRepository.Query().Where(p => p.Cost > 20.00);

            Assert.That(highPricedProducts.Count(), Is.EqualTo(2));
        }
        private void PopulateCollectionWithRandomProducts(int count)
        {
            var start = DateTime.Now;
            Console.WriteLine("Starting insert of {0} random products at {1}", count, start.ToShortTimeString());

            while (count > 0)
            {
                var product = new Product(Strings.GenerateAlphaNumericString(5, 25), Strings.GenerateAlphaNumericString(10, 250), Numbers.Double(max: 5000000));
                _collection.Save(product);
                count--;
            }

            var difference = DateTime.Now - start;
            Console.WriteLine("Finshed insert, took {0} milliseconds", difference.TotalMilliseconds);
        }
Exemple #13
0
        public static externalDTO.Product MapFromDomain(internalDTO.Product product)
        {
            var res = product == null ? null : new externalDTO.Product()
            {
                Id = product.Id,
                RouteOfAdministrationId = product.RouteOfAdministrationId,
                RouteOfAdministration   = RouteOfAdministrationMapper.MapFromDomain(product.RouteOfAdministration),
                ProductClassificationId = product.ProductClassificationId,
                ProductClassification   = ProductClassificationMapper.MapFromDomain(product.ProductClassification),
                ProductNameId           = product.ProductNameId,
                ProductName             = ProductNameMapper.MapFromDomain(product.ProductName)
            };

            return(res);
        }
Exemple #14
0
        public void IfTheProductDoesNotAllowCustomization_ThenReturnInvalidMessage()
        {
            var product = new Product
                              {
                                  Name = "latte",
                                  Customizations = {new Customization{Name = "size", PossibleValues = {"medium","large"}}}
                              };

            var order = new Order();
            order.AddItem(new OrderItem
                            {
                                Quantity = 1,
                                Product = product,
                                Preferences = { { "milk", "lot" } }
                            });
            order.GetErrorMessages()
                .Should().Contain("Item 0: The product latte does not have a customization: milk/lot.");
        }
Exemple #15
0
        public Product Add(EasyHardwareEntities context, Domain.Product product)
        {
            ICollection <Category> categories = new List <Category>();

            if (product.Categories.Any())
            {
                foreach (Category category in product.Categories)
                {
                    categories.Add(context.Category.Single(x => x.Id == category.Id));
                }

                product.Categories = categories;
            }

            // add product to context
            context.Product.Add(product);
            // save changes
            context.SaveChanges();
            return(product);
        }
Exemple #16
0
        public void CanStoreAnOrderWithPayment()
        {
            long id;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var productRepository = new Repository<Product>(session);
                var product = new Product { Name = "Latte", Price = 10.4m };
                productRepository.MakePersistent(product);

                var orderRepository = new Repository<Order>(session);
                var order = new Order
                {
                    Date = new DateTime(2011, 1, 1),
                    Location = Location.InShop,
                };
                order.AddItem(new OrderItem
                                    {
                                       Product = product,
                                       UnitPrice = 10.4m,
                                       Preferences =
                                           {
                                               {"Milk", "skim"},
                                               {"Size", "small"}
                                           }
                                    });
                orderRepository.MakePersistent(order);
                order.Pay("1234", "jose");
                id = order.Id;
                tx.Commit();
            }

            using (var context = m_sessionFactory.OpenSession())
            {
                var repository = new Repository<Order>(context);
                var order = repository.GetById(id);
                order.Satisfy(a_o => a_o.Location == Location.InShop
                                && a_o.Items.Count() == 1
                                && a_o.Payment != null);
            }
        }
Exemple #17
0
        public static DAL.App.DTO.DomainLikeDTO.Product MapFromDomain(Domain.Product product)
        {
            var res = product == null ? null : new DAL.App.DTO.DomainLikeDTO.Product
            {
                Id = product.Id,
                ManuFacturerItemCode      = product.ManuFacturerItemCode?.Translate(),
                ShopCode                  = product.ShopCode?.Translate(),
                ProductName               = product.ProductName?.Translate(),
                BuyPrice                  = product.BuyPrice,
                PercentageAddedToBuyPrice = product.PercentageAddedToBuyPrice,
                SellPrice                 = product.SellPrice,
                Quantity                  = product.Quantity,
                Weight = product.Weight?.Translate(),
                Length = product.Length?.Translate()
            };

            if (product?.Manufacturer != null)
            {
                res.ManuFacturerId = product.ManuFacturerId;
                res.Manufacturer   = ManuFacturerMapper.MapFromDomain(product.Manufacturer);
                res.InventoryId    = product.InventoryId;
                res.Inventory      = InventoryMapper.MapFromDomain(product.Inventory);
                res.ShopId         = product.ShopId;
                res.Shop           = ShopMapper.MapFromDomain(product.Shop);
            }

            if (product?.Comments != null)
            {
                res.Comments = product.Comments.Select(e => new DAL.App.DTO.DomainLikeDTO.Comment()
                {
                    CommentTitle = e.CommentTitle.Translate(),
                    CommentBody  = e.CommentBody.Translate(),
                    Id           = e.Id
                }).ToList();
            }

            return(res);
        }
Exemple #18
0
        public void CanChangeStatus()
        {
            long id;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var productRepository = new Repository<Product>(session);
                var product = new Product {Name = "Latte", Price = 10.4m};
                productRepository.MakePersistent(product);

                var orderRepository = new Repository<Order>(session);
                var order = new Order
                                {
                                    Date = new DateTime(2011, 1, 1),
                                    Location = Location.InShop,
                                };
                order.AddItem(new OrderItem
                                  {
                                      Product = product,
                                      UnitPrice = 10.4m,
                                      Preferences =
                                          {
                                              {"Milk", "skim"},
                                              {"Size", "small"}
                                          }
                                  });
                orderRepository.MakePersistent(order);
                order.Cancel("cascasas");
                id = order.Id;
                tx.Commit();
            }
            using (var session = m_sessionFactory.OpenSession())
            using (session.BeginTransaction())
            {
                session.Get<Order>(id).Status.Should().Be.EqualTo(OrderStatus.Canceled);
            }
        }
Exemple #19
0
 public void Pop(Product one)
 {
     goods.Remove(one);
 }
Exemple #20
0
 public AddProductForm()
 {
     InitializeComponent();
     prod = new Product();
     editMode = "create";
 }
        public void SetUp()
        {
            _title = Strings.GenerateAlphaNumericString();
            _description = Strings.GenerateAlphaNumericString();
            _cost = Numbers.Double();
            _reviewTitle = Strings.GenerateAlphaNumericString();
            _reviewContent = Strings.GenerateAlphaNumericString();
            _reviewAuthor = Names.FullName();
            _reviewScore = Numbers.Int(1, 5);

            _review = new Review(_reviewAuthor, _reviewTitle, _reviewContent, _reviewScore);
            _product = new Product(_title, _description, _cost);
        }
 public void Post(Product product)
 {
     int i = 10;
 }
Exemple #23
0
 public MenuProduct AddMenuProduct(Guid menuId, Product product, decimal price)
 {
     var menu = FetchMenu(menuId);
     return menu.AddMenuProduct(product, price);
 }
Exemple #24
0
 public MenuProduct AddMenuProduct(Product product, decimal price)
 {
     var menuProduct = new MenuProduct(this, product, price);
     this.MenuProducts.Add(menuProduct);
     return menuProduct;
 }
Exemple #25
0
        public void VersionNumberGrowOnEachUpdate()
        {
            long id;
            int version;
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var productRepository = new Repository<Product>(session);
                var product = new Product {Name = "Latte", Price = 10.4m};
                productRepository.MakePersistent(product);

                var orderRepository = new Repository<Order>(session);
                var order = new Order
                                {
                                    Date = new DateTime(2011, 1, 1),
                                    Location = Location.InShop,
                                };
                order.AddItem(new OrderItem
                                  {
                                      Product = product,
                                      UnitPrice = 10.4m,
                                      Preferences =
                                          {
                                              {"Milk", "skim"},
                                              {"Size", "small"}
                                          }
                                  });
                orderRepository.MakePersistent(order);
                order.Pay("1234", "jose");
                id = order.Id;

                tx.Commit();
                version = order.Version;
            }
            using (var session = m_sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var order = session.Get<Order>(id);
                order.Location = Location.TakeAway;
                tx.Commit();

                order.Version.Should().Be.GreaterThan(version);
            }
        }
 public void WhenSameTransientShouldBeTrue()
 {
     var product = new Product();
      product.Equals(product).Should().Be(true);
 }
 private void CreatePersistedProducts()
 {
     var product = new Product { Name = "MockProduct" };
     this.productRepository.SaveOrUpdate(product);
     FlushSessionAndEvict(product);
 }
Exemple #28
0
 public bool isAPlace(Product some)
 {
     float free = this.capacity - this.Busy();
        try
        {
        if (free<some.volume) return true; else return false;
        }
        catch (Exception) { return false; }
 }
Exemple #29
0
 public void Update(Product one)
 {
 }
Exemple #30
0
 public bool Push(Product one)
 {
     try
        {
        if (!this.isAPlace(one))
        {
            this.goods.Add(one);
            return true;
        }
        else return false;
        }
        catch (Exception) { return false; }
 }
Exemple #31
0
 public AddProductForm(Product p)
 {
     prod = p;
     InitializeComponent();
     editMode = "edit";
 }
 public void WhenComparingSameInstanceOfPersistedEntityThenShouldBeTrue()
 {
     var product = new Product { Id = 123 };
      product.Equals(product)
     .Should().Be(true);
 }