Exemple #1
0
        public async Task CustomerIDDoesNotExist()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = 0
            };
            await onlineReturnBL.AddReturnBL(onlineReturn);

            bool   isDisplayed  = false;
            string errorMessage = null;

            //Act
            try
            {
                List <Return> onlineReturnList1 = await onlineReturnBL.GetOnlineReturnByCustomerIDBL(default(Guid));

                if (onlineReturnList1.Count < 1)
                {
                    isDisplayed = true;
                }
            }
            catch (Exception ex)
            {
                isDisplayed  = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isDisplayed, errorMessage);
            }
        }
Exemple #2
0
        public async Task GetOnlineReturnByOnlineReturnIDBL()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = 0
            };
            await onlineReturnBL.AddReturnBL(onlineReturn);

            bool   isDisplayed  = false;
            string errorMessage = null;

            //Act
            try
            {
                Return onlineReturn1 = await onlineReturnBL.GetOnlineReturnByOnlineReturnIDBL(onlineReturn.OnlineReturnID);

                if (onlineReturn.OnlineReturnID == onlineReturn1.OnlineReturnID)

                {
                    isDisplayed = true;
                }
            }
            catch (Exception ex)
            {
                isDisplayed  = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isDisplayed, errorMessage);
            }
        }
Exemple #3
0
        public async Task OnlineReturnProductNumberCanNotBeZero()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 0, QuantityOfReturn = 5, Purpose = 0
            };
            bool   isAdded      = false;
            string errorMessage = null;

            //Act
            try
            {
                isAdded = await onlineReturnBL.AddReturnBL(onlineReturn);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isAdded, errorMessage);
            }
        }
Exemple #4
0
        public async Task GetAllValidOnlineReturns()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = PurposeOfReturn.DefectiveProduct
            };
            await onlineReturnBL.AddReturnBL(onlineReturn);

            bool   isDisplayed  = false;
            string errorMessage = null;

            //Act
            try
            {
                List <Return> onlineReturnList = await onlineReturnBL.GetAllReturnsBL();

                if (onlineReturnList.Count > 0)
                {
                    isDisplayed = true;
                }
            }
            catch (Exception ex)
            {
                isDisplayed  = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isDisplayed, errorMessage);
            }
        }
Exemple #5
0
        public async Task DeleteinValidOnlineReturnBL()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = 0
            };
            await onlineReturnBL.AddReturnBL(onlineReturn);

            bool   isDeleted    = false;
            string errorMessage = null;

            //Act
            try
            {
                isDeleted = await onlineReturnBL.DeleteOnlineReturnBL(default(Guid));
            }
            catch (Exception ex)
            {
                isDeleted    = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isDeleted, errorMessage);
            }
        }
Exemple #6
0
        public async Task OnlineReturnIDDoesNotExist()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn1  = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = 0
            };
            await onlineReturnBL.AddReturnBL(onlineReturn1);

            Return onlineReturn2 = new Return()
            {
                OnlineReturnID = default(Guid), OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = 0
            };
            bool   isUpdated    = false;
            string errorMessage = null;

            //Act
            try
            {
                isUpdated = await onlineReturnBL.UpdateReturnBL(onlineReturn2);
            }
            catch (Exception ex)
            {
                isUpdated    = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isUpdated, errorMessage);
            }
        }
Exemple #7
0
        public async Task OnlineReturnPurposeCanNotBeNull3()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn1  = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = PurposeOfReturn.DefectiveProduct
            };
            await onlineReturnBL.AddReturnBL(onlineReturn1);

            Return onlineReturn2 = new Return()
            {
                OnlineReturnID = onlineReturn1.OnlineReturnID, OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = PurposeOfReturn.WrongProductShipped
            };
            bool   isUpdated    = false;
            string errorMessage = null;

            //Act
            try
            {
                isUpdated = await onlineReturnBL.UpdateReturnBL(onlineReturn2);
            }
            catch (Exception ex)
            {
                isUpdated    = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isUpdated, errorMessage);
            }
        }
