public async Task <IActionResult> Create([FromForm] CreateProductCategoryInput input) { var absolutePath = Path.Combine(_webHostEnvironment.WebRootPath, ProductCategory.IMAGE_PATH); await _productCateService.Create(input, absolutePath); return(Ok()); }
public void Create_ProductCategoryNull_ThrowsArgumentNullException() { //Arrange ProductCategory invalidProductCategory = null; Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); IProductCategoryService productCategoryService = new ProductCategoryService(productCategoryRepository.Object); //Act Action actual = () => productCategoryService.Create(invalidProductCategory); //Assert Assert.Throws <ArgumentNullException>(actual); }
public void Create_IdSpecified_ThrowsArgumentException() { //Arrange ProductCategory invalidProductCategory = new ProductCategory { Id = 1, Name = "Accessories" }; Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); IProductCategoryService productCategoryService = new ProductCategoryService(productCategoryRepository.Object); //Act Action actual = () => productCategoryService.Create(invalidProductCategory); //Assert Assert.Throws <ArgumentException>(actual); }
public async void Create() { var mock = new ServiceMockFacade <IProductCategoryRepository>(); var model = new ApiProductCategoryRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductCategory>())).Returns(Task.FromResult(new ProductCategory())); var service = new ProductCategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductCategoryMapperMock, mock.DALMapperMockFactory.DALProductCategoryMapperMock, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock); CreateResponse <ApiProductCategoryResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductCategoryRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductCategory>())); }
protected void Page_Load(object sender, EventArgs e) { //是回发触发条件 if (IsPostBack) { string category = Request["category"]; string summary = Request["summary"]; string remark = Request["remark"]; bool recommend = Convert.ToBoolean(Request["recommend"]); BLL.ProductCategoryService service = new ProductCategoryService(); ProductCategoryEntity entity = new ProductCategoryEntity(); entity.Category = category; entity.Remark = remark; entity.Summary = summary; entity.CreatedTime = DateTime.Now; entity.ModifiedTime = DateTime.Now; entity.ParentId = Convert.ToInt32(Request["parentid"]); entity.deleted = false; entity.isRecommend = recommend; bool success = service.Create(entity); if (success) { Response.Redirect("/Pages/ProductCategory/List.aspx"); } else { Response.Write("<script>添加失败!</script>"); } } else { ProductCategoryService service = new ProductCategoryService(); parent_list = service.GetList(new ProductCategoryEntity { ParentId = 0, }, new Entity.BussinessModel.Pagination { IsPaging = false }); } }
public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryModel ProductCategoryModel) { return(CreateHttpResponse(request, () => { var a = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var ProductCategoryService = new ProductCategoryService(); ProductCategoryService.Create(ProductCategoryModel); //var responseData = true; response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public void Create_ProductCategoryValid_ReturnsCreatedProductCategoryWithId() { //Arrange ProductCategory validProductCategory = new ProductCategory { Name = "Accessories" }; ProductCategory expected = new ProductCategory { Id = 1, Name = validProductCategory.Name }; Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Create(validProductCategory)). Returns(expected); IProductCategoryService productCategoryService = new ProductCategoryService(productCategoryRepository.Object); //Act ProductCategory actual = productCategoryService.Create(validProductCategory); //Assert Assert.Equal(expected, actual); }
public void ProductCategoryServiceCRUDTest() { var context = new NoodleDbContext("NoodleDb"); IProductCategoryService service = new ProductCategoryService(context); var id = Guid.NewGuid(); var productId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var record = new ProductCategory { Id = id, ProductId = productId, CategoryId = categoryId }; service.Create(record); record.CategoryId = Guid.NewGuid(); record.ProductId = Guid.NewGuid(); service.Update(record); var record2 = service.GetById(id); Assert.AreEqual(record.Id, record2.Id); Assert.AreEqual(record.CategoryId, record2.CategoryId); Assert.AreEqual(record.ProductId, record2.ProductId); service.Delete(record.Id); var record3 = service.GetById(id); Assert.IsNull(record3); }
public void Seed() { // Look for any Product. //if (!_db.ProductOption.Any()) //{ // IProductOptionService _productOptionService = new ProductOptionService(_db); // List<ProductOption> productOptions = new List<ProductOption>(); // { // ProductOption productOption1 = new ProductOption(); // { // productOption1.CreatedBy = "Sameera"; // productOption1.CreatedDate = DateTime.Now; // productOption1.Name = "Size"; // productOption1.Option = "Small"; // productOption1.IsActive = true; // _productOptionService.Create(productOption1); // } // ProductOption productOption2 = new ProductOption(); // { // productOption2.CreatedBy = "Sameera"; // productOption2.CreatedDate = DateTime.Now; // productOption2.Name = "Size"; // productOption2.Option = "X-Small"; // productOption2.IsActive = true; // _productOptionService.Create(productOption2); // } // ProductOption productOption3 = new ProductOption(); // { // productOption3.CreatedBy = "Sameera"; // productOption3.CreatedDate = DateTime.Now; // productOption3.Name = "Size"; // productOption3.Option = "Medium"; // productOption3.IsActive = true; // _productOptionService.Create(productOption3); // } // ProductOption productOption4 = new ProductOption(); // { // productOption4.CreatedBy = "Sameera"; // productOption4.CreatedDate = DateTime.Now; // productOption4.Name = "Size"; // productOption4.Option = "Large"; // productOption4.IsActive = true; // _productOptionService.Create(productOption4); // } // } //} if (!_db.ProductCategory.Any()) { IProductCategoryService _productCategoryService = new ProductCategoryService(_db); List <ProductCategory> productCategories = new List <ProductCategory>(); { ProductCategory productCategory1 = new ProductCategory(); { productCategory1.CreatedBy = "Sameera"; productCategory1.CreatedDate = DateTime.Now; productCategory1.IsActive = true; productCategory1.ProductCategoryName = "Default"; _productCategoryService.Create(productCategory1); } ProductCategory productCategory2 = new ProductCategory(); { productCategory2.CreatedBy = "Sameera"; productCategory2.CreatedDate = DateTime.Now; productCategory2.IsActive = true; productCategory2.ProductCategoryName = "Juice"; _productCategoryService.Create(productCategory2); } ProductCategory productCategory3 = new ProductCategory(); { productCategory3.CreatedBy = "Sameera"; productCategory3.CreatedDate = DateTime.Now; productCategory3.IsActive = true; productCategory3.ProductCategoryName = "Water"; _productCategoryService.Create(productCategory3); } ProductCategory productCategory4 = new ProductCategory(); { productCategory4.CreatedBy = "Sameera"; productCategory4.CreatedDate = DateTime.Now; productCategory4.IsActive = true; productCategory4.ProductCategoryName = "Coffee"; _productCategoryService.Create(productCategory4); } } } if (!_db.ProductType.Any()) { List <ProductType> productTypes = new List <ProductType>(); { IProductTypeService _productTypeService = new ProductTypesService(_db); ProductType productType1 = new ProductType(); { productType1.CreatedBy = "Sameera"; productType1.CreatedDate = DateTime.Now; productType1.ProductTypeName = "Default Type"; _productTypeService.Create(productType1); } ProductType productType2 = new ProductType(); { productType2.CreatedBy = "Sameera"; productType2.CreatedDate = DateTime.Now; productType2.ProductTypeName = "Convenience products"; _productTypeService.Create(productType2); } ProductType productType3 = new ProductType(); { productType3.CreatedBy = "Sameera"; productType3.CreatedDate = DateTime.Now; productType3.ProductTypeName = "Shopping products"; _productTypeService.Create(productType3); } ProductType productType4 = new ProductType(); { productType4.CreatedBy = "Sameera"; productType4.CreatedDate = DateTime.Now; productType4.ProductTypeName = "Speciality products"; _productTypeService.Create(productType4); } ProductType productType5 = new ProductType(); { productType5.CreatedBy = "Sameera"; productType5.CreatedDate = DateTime.Now; productType5.ProductTypeName = "Unsought products"; _productTypeService.Create(productType5); } } } if (!_db.Product.Any()) { IProductService _productService = new ProductService(_db); List <Product> product = new List <Product>(); { Product product1 = new Product(); { product1.ProductName = "Test t-shirt"; product1.ProductImage = @"\images\ProductImage\default_image.png"; product1.Sku = "“Test0001"; product1.Variants = "“Test0001_s"; product1.ProductTypeIdFk = 1; product1.ProductCategoryIdFk = 1; product1.OnHand = true; product1.Fullfilled = false; product1.Instock = 10; product1.CreatedBy = "Sameera"; product1.CreatedDate = DateTime.Now; product1.IsActive = true; _productService.Create(product1); } Product product2 = new Product(); { product2.ProductName = "Test Soap"; product2.ProductImage = @"\images\ProductImage\default_image.png"; product2.Sku = "“Test0001"; product2.Variants = "“Test0001_m"; product2.ProductTypeIdFk = 1; product2.ProductCategoryIdFk = 1; product2.OnHand = true; product2.Fullfilled = false; product2.Instock = 10; product2.CreatedBy = "Sameera"; product2.CreatedDate = DateTime.Now; product2.IsActive = true; _productService.Create(product2); } Product product3 = new Product(); { product3.ProductName = "Test Coffee"; product3.ProductImage = @"\images\ProductImage\default_image.png"; product3.Sku = "“Test0002"; product3.Variants = "“Test0002_m"; product3.ProductTypeIdFk = 1; product3.ProductCategoryIdFk = 1; product3.OnHand = true; product3.Fullfilled = false; product3.Instock = 10; product3.CreatedBy = "Sameera"; product3.CreatedDate = DateTime.Now; product3.IsActive = true; _productService.Create(product3); } }; } //if (!_db.User.Any()) //{ // List<User> users = new List<User>(); // { // User user1 = new User(); // { // user1.FirstName = "Sameera"; // user1.LastName = "Akhtar"; // user1.Username = "******"; // IUserService userService = new UserService(_db); // userService.Create(user1, "sameera1"); // } // User user2 = new User(); // { // user2.FirstName = "Urooj"; // user2.LastName = "Irfat"; // user2.Username = "******"; // IUserService userService = new UserService(_db); // userService.Create(user2, "sameera1"); // } // User user3 = new User(); // { // user3.FirstName = "Zehra"; // user3.LastName = "Aamir"; // user3.Username = "******"; // IUserService userService = new UserService(_db); // userService.Create(user3, "sameera1"); // } // } //} if (!_db.Role.Any()) { IRoleService roleService = new RoleService(_db); List <Role> roles = new List <Role>(); { Role role1 = new Role(); { role1.CreatedBy = "Seeded"; role1.CreatedDate = DateTime.Now; role1.RoleName = "Admin"; role1.IsActive = true; } Role role2 = new Role(); { role2.CreatedBy = "Seeded"; role2.CreatedDate = DateTime.Now; role2.RoleName = "Admin"; role2.IsActive = true; } Role role3 = new Role(); { role3.CreatedBy = "Seeded"; role3.CreatedDate = DateTime.Now; role3.RoleName = "Admin"; role3.IsActive = true; } } } }
public ActionResult <ProductCategory> Create(ProductCategory productCategory) { _productCategoryService.Create(productCategory); return(CreatedAtRoute("GetProductCategory", new { id = productCategory.Id.ToString() }, productCategory)); }