• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Entities.Product类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SportsStore.Domain.Entities.Product的典型用法代码示例。如果您正苦于以下问题:C# Product类的具体用法?C# Product怎么用?C# Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Product类属于SportsStore.Domain.Entities命名空间,在下文中一共展示了Product类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RemoveLine

        public void RemoveLine(Product product)
        {
            CartLine line = GetCartLineByProduct(product);

            if (line != default(CartLine))
                _cartLineCollections.Remove(line);
        }
开发者ID:PawelHaracz,项目名称:SportsStore,代码行数:7,代码来源:CartRepository.cs


示例2: ProductController_GetImage_CanRetrieveImageData

        public void ProductController_GetImage_CanRetrieveImageData()
        {
            // Arrange
            var prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Cat1" },
                prod,
                new Product {ProductID = 3, Name = "P3", Category = "Cat1" },

            }.AsQueryable());
            var target = new ProductController(mock.Object);

            // Act
            var result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);
        }
开发者ID:nitzerebbnitzerebb,项目名称:Lab2,代码行数:27,代码来源:ProductControllerTests.cs


示例3: ComputeToProductValue

 public decimal ComputeToProductValue(Product product)
 {
     CartLine line = GetCartLineByProduct(product);
     if (line == default(ICartRepository))
         return default(decimal);
     return line.Product.Price * line.Quantity;
 }
开发者ID:PawelHaracz,项目名称:SportsStore,代码行数:7,代码来源:CartRepository.cs


示例4: Cannot_Save_Invalid_Changes

        public void Cannot_Save_Invalid_Changes()
        {
            // Arrange
            // - Create a mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            // Arrange
            // - Crete the controller
            AdminController target = new AdminController(mock.Object);

            // Arrange
            // - Create a product
            Product product = new Product { Name = "Test" };

            // Arrange
            // - Add an error to the model state
            target.ModelState.AddModelError("error", "error");

            // Act
            // - Try to save the product
            ActionResult result = target.Edit(product, null);

            // Assert
            // - Check that the repository was not called
            mock.Verify(m => m.SaveProduct(It.IsAny<Product>()), Times.Never());

            // Assert
            // - Check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
开发者ID:Zanion,项目名称:SportsStore,代码行数:30,代码来源:AdminTests.cs


示例5: Can_Retreive_Image_Data

        public void Can_Retreive_Image_Data()
        {
            //Arrange - create a product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "test",
                ImageData = new Byte[] { },
                ImageMimeType = "image/png"

            };

            //Arrange -create a mock repository

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

            ProductController controller = new ProductController(mock.Object);

            ActionResult result = controller.GetImage(2);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);

        }
开发者ID:KannugoPrithvi,项目名称:SportStore,代码行数:32,代码来源:ImageTests.cs


示例6: AddBindings

        private void AddBindings()
        {
            // put additional bindings here
            var prods = new Product[] {
                new Product{ProductID =1, Name ="Mangos", Category="Fruit", Description="Summer gift", Price=12M},
                new Product{ProductID =2, Name ="Apples", Category="Fruit", Description="spring gift", Price=20M},
                new Product{ProductID =3, Name ="Nike Joggers", Category="Sports", Description="football fever", Price=13M},
                new Product{ProductID =4, Name ="Calculator", Category="Accounting", Description="japaniiii", Price=52M},
                new Product{ProductID =5, Name ="PC", Category="Computers", Description="I am PC", Price=92M},
                new Product{ProductID =6, Name ="MAC", Category="Computers", Description="I am  Mac", Price=120M}
            };

            //Mocking IProduct and setting what will its Products property will return
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(prods.AsQueryable());

            //Registering the Mock object with IProductRepository
            //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object);
            ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>();
            EmailSettings emailSettings = new EmailSettings
            {
                WriteAsFile
                = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false")
            };
            ninjectKernel.Bind<IOrderProcessor>()
            .To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings);

            ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>();
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:29,代码来源:NinjectControllerFactory.cs


示例7: Can_Retrieve_Image_Data

        public void Can_Retrieve_Image_Data()
        {
            Product product = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] {},
                ImageMimeType = "image/png"
            };

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1"},
                product,
                new Product {ProductID = 1, Name = "P3"}
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            ActionResult result = target.GetImage(2);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(product.ImageMimeType,((FileResult)result).ContentType);
        }
开发者ID:SHassona,项目名称:Personal-Repository,代码行数:26,代码来源:ImageTests.cs


示例8: PutProduct

        public async Task<IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != product.ProductID)
            {
                return BadRequest();
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
开发者ID:HowardHaoSun,项目名称:GITProject1,代码行数:32,代码来源:AdminProductsController.cs


示例9: Can_Retrieve_Image_Data

        public void Can_Retrieve_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // Arrange - create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);
        }
开发者ID:afrancocode,项目名称:Test,代码行数:30,代码来源:ImageTests.cs


