public ServiceModel.Types.ProductData MapToInternalProductModel(Model.RedskyProduct product) { ProductData productData = new ProductData(); try { productData.ProductId = int.Parse(product.item.tcin); productData.Title = product.item.product_description.title; } catch (Exception ex) { //log exception here. for the purposes of this mapper, we're ok swallowing the exception and handling an //empty ProductData object elsewhere. //We could be swallowing: // ArgumentNullException, in case the product, product.item, or product.item.tcin is null // FormatException if we're getting something that isn't of the expected input // OverflowException if we'd get higher than int32 } return(productData); }
public void Map_Should_Return_Product() { // Setup var redSkyProduct = new Model.RedskyProduct { item = new Model.RedskyItem { tcin = _fixture.Create <int>().ToString(), product_description = new Model.RedskyItemDescription { title = _fixture.Create <string>() } } }; // Act var result = _redskyProductMapper.MapToInternalProductModel(redSkyProduct); // Assert result.ProductId.Should().Equals(redSkyProduct.item.tcin); }