/// <summary> /// Update the informatin in the database for the given product /// </summary> /// <param name="productEditObject"></param> /// <returns></returns> public ActionResult <ProductEditObject> Update(ProductEditObject productEditObject) { try { // map the product core object to the product domain object var product = AutoMapper.Mapper.Map <ProductEditObject, Product>(productEditObject); // we want to update/set the tag values that actually have a value set product.ProductTagValues = product.ProductTagValues.Where(ptv => !string.IsNullOrWhiteSpace(ptv.Value)).ToList(); var updatedProduct = _unitOfWork.ProductRepository.Update(product); _unitOfWork.Commit(); // map back to the core object var coreObject = AutoMapper.Mapper.Map <Product, ProductEditObject>(updatedProduct); // get and set the properties for the new category on the updated product var properties = GetAllProductProperties(updatedProduct.CategoryId, updatedProduct); coreObject.Properties = properties; return(ActionResult <ProductEditObject> .GetSuccess(coreObject)); } catch (Exception ex) { return(ActionResult <ProductEditObject> .GetFailed($"[Update Product] Exception/Failed when updating product. Exception message: {ex.Message}")); } }
private void SetValuesOnAllPropertiesOnProduct(ProductEditObject product) { foreach (var property in product.Properties) { property.Value = GetUniqueString("PropValue"); } }
/// <summary> /// Execute the main method under the test for the current integration set of tests /// </summary> /// <param name="productToEdit"></param> /// <returns></returns> private ProductServiceUpdateExecuteResult ExecuteMethodUnderTest(ProductEditObject productToEdit) { var service = GetServiceInstance(); var result = service.Update(productToEdit); return(new ProductServiceUpdateExecuteResult { Result = result, ServiceUnderTest = service }); }
private string SetPropertyValueForSpecificTagType(ProductEditObject product, int propertyTagTypeId) { var newValue = GetUniqueString("PropNewValue", 8); var property = product.Properties.FirstOrDefault(p => p.PropertyTypeId == propertyTagTypeId); if (property != null) { property.Value = newValue; } return(newValue); }
private void MapCategoryPath(ProductEditObject coreObject) { var categories = _unitOfWork.CategoryRepository.Query().ToList(); var parent = categories.FirstOrDefault(c => c.Id == coreObject.Category.Id); while (parent != null) { coreObject.CategoryHirearchy.Add(AutoMapper.Mapper.Map <Category, CategoryOperationObject>(parent)); parent = categories.FirstOrDefault(c => c.Id == parent.ParentId); } coreObject.CategoryHirearchy.Reverse(); }
// PUT api/products/5 public ProductEditObject Put(ProductEditObject product) { return(ActionVerbConfigService.WrapAction(() => { var updateResult = _productLogic.Update(product); if (updateResult.Success) { CheckAndDeleteImages(product); return updateResult.Data; } throw new HttpResponseException(ResponseMessageBuilder.BuildMessageFromActionResult(updateResult)); })); }
private void RunUpdateProductAsserts(string assertPrefix, ProductEditObject updatedProduct, string updatedProductName, ProductProperty existingProperty, string updatedTagValueForProduct, string newTagTypeName, string newTagValueForProduct) { // check to see if the product has been corectly update // first check for the name Assert.AreEqual(updatedProductName, updatedProduct.Name, $"{assertPrefix} The name of the product which is now {updatedProduct.Name} must match the expected name {updatedProductName}"); // if there was an existing property if (existingProperty != null) { // check to see if the existing property has been updated var property = updatedProduct.Properties.FirstOrDefault(pr => pr.Id == existingProperty.Id); Assert.IsNotNull(property, $"{assertPrefix} The existing property which we updated must exist again"); Assert.AreEqual(updatedTagValueForProduct, property.Value, $"{assertPrefix} The property {property.Name} has the value {property.Value} but we expect it to have the value {updatedTagValueForProduct}"); } // check if the product has the new property var productNewlyCreatedProperty = updatedProduct.Properties.FirstOrDefault(pr => pr.Name == newTagTypeName); Assert.IsNotNull(productNewlyCreatedProperty); Assert.AreEqual(newTagValueForProduct, productNewlyCreatedProperty.Value, $"{assertPrefix} We are expecting the new created value/tag for the product: {productNewlyCreatedProperty.Name} to have the value {newTagValueForProduct}, but it has value: {productNewlyCreatedProperty.Value}"); }
private void RunFullAssertionSet( ProductEditObject readProduct, ProductOperationObject expectedProductInfo, Category expectedCategoryInfo, Manufacturer expectedManufacturerInfo, List <TagType> expectedTagList, bool runPropertyValueAsserts = false) { // product general asserts Assert.AreEqual(expectedProductInfo.Name, readProduct.Name, "The product name must match"); Assert.AreEqual(expectedProductInfo.PriceCurrent, readProduct.PriceCurrent, "The product price current must match"); Assert.AreEqual(expectedProductInfo.PriceRegular, readProduct.PriceRegular, "The product price regular must match"); // assert manufacturer Assert.AreEqual(expectedManufacturerInfo.Id, readProduct.ManufacturerId, "The product must have the correct manufacturer set"); Assert.IsNotNull(readProduct.Manufacturer); // assert product Assert.AreEqual(expectedCategoryInfo.Id, readProduct.CategoryId, "The Product must have the correct expected category"); Assert.IsNotNull(readProduct.Category, "The category information for the product must be present"); // assert tag types Assert.AreEqual(readProduct.Properties.Count, expectedTagList.Count, "The number of properties on the product must match the expected tag types present on the product"); foreach (var tagType in expectedTagList) { var propertyOnProduct = readProduct.Properties.FirstOrDefault(p => p.PropertyTypeId == tagType.Id); Assert.IsNotNull(propertyOnProduct, $"The tag type with id {tagType.Id} must be contained in the list of properties for the product"); Assert.IsTrue(propertyOnProduct.Name == tagType.Name, $"The name of the contained tag type {tagType.Name} must match the name of the property: {propertyOnProduct.Name}"); if (runPropertyValueAsserts) { Assert.IsTrue(!string.IsNullOrWhiteSpace(propertyOnProduct.Value), $"The value on the property with name {propertyOnProduct.Name} must be set"); } } }
private void CheckAndDeleteImages(ProductEditObject product) { new FileManager().ProcessAndDeleteFilesInDirectory($"ProductImages\\{product.Id}", product.ProductImages.Select(s => s.Image.Uri).ToList()); }
private void AddProductToEntitiesCompare(ProductEditObject productEditObject, EntitiesCompareObject <ProductEditObject> entitiesCompareObject) { var entityId = productEditObject.Id.ToString(); entitiesCompareObject.AddValue(entityId, "Name", productEditObject.Name).AddValue(entityId, "Description", productEditObject.Description).AddValue(entityId, "Category", productEditObject.Category.Name).AddValue(entityId, "Manufacturer", productEditObject.Manufacturer.Name).AddValue(entityId, "PriceRegular", productEditObject.PriceRegular).AddValue(entityId, "PriceCurrent", productEditObject.PriceCurrent); }