public void ProductToSoldProduct_ShouldBeMapped() { IProductModel product = Factory.InstanceProductModel(); product.Name = "some product"; product.Price = 888.45M; product.CategoryID = 654; product.Category.ID = 654; product.Category.Name = "some category"; int idTable = 36; Mock <IDataAccessSubCategory <ITableModel> > data = new Mock <IDataAccessSubCategory <ITableModel> >(); data.Setup(x => x.FindById(idTable)). Returns(new TableModel() { ID = 36, AreaID = 7, NumberOfTable = 9765, Occupied = true, Area = new AreaModel { ID = 7, Name = "some area" } }); ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, idTable, data.Object); Assert.Equal(product.Name, soldProduct.Name); Assert.Equal(product.Price, soldProduct.Price); Assert.Equal("", soldProduct.Detail); soldProduct.Category.Should().BeEquivalentTo(product.Category); soldProduct.Table.Should().BeEquivalentTo(data.Object.FindById(idTable)); }
public PsMappingConfiguration() { MappingObjects.Insert(0, new FuncToTypeListItem <object>(NativeFieldsDataTableMappingObject.IsValid, typeof(NativeFieldsDataTableMappingObject))); MappingObjects.Insert(0, new FuncToTypeListItem <object>(CustomFieldsDataTableMappingObject.IsValid, typeof(CustomFieldsDataTableMappingObject))); PropertyNameConverters.Insert(0, new FuncToTypeListItem <MappingPair>(PsToCamelCasePropsMatcher.CanMap, typeof(PsToCamelCasePropsMatcher))); PropertyNameConverters.Insert(0, new FuncToTypeListItem <MappingPair>(CamelCaseToPsPropsMatcher.CanMap, typeof(CamelCaseToPsPropsMatcher))); }
public void SoldProductToSoldProductAccomplished_ShouldBeMapped() { ISoldProductModel soldProduct = Factory.InstanceSoldProductModel(); soldProduct.Name = "some product"; soldProduct.Price = 999.93M; soldProduct.Category.Name = "some category"; soldProduct.Category.ID = 897; soldProduct.CategoryID = 897; ISoldProductAccomplishedModel soldProductAccomplished = MappingObjects.SoldProductToSoldProductAccomplished(soldProduct); Assert.Equal(soldProduct.Name, soldProductAccomplished.Name); Assert.Equal(soldProduct.Price, soldProductAccomplished.Price); soldProductAccomplished.Category.Should().BeEquivalentTo(soldProduct.Category); }
public ActionResult TableAddProduct(int?idTable, int?idCategory, int?idProduct) { if (idProduct != null) { try { // Finding the selected product and the table where is going to be added ITableModel table = tableData.FindById((int)idTable); IProductModel product = productData.FindById((int)idProduct); if (product == null) { log.Error("Could't find a product in the Database - return null"); return(View("ErrorAddProduct")); } // Creates a SoldProductModel from a ProductModel that can be added to a list in each TableModel ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, (int)idTable, tableData); soldProductData.Create(soldProduct); // Sets the current table as opened (Occupied by products) table.Occupied = true; tableData.Update(table); table.SoldProducts = soldProductData.GetByTable(table.ID); // Joins list of products and selected table to a single model mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();; mainPageModel.Tables.Add(table); } catch (Exception ex) { log.Error("Could't load products, sold products or tables from Database", ex); return(View("ErrorRetriveData")); } return(View(mainPageModel)); } else { log.Error("The product ID was null while trying to access"); return(View("ErrorAddProduct")); } }