コード例 #1
0
        public async Task TotalAmountCannotBeNegative()
        {
            //Arrange
            OrderBL orderBL = new OrderBL();
            Order   order   = new Order()
            {
                CustomerID = Guid.NewGuid(), OrderAmount = -10, TotalQuantity = 10
            };
            bool   isAdded = false;
            Guid   newGuid;
            string errorMessage = null;

            //Act
            try
            {
                (isAdded, newGuid) = await orderBL.AddOrderBL(order);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isAdded, errorMessage);
            }
        }
コード例 #2
0
        public async Task AddValidOrderDetail()
        {
            //Arrange
            OrderDetailBL orderDetailBL = new OrderDetailBL();
            OrderDetail   orderDetail   = new OrderDetail()
            {
                ProductID = Guid.NewGuid(), TotalAmount = 10, ProductQuantityOrdered = 10, ProductPrice = 10
            };
            bool   isAdded = false;
            Guid   newGuid;
            string errorMessage = null;

            //Act
            try
            {
                Customer customer = new Customer()
                {
                    CustomerName = "Arshia", CustomerMobile = "9039607074", Password = "******", Email = "*****@*****.**"
                };
                CustomerBL customerBL = new CustomerBL();
                bool       isAdded2   = false;
                Guid       newGuid2;
                (isAdded2, newGuid2) = await customerBL.AddCustomerBL(customer);

                Order order = new Order()
                {
                    CustomerID = newGuid2, TotalQuantity = 10, OrderAmount = 10
                };
                OrderBL orderBL  = new OrderBL();
                bool    isAdded1 = false;
                Guid    newGuid1;
                (isAdded1, newGuid1) = await orderBL.AddOrderBL(order);

                orderDetail.OrderId = newGuid1;
                (isAdded, newGuid)  = await orderDetailBL.AddOrderDetailsBL(orderDetail);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isAdded, errorMessage);
            }
        }
コード例 #3
0
        /// <summary>
        /// Confirm Order
        /// </summary>
        /// <returns></returns>
        public static async Task ConfirmOrder()
        {
            try
            {
                IProductBL productBL = new ProductBL();
                Guid       tempOrderID;
                using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                {
                    CustomerBL CustomerBL = new CustomerBL();
                    Customer   Customer   = await CustomerBL.GetCustomerByEmailBL(CommonData.CurrentUser.Email);

                    AddressBL      addressBL = new AddressBL();
                    List <Address> addresses = await addressBL.GetAddressByCustomerIDBL(Customer.CustomerID);

                    double totalamount = 0;
                    int    quantity    = 0;
                    Guid   orderID     = Guid.NewGuid();
                    tempOrderID = orderID;
                    foreach (var cartProduct in cart)
                    {
                        OrderDetail orderDetail = new OrderDetail();
                        WriteLine("#\tAddressLine 1\tLandMark\tCity");
                        int serial = 0;
                        foreach (var address in addresses)
                        {
                            serial++;
                            WriteLine($"{serial}\t{address.AddressLine1}\t{address.Landmark}\t{address.City}");
                        }

                        Write("Address #: ");
                        bool isNumberValid = int.TryParse(ReadLine(), out int serial1);
                        if (isNumberValid)
                        {
                            serial1--;

                            if (serial1 <= addresses.Count - 1)
                            {
                                //Read inputs
                                Address address = addresses[serial1];
                                orderDetail.AddressId = address.AddressID;
                            }
                        }
                        orderDetail.OrderId                = orderID;
                        orderDetail.ProductID              = cartProduct.ProductID;
                        orderDetail.ProductPrice           = cartProduct.ProductPrice;
                        orderDetail.ProductQuantityOrdered = cartProduct.ProductQuantityOrdered;
                        orderDetail.TotalAmount            = (cartProduct.ProductPrice * cartProduct.ProductQuantityOrdered);
                        totalamount += orderDetail.TotalAmount;
                        quantity    += orderDetail.ProductQuantityOrdered;
                        bool isAdded;
                        Guid newguid;
                        (isAdded, newguid) = await orderDetailBL.AddOrderDetailsBL(orderDetail);
                    }

                    using (IOrderBL orderBL = new OrderBL())
                    {
                        Order order = new Order();
                        order.OrderId       = orderID;
                        order.CustomerID    = Customer.CustomerID;
                        order.TotalQuantity = quantity;
                        order.OrderAmount   = totalamount;
                        bool isAdded;
                        Guid newguid;
                        (isAdded, newguid) = await orderBL.AddOrderBL(order);

                        if (isAdded)
                        {
                            WriteLine("Order  Added");
                        }
                    }
                }
                IOrderBL orderBL1 = new OrderBL();

                Order order1 = await orderBL1.GetOrderByOrderIDBL(tempOrderID);

                WriteLine($"Your Order No. {order1.OrderNumber}\t{order1.TotalQuantity}\t{order1.OrderAmount}\t{order1.DateOfOrder}");
                WriteLine("Order Details");
                IOrderDetailBL     orderDetailBL1   = new OrderDetailBL();
                List <OrderDetail> orderDetailslist = await orderDetailBL1.GetOrderDetailsByOrderIDBL(tempOrderID);

                foreach (var item in orderDetailslist)
                {
                    Product product = await productBL.GetProductByProductIDBL(item.ProductID);

                    WriteLine($"{product.ProductName}\t{item.ProductPrice}\t{item.ProductQuantityOrdered}\t{item.TotalAmount}");
                }
                cart.Clear();
            }
            catch (System.Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }