Acme.Biz.Vendor.PlaceOrder C# (CSharp) Method

PlaceOrder() public method

Sends a product order to the vendor.
public PlaceOrder ( Product product, int quantity, DateTimeOffset deliverBy = null, string instructions = "standard delivery" ) : Acme.Common.OperationResult
product Product Product to order.
quantity int Quantity of the product to order.
deliverBy DateTimeOffset Requested delivery date.
instructions string Delivery instructions.
return Acme.Common.OperationResult
        public OperationResult PlaceOrder(Product product, int quantity,
                                            DateTimeOffset? deliverBy = null,
                                            string instructions = "standard delivery")
        {
            if (product == null)
                throw new ArgumentNullException("product");
            if (quantity <= 0)
                throw new ArgumentOutOfRangeException("quantity");
            if (deliverBy <= DateTimeOffset.Now)
                throw new ArgumentOutOfRangeException("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(success, orderText);
            return operationResult;
        }

Usage Example

Esempio n. 1
0
        public void PlaceOrderTest_NullProduct_Exception()
        {
            // Arrange
            var vender = new Vendor();

            // Act
            var actual = vender.PlaceOrder(null, 12);

            // Assert
        }
All Usage Examples Of Acme.Biz.Vendor::PlaceOrder