public void CalculateFee(ShippingProduct product) { var weight = product.Weight; if (weight > 20) { product.ShippingFee = 500; } else { product.ShippingFee = 100 + weight * 10; } }
public void CalculateFee(ShippingProduct product) { var size = product.Size.Length * product.Size.Width * product.Size.Height; //長 x 寬 x 高(公分)x 0.0000353 if (product.Size.Length > 100 || product.Size.Width > 100 || product.Size.Height > 100) { product.ShippingFee = size * 0.0000353 * 1100 + 500; } else { product.ShippingFee = size * 0.0000353 * 1200; } }
private ShippingProduct GetShippingProduct() { var result = new ShippingProduct { Name = this.txtProductName.Text, Weight = Convert.ToDouble(this.txtProductWeight.Text), Size = new Size { Length = Convert.ToDouble(this.txtProductLength.Text), Width = Convert.ToDouble(this.txtProductWidth.Text), Height = Convert.ToDouble(this.txtProductHeight.Text) }, Shipper = Convert.ToInt32(this.drpCompany.SelectedValue) }; return result; }
public void CalculateFee(ShippingProduct product) { var weight = product.Weight; var feeByWeight = 80 + weight * 10; var size = product.Size.Length * product.Size.Width * product.Size.Height; var feeBySize = size * 0.0000353 * 1100; if (feeByWeight < feeBySize) { product.ShippingFee = feeByWeight; } else { product.ShippingFee = feeBySize; } }
public void CalculateFeeTest() { //arrange var target = new Postoffice(); var product = new ShippingProduct { Name = "book", Weight = 10, Size = new Size { Length = 30, Width = 20, Height = 10 }, }; //act target.CalculateFee(product); //assert var expected = 180; Assert.AreEqual(expected, product.ShippingFee); }