Exemple #8
0
        public async Task OnlineReturnPurposeCanNotBeNull1()
        {
            //Arrange
            ReturnBL onlineReturnBL = new ReturnBL();
            Return   onlineReturn   = new Return()
            {
                OrderNumber = 20, ProductNumber = 4, QuantityOfReturn = 5, Purpose = PurposeOfReturn.UnsatiSfactoryProduct
            };
            bool   isAdded      = false;
            string errorMessage = null;

            //Act
            try
            {
                isAdded = await onlineReturnBL.AddReturnBL(onlineReturn);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isAdded, errorMessage);
            }
        }
        public static async Task AddReturn()
        {
            Return             onlineReturn  = new Return();
            List <OrderDetail> matchingOrder = new List <OrderDetail>();

            WriteLine("Enter the order number which you want to return");
            double orderToBeReturned = double.Parse(Console.ReadLine());

            WriteLine("Entered Number is: " + orderToBeReturned);
            try
            {
                using (IOrderBL orderBL = new OrderBL())
                {
                    Order order = await orderBL.GetOrderByOrderNumberBL(orderToBeReturned);

                    onlineReturn.OrderID = order.OrderId;
                    using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                    {
                        matchingOrder = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);
                    }
                }

                if (matchingOrder.Count != 0)
                {
                    int orderNo = 0;
                    WriteLine("Products in the order are ");
                    foreach (var orderDetail in matchingOrder)
                    {
                        orderNo++;
                        WriteLine("#\tProductID\t ProductQuantityOrdered\t ProductPrice\t TotalAmount");
                        WriteLine($"{orderNo}\t{orderDetail.ProductID}\t{orderDetail.ProductQuantityOrdered}\t{orderDetail.ProductPrice}\t{orderDetail.TotalAmount}");
                    }
                    WriteLine("Enter The Product Number to be Returned");
                    int ProductToBeReturned = int.Parse(ReadLine());
                    if (ProductToBeReturned <= matchingOrder.Count && ProductToBeReturned > 0)
                    {
                        WriteLine("Enter The Product Serial No. to be Returned");
                        Write("Product  #: ");
                        bool isNumberValid = int.TryParse(ReadLine(), out int serialNo);
                        if (isNumberValid)
                        {
                            serialNo--;
                            if (serialNo <= matchingOrder.Count - 1)
                            {
                                OrderDetail orderDetail = matchingOrder[serialNo];
                                onlineReturn.ProductID = orderDetail.ProductID;
                            }
                        }
                        Console.WriteLine("Enter The Quantity to be Returned");
                        int          QuantityOfReturn = int.Parse(Console.ReadLine());
                        IOrderDetail orderDetail1     = new OrderDetail();
                        onlineReturn.QuantityOfReturn = QuantityOfReturn;

                        foreach (var orderDetail in matchingOrder)
                        {
                            orderDetail1 = matchingOrder.Find(
                                (item) => { return(item.ProductQuantityOrdered == orderDetail.ProductQuantityOrdered); });
                        }

                        if (QuantityOfReturn <= orderDetail1.ProductQuantityOrdered)
                        {
                            WriteLine("Purpose of Return:\n1.  UnsatiSfactoryProduct\n2. WrongProductShipped\n3.  WrongProductOrdered\n4. DefectiveProduct  ");
                            bool isPurposeValid = int.TryParse(ReadLine(), out int purpose);
                            if (isPurposeValid)
                            {
                                if (purpose == 1)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.UnsatiSfactoryProduct;
                                }
                                else if (purpose == 2)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductShipped;
                                }
                                else if (purpose == 3)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductOrdered;
                                }
                                else if (purpose == 4)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.DefectiveProduct;
                                }
                                else
                                {
                                    WriteLine("Invalid Option Selected ");
                                }

                                Write("Are you sure? (Y/N): ");
                                string confirmation = ReadLine();
                                if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                                {
                                    using (IReturnBL onlineReturnBL = new ReturnBL())
                                    {
                                        bool confirmed = await onlineReturnBL.AddReturnBL(onlineReturn);

                                        if (confirmed)
                                        {
                                            matchingOrder[ProductToBeReturned - 1].ProductQuantityOrdered -= QuantityOfReturn;
                                            matchingOrder[ProductToBeReturned - 1].TotalAmount            -= matchingOrder[ProductToBeReturned - 1].ProductPrice * QuantityOfReturn;
                                            WriteLine("Total Return Amount: " + (matchingOrder[ProductToBeReturned - 1].ProductPrice * QuantityOfReturn));
                                            WriteLine("OnlineReturn Confirmed");
                                            WriteLine("OnlineReturnID is" + "  " + onlineReturn.OnlineReturnID);
                                        }
                                        else
                                        {
                                            WriteLine("Data Not Serialized");
                                        }
                                    }
                                }
                                else
                                {
                                    WriteLine(" Not Confirmed");
                                }
                            }
                            else
                            {
                                WriteLine(" Purpose of return not valid");
                            }
                        }
                        else
                        {
                            WriteLine("Invalid QuantityOfReturn");
                        }
                    }
                    else
                    {
                        WriteLine("Wrong Input");
                    }
                }
                else
                {
                    Console.WriteLine("OrderID not Found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }