public void Update_Option_Without_Text_Error() { Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict); Option option = new Option(); option.Text = null; mockRepository.Setup(s => s.Update(option)) .Throws(new ArgumentNullException(nameof(option.Text))); option.Text = String.Empty; mockRepository.Setup(s => s.Update(option)) .Throws(new ArgumentNullException(nameof(option.Text))); OptionService service = new OptionService(mockRepository.Object); Option optionToUpdate = new Option { Text = String.Empty }; ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => service.Update(optionToUpdate)); Assert.NotNull(ex); Assert.Equal(nameof(option.Text), ex.ParamName); optionToUpdate = new Option { Text = null }; ex = Assert.Throws <ArgumentNullException>(() => service.Update(optionToUpdate)); Assert.NotNull(ex); Assert.Equal(nameof(option.Text), ex.ParamName); mockRepository.Verify(m => m.Update(It.IsAny <Option>()), Times.AtLeast(2)); }
public async Task UpdateOption() { // Arrange var option = new OptionUpdateModel { Id = 5, Text = "Updated text" }; // Act var result = await _service.Update(option); // Assert result.Should().NotBeNull(); result.Should().BeAssignableTo <OptionBaseModel>(); result.Id.Should().Be(option.Id); result.Text.Should().Be(option.Text); }
public async Task UpdateOption() { // Arrange var option = new OptionUpdateModel { Id = 1, OptionDate = DateTime.Today, Venue = "VisualStudio 2019" }; // Act var result = await _service.Update(option); // Assert result.Should().NotBeNull(); result.Should().BeAssignableTo <OptionModelBase>(); result.Id.Should().Be(option.Id); result.OptionDate.Should().Be(option.OptionDate); result.Venue.Should().Be(option.Venue); }
public void _005_TestOptionUpdate() { var ServiceObject = new OptionService(); var ArgsObject = new OptionUpdateServiceOptions(); ArgsObject.option_id = option_id; ArgsObject.option_name = "Test Option 123"; ArgsObject.option_value_name = "Test Option Value 123"; ArgsObject.option_value_surcharge = (decimal)1.00; var result = ServiceObject.Update(ArgsObject); Assert.IsInstanceOf <TwoCheckoutResponse>(result); }
public async Task UpdateOption() { // Arrange var option = new OptionUpdateModel { Id = 1, Text = "Option 1", Order = 1, QuestionId = 1 }; // Act var result = await _service.Update(option); // Assert result.Should().NotBeNull(); result.Should().BeAssignableTo <OptionModelBase>(); result.Id.Should().Be(option.Id); result.Text.Should().Be(option.Text); result.Order.Should().Be(option.Order); result.QuestionId.Should().Be(option.QuestionId); }
public async Task <IActionResult> Put(int id, [FromBody] OptionsUpdateModel model) { if (ModelState.IsValid) { model.Id = id; var result = await _service.Update(model); return(result != null ? (IActionResult)Ok(result) : NoContent()); } return(BadRequest()); }
public ActionResult delete(int id) { Variant variant = variantService.GetByPrimaryKey(id); try { int numVariantOfProduct = variantService.CountByProductID(variant.ProductID); if (numVariantOfProduct == 1) { variant.Option1 = variant.VariantTittle = "Default Title"; variant.Option2 = null; variant.Option3 = null; variant.ImageID = null; variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); variantService.Update(variant); List <TblOption> optionOfProduct = optionService.GetByProductID(variant.ProductID); if (optionOfProduct != null && optionOfProduct.Count > 0) { for (int i = 0; i < optionOfProduct.Count; i++) { if (i == 0) { TblOption option = optionOfProduct[i]; option.OptionName = "Title"; option.CreatedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); option.OptionValue = "Default Title"; option.Position = 1; optionService.Update(option); } else { optionService.DeleteByPrimary(optionOfProduct[i].OptionID); } } } } else { variantService.DeleteByPrimary(id); } optionService.UpdateOptionOfProduct(variant.ProductID); return(RedirectToAction("detail", "products", new { id = variant.ProductID, strMessage = "Variant1" })); } catch (Exception ex) { LogService.WriteException(ex); } return(RedirectToAction("detail", "products", new { id = variant.ProductID, strMessage = "Variant0" })); }
public void Update_Option_NonExistent_Error() { Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict); Option option666 = new Option { Id = 666, Text = "new text. 666" }; mockRepository.Setup(s => s.Update(option666)) .Throws(new DbUpdateException("The current option does not exist.", new NullReferenceException())); Option option = new Option { Text = "new text. option without id" }; mockRepository.Setup(s => s.Update(option)) .Throws(new DbUpdateException("The current option does not exist.", new NullReferenceException())); OptionService service = new OptionService(mockRepository.Object); Option optionToUpdate = new Option { Id = 666, Text = "new text. 666" }; DbUpdateException ex = Assert.Throws <DbUpdateException>(() => service.Update(optionToUpdate)); Assert.NotNull(ex); Assert.Equal("The current option does not exist.", ex.Message); optionToUpdate = new Option { Text = "new text. option without id" }; ex = Assert.Throws <DbUpdateException>(() => service.Update(optionToUpdate)); Assert.NotNull(ex); Assert.Equal("The current option does not exist.", ex.Message); mockRepository.Verify(m => m.Update(It.IsAny <Option>()), Times.AtLeast(2)); }
public void Update_Option_Success() { Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict); mockRepository.Setup(s => s.Update(new Option { Id = 1, Text = "Updated" })) .Callback <Option>(o => o.Text = "Updated"); OptionService service = new OptionService(mockRepository.Object); var expected = new Option { Id = 1, Text = "Updated" }; var actual = service.Update(new Option { Id = 1, Text = "Updated" }); Assert.NotNull(actual); Assert.Equal(expected, actual); mockRepository.Verify(m => m.Update(It.IsAny <Option>()), Times.Once()); }
public void Update_Option_With_Text_Greater_Than_Max_Size_Error() { Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict); Option option = new Option { Id = 1, Text = new String('B', 201) }; mockRepository.Setup(s => s.Update(option)) .Throws(new ArgumentOutOfRangeException(nameof(option.Text))); OptionService service = new OptionService(mockRepository.Object); Option optionToUpdate = new Option { Id = 1, Text = new String('B', 201) }; ArgumentOutOfRangeException ex = Assert.Throws <ArgumentOutOfRangeException>(() => service.Update(optionToUpdate)); Assert.NotNull(ex); Assert.Equal(nameof(option.Text), ex.ParamName); mockRepository.Verify(m => m.Update(It.IsAny <Option>()), Times.Once()); }
public ActionResult detail(Product product) { if (ModelState.IsValid) { try { if (CheckInput(product)) { if (product.SupplierID == 0) { product.SupplierID = null; } if (product.ProductStyleID == 0) { product.ProductStyleID = null; } product.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); if (!string.IsNullOrEmpty(product.Tags)) { string[] tags = product.Tags.Split(','); foreach (var item in tags) { if (!tagService.CheckExistTag(item, (int)Common.TableName.Product)) { Tag tag = new Tag(); tag.TagName = item; tag.TableNameID = (int)Common.TableName.Product; int tagID = tagService.Insert(tag); } } } bool flg = productService.Update(product); if (flg) { LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Update, product.ProductID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, product.ProductName); } // update variant defaul || update list variant if (!product.AutoGenerate) { // variant default if (product.Variant.VariantID > 0) { Variant variant = variantService.GetByPrimaryKey(product.Variant.VariantID); variant.VariantPrice = product.Variant.VariantPrice; variant.CompareWithPrice = product.Variant.CompareWithPrice; variant.Textable = product.Variant.Textable; variant.VariantSKU = product.Variant.VariantSKU; variant.VariantBarcode = product.Variant.VariantBarcode; variant.VariantWeight = product.Variant.VariantWeight; variant.WeightUnit = product.Variant.WeightUnit; variant.RequireShipping = product.Variant.RequireShipping; variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); bool updateVariant = variantService.Update(variant); } // has list variant else { if (product.Variants != null && product.Variants.Count > 0) { for (int i = 0; i < product.Variants.Count; i++) { product.Variants[i].VariantTittle = variantService.GetVariantTittle(product.Variants[i]); product.Variants[i].ProductID = product.ProductID; product.Variants[i].ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); bool updateVariantFlg = variantService.Update(product.Variants[i]); } } } } // add variant, add option else { if (product.Variants != null && product.Variants.Count > 0) { variantService.DeleteByProductID(product.ProductID); for (int i = 0; i < product.Variants.Count; i++) { Variant variant = product.Variants[i]; if (variant.IsCreate) { if (SNumber.ToNumber(variant.VariantPrice) <= 0) { variant.VariantPrice = SNumber.ToNumber(product.Variant.VariantPrice) >= 0 ? product.Variant.VariantPrice : 0; } if (string.IsNullOrEmpty(variant.VariantSKU)) { variant.VariantSKU = product.Variant.VariantSKU + "_" + (i + 1); } if (string.IsNullOrEmpty(variant.VariantBarcode)) { variant.VariantSKU = product.Variant.VariantBarcode; } variant.CompareWithPrice = product.Variant.CompareWithPrice; variant.Textable = product.Variant.Textable; variant.VariantWeight = product.Variant.VariantWeight; variant.WeightUnit = product.Variant.WeightUnit; variant.RequireShipping = product.Variant.RequireShipping; variant.VariantBarcode = product.Variant.VariantBarcode; variant.ProductID = product.ProductID; variant.VariantTittle = variantService.GetVariantTittle(variant); variant.CreatedDateTime = variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); int variantID = variantService.Insert(variant); } } } //option if (product.Options != null && product.Options.Count > 0) { for (int i = 0; i < product.Options.Count; i++) { if (i == 0) { TblOption optionDefault = optionService.GetOptionDefaultOfProduct(product.ProductID); if (optionDefault != null) { optionDefault.OptionName = product.Options[i].OptionName; optionDefault.OptionValue = product.Options[i].OptionValue; optionDefault.ProductID = product.ProductID; optionDefault.Position = 1; optionDefault.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); bool updateOptionDefault = optionService.Update(optionDefault); } } else { TblOption option = product.Options[i]; option.ProductID = product.ProductID; option.Position = i + 1; option.CreatedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); option.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow(); int optionID = optionService.Insert(option); } } } } optionService.UpdateOptionOfProduct(product.ProductID); return(RedirectToAction("detail", "products", new { id = product.ProductID, strMessage = "1" })); } } catch (Exception ex) { LogService.WriteException(ex); return(RedirectToAction("", "products")); } } product.ListTag = tagService.GetByTableNameID((int)Common.TableName.Product); product.Options = optionService.GetByProductID(product.ProductID); product.Variants = variantService.GetByProductID(product.ProductID); product.Variant = null; if (product.Variants != null && product.Variants.Count > 0) { if (!string.IsNullOrEmpty(product.Variants[0].Option1) && product.Variants[0].Option1.Equals("Default Title")) { product.Variant = product.Variants[0]; product.Variants = null; } } product.AutoGenerate = false; List <TblImage> images = imageService.GetByProductID(product.ProductID); product.Images = images; List <ProductStyle> productStyle = productStyleService.GetAll(); productStyle.Insert(0, new ProductStyle { ProductStyleID = 0, ProductStyleName = "Chọn loại sản phẩm" }); product.ProductStyles = new SelectList(productStyle, "ProductStyleID", "ProductStyleName", product.ProductStyleID.ToString()); List <Supplier> supplier = supplierService.GetAll(); supplier.Insert(0, new Supplier { SupplierID = 0, SupplierName = "Chọn nhà sản xuất" }); product.Suppliers = new SelectList(supplier, "SupplierID", "SupplierName", product.SupplierID); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { strErrorMessage += error.ErrorMessage; } } ViewBag.strError = strErrorMessage; return(View(product)); }