示例10: Edit

 public ActionResult Edit(Product product, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             product.ImageMimeType = image.ContentType;
             product.ImageData = new byte[image.ContentLength];
             image.InputStream.Read(product.ImageData, 0, image.ContentLength);
         }
         else
         {
             ModelState.Clear();
         }
         // save the product
         repository.SaveProduct(product);
         // add a message to the viewbag
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         // return the user to the list
         return RedirectToAction("Index");
     }
     else
     {
         // there is something wrong with the data values
         return View(product);
     }
 }
开发者ID:KrasiGatev,项目名称:SportsStore,代码行数:27,代码来源:AdminController.cs


示例11: Cannot_Retrieve_Image_Data_For_Invalid_Id

        public void Cannot_Retrieve_Image_Data_For_Invalid_Id()
        {
            // Arrange
            Product prod = new Product
            {
                ProductId = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductId = 1, Name = "P1" },
                new Product { ProductId = 2, Name = "P2" }
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            // Act
            ActionResult result = target.GetImage(100);

            // Assert
            Assert.IsNull(result);
        }
开发者ID:nhebb,项目名称:ProMVC5,代码行数:25,代码来源:ImageTests.cs


示例12: Cant_Retrieve_NonExistint_Image_Data

        public void Cant_Retrieve_NonExistint_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // Arrange - create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(3);

            // Assert
            Assert.IsNull(result);
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:28,代码来源:ProductControllerTest.cs


示例13: SaveProduct

 public void SaveProduct(Product product)
 {
     if (product.ProductID == 0) {
         context.Products.Add(product);
     }
     context.SaveChanges();
 }
开发者ID:tofka,项目名称:Lab-3,代码行数:7,代码来源:EFProductRepository.cs


示例14: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            // Arrange
            // - Create a product
            Product prod = new Product { ProductID = 2, Name = "Test" };

            // Arrange
            // - Create a mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductID = 1, Name = "P1" },
                prod,
                new Product { ProductID = 3, Name = "P3" }
            }.AsQueryable());

            // Arrange
            // - Create the controller
            AdminController target = new AdminController(mock.Object);

            // Act
            // - Delete the product
            target.Delete(prod.ProductID);

            // Assert
            // - Ensure that the repository delete method was called with the correct product
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:Zanion,项目名称:SportsStore,代码行数:27,代码来源:AdminTests.cs


示例15: Edit

        public virtual ActionResult Edit(Product product, HttpPostedFileBase image)
        {
            var products = this.productRepository.GetProducts();

            if (products.FirstOrDefault(x => x.ProductID == product.ProductID) == null)
            {
                throw new IndexOutOfRangeException("Product not found");
            }

            if (!this.ModelState.IsValid)
            {
                return View(product);
            }

            if (image != null)
            {
                product.ImageMimeType = image.ContentType;
                product.ImageData = new byte[image.ContentLength];
                image.InputStream.Read(product.ImageData, 0, image.ContentLength);
            }

            this.productRepository.UpdateProduct(product);

            this.TempData["message"] = string.Format("The product {0} with id {1} was updated successfuly", product.Name, product.ProductID);

            return RedirectToAction(MVC.Administration.Admin.Details(product.ProductID));
        }
开发者ID:jupaol,项目名称:LearningProjects,代码行数:27,代码来源:AdminController.cs


示例16: AddItem

 public void AddItem(Product product, int quantity)
 {
     CartLine line = lineCollection.FirstOrDefault(p => p.Product.Id == product.Id);
     if (line == null)
         lineCollection.Add(new CartLine() {Product = product, Quantity = quantity});
     else
         line.Quantity += quantity;
 }
开发者ID:MichalZawadzki,项目名称:SportsStore,代码行数:8,代码来源:Cart.cs


示例17: Save

 public void Save(Product product)
 {
     if (product.ProductID == 0)
         context.Products.Add(product);
     else
         context.Entry(product).State = System.Data.EntityState.Modified;
     context.SaveChanges();
 }
开发者ID:nitzerebbnitzerebb,项目名称:Lab2,代码行数:8,代码来源:EFProductRepository.cs


示例18: DeleteProduct

 public void DeleteProduct(Product product)
 {
     Product prod = context.Products.Find(product.ProductID);
     if (prod != null) {
         context.Products.Remove(prod);
         context.SaveChanges();
     }
 }
开发者ID:eugeniomiro,项目名称:SportsStore,代码行数:8,代码来源:EFProductRepository.cs


示例19: AddItem

 public void AddItem(Product product, int quantity)
 {
     var line = lines.FirstOrDefault(x => x.Product.ProductID == product.ProductID);
     if (line == null)
         lines.Add(new CartLine { Product = product, Quantity = quantity });
     else
         line.Quantity += quantity;
 }
开发者ID:astrateg,项目名称:SportsStore,代码行数:8,代码来源:Cart.cs


示例20: Edit

 public ActionResult Edit(Product product) {
     if (ModelState.IsValid) {
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         return RedirectToAction("Index");
     } else {
         return View(product);
     }                       
 }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:9,代码来源:AdminController.cs



注:本文中的SportsStore.Domain.Entities.Product类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Entities.ShippingDetails类代码示例发布时间:2022-05-26
下一篇:
C# Entities.Cart类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap