/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="includeAddress">True to include the shipping address in the order.</param> /// <param name="sendCopy">True to send a copy of the email to the current user.</param> /// <returns>Success flag and order text</returns> public OperationResult PlaceOrder(Product product, int quantity, IncludeAddress includeAddress, SendCopy sendCopy) { var orderText = "Test"; if (includeAddress == IncludeAddress.Yes) orderText += " With Address"; if (sendCopy == SendCopy.Yes) orderText += " With Copy"; var operationResult = new OperationResult(true, orderText); return operationResult; }
public void CalculateSuggestedPriceTest() { // Arrange var currentProduct = new Product(1, "Saw", ""); currentProduct.Cost = 50m; var expected = new OperationResult<decimal>(55m, ""); // Act var actual = currentProduct.CalculateSuggestedPrice(10m); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrderTest() { // Arrange var vender = new Vendor(); var product = new Product(1, "Hammer", ""); var expected = new OperationResult(true, "Order from ACME, Inc\nProduct: Tools-1\nQuantity: 1"); // Act var actual = vender.PlaceOrder(product, 1); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrderTest() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nInstructions: standard delivery"); // Act var actual = vendor.PlaceOrder(product, 12); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrderTest() { // Arrange var vendor = new Vendor(); var product = new Product(); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Tools-1\r\nQuantity: 12"); // Act var actual = vendor.PlaceOrder(product, 12); Console.WriteLine(expected.Message); Console.WriteLine(actual.Message); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrder_3Parameters() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Tools-1\r\nQuantity: 12" + "\r\nDeliver By: 10/25/2015"); // Act var actual = vendor.PlaceOrder(product, 12, new DateTimeOffset(2015, 10, 25, 0, 0, 0, new TimeSpan(-7, 0, 0))); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrder_NoDeliveryDate() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult<bool,string>(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nInstructions: Deliver to Suite 42"); // Act var actual = vendor.PlaceOrder(product, 12, instructions: "Deliver to Suite 42"); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrder_3Parameters() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult<bool>(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nDeliver By: 10/25/2018" + "\r\nInstructions: standard delivery"); // Act var actual = vendor.PlaceOrder(product, 12, new DateTimeOffset(2018, 10, 25, 0, 0, 0, new TimeSpan(-7, 0, 0))); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="deliverBy">Requested delivery date.</param> /// <param name="instructions">Delivery instructions.</param> /// <returns></returns> public OperationResult<bool, string> PlaceOrder(Product product, int quantity, DateTimeOffset? deliverBy = null, string instructions = "standard delivery") { if (product == null) throw new ArgumentNullException(nameof(product)); if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(quantity)); if (deliverBy <= DateTimeOffset.Now) throw new ArgumentOutOfRangeException(nameof(deliverBy)); var success = false; var orderTextBuilder = new StringBuilder("Order from Acme, Inc" + System.Environment.NewLine + "Product: " + product.ProductName + System.Environment.NewLine + "Quantity: " + quantity); if (deliverBy.HasValue) { orderTextBuilder.Append( System.Environment.NewLine + "Deliver By: " + deliverBy.Value.ToString("d")); } if (!String.IsNullOrWhiteSpace(instructions)) { orderTextBuilder.Append( System.Environment.NewLine + "Instructions: " + instructions); } var orderText = orderTextBuilder.ToString(); var emailService = new EmailService(); var confirmation = emailService.SendMessage("New Order", orderText, this.Email); if (confirmation.StartsWith("Message sent:")) { success = true; } var operationResult = new OperationResult<bool,string>(success, orderText); return operationResult; }
/// <summary> /// Sends a product order to the vendor /// </summary> /// <param name="product">Product to order</param> /// <param name="quantity">Quantity of the product to order.</param> /// <returns></returns> public OperationResult PlaceOrder(Product product, int quantity, DateTimeOffset? deliverBy, string instructions) { if (product == null) throw new ArgumentNullException("product"); if (quantity < 0) throw new ArgumentNullException("quantity"); if (deliverBy <= DateTimeOffset.Now) throw new ArgumentOutOfRangeException("deliverBy"); var success = false; var orderText = "Order from Acme, Inc" + System.Environment.NewLine + "Product: " + product.ProductName + System.Environment.NewLine + "Quantity: " + quantity; if (deliverBy.HasValue) { orderText += System.Environment.NewLine + "Deliver By: " + deliverBy.Value.ToString("d"); } if (!string.IsNullOrWhiteSpace(instructions)) { orderText += System.Environment.NewLine + "Instuctions: " + instructions; } var emailService = new EmailService(); var confirmation = emailService.SendMessage("New Order", orderText, this.Email); if (confirmation.StartsWith("Message sent:")) { success = true; } var operationResult = new OperationResult(success, orderText); return operationResult; }
public void PlaceOrderTest_WithAddress() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult(true, "Test With Address"); // Act var actual = vendor.PlaceOrder(product, 12, Vendor.IncludeAddress.Yes, Vendor.SendCopy.No); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
/// <summary> /// Calculates the suggested retail price /// </summary> /// <param name="markupPercent">Percent used to mark up the cost.</param> /// <returns></returns> public OperationResult<decimal> CalculateSuggestedPrice(decimal markupPercent) { var message = ""; if (markupPercent <= 0m) { message = "Invalid markup percentage"; } else if (markupPercent < 10) { message = "Below recommended markup percentage"; } var result = this.Cost + (this.Cost * markupPercent / 100); var operationResult = new OperationResult<decimal>(result, message); return operationResult; }
public void PlaceOrder_3Parameters() { // Arrange var vender = new Vendor(); var product = new Product(1, "Hammer", ""); var expected = new OperationResult(true, "Order from ACME, Inc\nProduct: Tools-1\nQuantity: 1" + "\nInstructions: standard delivery"); // Act var actual = vender.PlaceOrder(product, 1, instructions: "standard delivery"); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="deliverBy">Requested delivery date.</param> /// <param name="instructions">Delivery instructions</param> /// <returns></returns> public OperationResult PlaceOrder(Product product, int quantity, DateTimeOffset? deliverBy = null, string instructions = "standard delivery") { // Guard clauses make sure passed in values are within constraints. if (product == null) throw new ArgumentNullException(nameof(product)); if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(product)); if (deliverBy <= DateTimeOffset.Now) throw new ArgumentOutOfRangeException(nameof(deliverBy)); var success = false; var orderText = "Order from ACME, Inc" + "\n" + "Product: " + product.ProductCode + "\n" + "Quantity: " + quantity; if (deliverBy.HasValue) { orderText += "\n" + "Deliver By: " + deliverBy.Value.ToString("d"); } if (!String.IsNullOrWhiteSpace(instructions)) { orderText += "\n" + "Instructions: " + instructions; } var emailService = new EmailService(); var confirmation = emailService.SendMessage("New Order", orderText, Email); if (confirmation.StartsWith("Message sent: ")) { success = true; } var operationResult = new OperationResult(success, orderText); return operationResult; }
/// <summary> /// Send Order to Vendor /// </summary> /// <param name="product">Product Ordered</param> /// <param name="quantity">Product Quantity</param> /// <param name="deliveryBy">Requested Delivery Date.</param> /// <param name="instruction">Delivery Instruction</param> /// <returns>True or false</returns> public OperationResult PlaceOrder(Product product, int quantity, DateTimeOffset? deliveryBy=null,string instruction="Standard Delivery") { if (product == null) { throw new ArgumentNullException(nameof(product)); } if (quantity <= 0) { throw new ArgumentOutOfRangeException(nameof(quantity)); } var success = false; var orderText = "Order from Acme, Inc" + System.Environment.NewLine + "Product: " + product.ProductCode + System.Environment.NewLine + "Quantity: " + quantity; if (deliveryBy!=null && deliveryBy.HasValue) { orderText += Environment.NewLine + "Deliver By: " + deliveryBy.Value.ToString("d"); } if (!String.IsNullOrWhiteSpace(instruction)) { orderText += Environment.NewLine + "Instructions: " +instruction; } var emailService = new EmailService(); var confirmation = emailService.SendMessage("New Order", orderText, this.Email); if (confirmation.StartsWith("Message sent:", StringComparison.CurrentCultureIgnoreCase)) { success = true; } var operationResult = new OperationResult(success, orderText); return operationResult; }