Acme.Biz.Vendor.PlaceOrder C# (CSharp) 메소드

PlaceOrder() 공개 메소드

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.
리턴 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

예제 #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