public OperationsResult ValidateEmail()
        {
            OperationsResult operationsResult = new OperationsResult();

            if (string.IsNullOrWhiteSpace(this.EmailAddress))
            {
                operationsResult.Success = false;
                operationsResult.AddMessage("Email address is null");
            }

            if (operationsResult.Success)
            {
                var isValidFormat = true;
                // Code here that validates the format of the email
                // using regular expressions.
                if (!isValidFormat)
                {
                    operationsResult.Success = false;
                    operationsResult.AddMessage("Email address is not in a correct format");
                }
            }


            if (operationsResult.Success)
            {
                var isRealDomain = true;
                if (!isRealDomain)
                {
                    operationsResult.Success = false;
                    operationsResult.AddMessage("Email addres does not include a valid domain");
                }
            }

            return(operationsResult);
        }
Beispiel #2
0
        public OperationsResult PlaceOrder(Customer customer,
                                           Order order,
                                           Payment payment,
                                           bool allowSplitOrders,
                                           bool emailReciepts)
        {
            // Only works during the debug phase
            Debug.Assert(customerRepository != null, "Missing customer repository instance");
            Debug.Assert(orderRepository != null, "Missing order repository instance");
            Debug.Assert(inventoryRepository != null, "Missing inventory repository instance");
            Debug.Assert(emailLibrary != null, "Missing email repository instance");

            if (customer == null)
            {
                throw new ArgumentNullException("Customer instance is null");
            }
            if (order == null)
            {
                throw new ArgumentNullException("Order instance is null");
            }
            if (payment == null)
            {
                throw new ArgumentNullException("Payment instance is null");
            }

            var op = new OperationsResult();

            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment(payment);

            if (emailReciepts)
            {
                var result = customer.ValidateEmail();
                if (result.Success)
                {
                    customerRepository.Update();

                    emailLibrary.SendEmail(customer.EmailAddress, "reciept");
                }
                else
                {
                    //log the messages
                    if (result.MessageList.Any())
                    {
                        op.AddMessage(result.MessageList[0]);
                    }
                }
            }
            return(op);
        }
Beispiel #3
0
        public void PlaceOrderTestNullCustomer()
        {
            //-- Arrange
            OrderController orderController = new OrderController();
            Customer        customer        = null;
            var             order           = new Order();
            var             payment         = new Payment()
            {
                PaymentType = 1
            };


            //-- Act
            OperationsResult op = orderController.PlaceOrder(customer, order, payment, allowSplitOrders: true, emailReciepts: true);

            //-- Assert
        }
Beispiel #4
0
        public void PlaceOrderTest()
        {
            //-- Arrange
            OrderController orderController = new OrderController();
            var             customer        = new Customer()
            {
                EmailAddress = "*****@*****.**"
            };
            var order   = new Order();
            var payment = new Payment()
            {
                PaymentType = 1
            };


            //-- Act
            OperationsResult op = orderController.PlaceOrder(customer, order, payment, allowSplitOrders: true, emailReciepts: true);

            //-- Assert
            Assert.AreEqual(true, op.Success);
            Assert.AreEqual(0, op.MessageList.Count);
        }
Beispiel #5
0
        public void PlaceOrderTestInvalidEmail()
        {
            //-- Arrange
            OrderController orderController = new OrderController();
            var             customer        = new Customer()
            {
                EmailAddress = ""
            };
            var order   = new Order();
            var payment = new Payment()
            {
                PaymentType = 1
            };


            //-- Act
            OperationsResult op = orderController.PlaceOrder(customer, order, payment, allowSplitOrders: true, emailReciepts: true);

            //-- Assert
            Assert.AreEqual(true, op.Success);
            Assert.AreEqual(1, op.MessageList.Count);
            Assert.AreEqual("Email address is null", op.MessageList[0]);
        }