Esempio n. 1
0
        public void RemoveOrder(int number)
        {
            //Arrange
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "prod1", Author = UserProfile1
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "prod2", Author = UserProfile2
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "prod3", Author = UserProfile2
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "prod4", Author = UserProfile1
            });

            //Act
            var  order  = OrderDirectory.GetAllOrders()[number];
            bool result = OrderDirectory.TryRemoveOrder(order.Id);

            //Assert
            Assert.IsTrue(result == true);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Count() == 3);
            Assert.IsFalse(OrderDirectory.GetAllOrders().Any(o => o.Id == order.Id || o.Product == order.Product));
        }
Esempio n. 2
0
        public void Deny_AddNullOrder()
        {
            bool result = OrderDirectory.TryAddOrder(null);

            Assert.IsTrue(result == false);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Count == 0);
        }
Esempio n. 3
0
        public void GetOrders_ByAuthorId()
        {
            OrderDirectory.TryAddOrder(new Order()
            {
                Author = UserProfile1, Product = "user_1_prod_1"
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Author = UserProfile1, Product = "user_1_prod_2"
            });

            OrderDirectory.TryAddOrder(new Order()
            {
                Author = UserProfile2, Product = "user_2_prod_1"
            });

            var user1orders = OrderDirectory.GetOrders(UserProfile1.Id);

            Assert.IsTrue(user1orders.Count == 2);

            var user2orders = OrderDirectory.GetOrders(UserProfile2.Id);

            Assert.IsTrue(user2orders.Count == 1);

            var allOrders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(allOrders.Count == 3);
        }
Esempio n. 4
0
        public void Deny_InvalidOrEmptyProduct(string product)
        {
            bool result = OrderDirectory.TryAddOrder(new Order()
            {
                Product = product, Author = UserProfile1
            });

            Assert.IsTrue(result == false);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Count == 0);
        }
Esempio n. 5
0
        public void Deny_AddOrder_with_incorrect_AuthorId()
        {
            bool result = OrderDirectory.TryAddOrder(new Order()
            {
                Product = "something", AuthorId = 20
            });

            Assert.IsTrue(result == false);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Count == 0);
        }
Esempio n. 6
0
        public void Deny_AddOrder_with_new_Author()
        {
            bool result = OrderDirectory.TryAddOrder(new Order()
            {
                Product = "something", Author = new UserProfile()
            });

            Assert.IsTrue(result == false);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Count == 0);
        }
Esempio n. 7
0
        public void GetDefaultOrderStatus()
        {
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "car", Author = UserProfile1
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().Status == OrderStatus.INITIALIZE);
        }
Esempio n. 8
0
        public void AddOrderAuthorById()
        {
            bool result = OrderDirectory.TryAddOrder(new Order()
            {
                Product = "bread", AuthorId = UserProfile2.Id
            });

            var order = OrderDirectory.GetAllOrders().Single();

            Assert.IsTrue(result == true &&
                          order.Author.Id == order.AuthorId);
        }
Esempio n. 9
0
        public void Deny_PutNewOrder()
        {
            bool result = OrderDirectory.TryPutOrder(new Order()
            {
                Product = "thomething", Author = UserProfile1
            });

            var orderCount = OrderDirectory.GetAllOrders().Count;

            Assert.IsTrue(result == false);
            Assert.IsTrue(orderCount == 0);
        }
Esempio n. 10
0
        public void GetOrderProduct()
        {
            string product = "cherry";

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = product, AuthorId = UserProfile1.Id
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().Product == product);
        }
Esempio n. 11
0
        public void GetOrderDescription()
        {
            string description = "It's the best car in our city";

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "car", ProductDescription = description, Author = UserProfile1
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().ProductDescription == description);
        }
Esempio n. 12
0
        public void GetOrderCost()
        {
            double orderCost = 6800f;

            OrderDirectory.TryAddOrder(new Order()
            {
                Cost = orderCost, Product = "car", Author = UserProfile1
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().Cost == orderCost);
        }
Esempio n. 13
0
        public void GetOrderType()
        {
            string orderType = OrderTypes.SELL;

            OrderDirectory.TryAddOrder(new Order()
            {
                OrderType = orderType, Product = "car", Author = UserProfile1
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().OrderType == orderType);
        }
Esempio n. 14
0
        public void GetOrderStatus()
        {
            string status = OrderStatus.ACTIVE;

            OrderDirectory.TryAddOrder(new Order()
            {
                Status = status, Product = "car", Author = UserProfile1
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders.Single().Status == status);
        }
Esempio n. 15
0
        public void GetOrder_ById()
        {
            string product = "apple";

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = product, AuthorId = UserProfile1.Id
            });

            int orderId = OrderDirectory.GetAllOrders().First().Id;
            var order   = OrderDirectory.GetOrder(orderId);

            Assert.IsTrue(order.Product == product);
        }
Esempio n. 16
0
        public void UniqueOrderId()
        {
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "vegetables", Author = UserProfile1
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "books", Author = UserProfile2
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders[0].Id != orders[1].Id);
        }
Esempio n. 17
0
        public void Deny_AddDublicateOrders()
        {
            var order = new Order()
            {
                Product = "vegetables", Author = UserProfile1
            };

            OrderDirectory.TryAddOrder(new Order());
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "books", Author = UserProfile2
            });

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(orders[0].Id != orders[1].Id);
        }
Esempio n. 18
0
        public void AddOrder(int countOfOrder)
        {
            bool result = true;

            for (int i = 1; i <= countOfOrder; i++)
            {
                result = OrderDirectory.TryAddOrder(new Order()
                {
                    Product = $"product{i}", Author = UserProfile1
                });
            }

            var orders = OrderDirectory.GetAllOrders();

            Assert.IsTrue(result == true);
            Assert.IsTrue(orders.Count == countOfOrder);
        }
Esempio n. 19
0
        public void Deny_RemoveOrder_by_incorrect_Id()
        {
            //Arrange
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "prod1", Author = UserProfile1
            });

            //Act
            var  order  = OrderDirectory.GetAllOrders().Single();
            bool result = OrderDirectory.TryRemoveOrder(order.Id + 25);

            //Assert
            Assert.IsFalse(result);
            Assert.IsFalse(OrderDirectory.GetAllOrders().Count() == 0);
            Assert.IsTrue(OrderDirectory.GetAllOrders().Any(o => o.Id == order.Id || o.Product == order.Product));
        }
Esempio n. 20
0
        public void Get_untracked_ChangingProduct()
        {
            bool trackingOption = false;

            string originalProduct = "cherry";
            string newProduct      = "banana";

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = originalProduct, Author = UserProfile1
            });

            OrderDirectory.GetAllOrders(trackingOption).Single()
            .Product = newProduct;
            var order = OrderDirectory.GetAllOrders(trackingOption).Single();

            Assert.IsTrue(order.Product == originalProduct);
        }
Esempio n. 21
0
        public void PutOrderStatus_trackingOption(bool trackingOption)
        {
            string originalStatus = OrderStatus.INITIALIZE;
            string newStatus      = OrderStatus.ACTIVE;

            OrderDirectory.TryAddOrder(new Order()
            {
                Status = originalStatus, Product = "prod", Author = UserProfile1
            });

            var firstOrder = OrderDirectory.GetAllOrders(trackingOption).Single();

            firstOrder.Status = newStatus;
            bool result = OrderDirectory.TryPutOrder(firstOrder);

            firstOrder = OrderDirectory.GetAllOrders(trackingOption).Single();
            Assert.IsTrue(result == true &&
                          firstOrder.Status == newStatus);
        }
Esempio n. 22
0
        public void PutOrderProduct_trackingOption(bool trackingOption)
        {
            string originalProduct = "first";
            string newProduct      = "newProd";

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = originalProduct, Author = UserProfile1
            });


            var firstOrder = OrderDirectory.GetAllOrders(trackingOption).Single();

            firstOrder.Product = newProduct;
            bool result = OrderDirectory.TryPutOrder(firstOrder);

            firstOrder = OrderDirectory.GetAllOrders(trackingOption).Single();
            Assert.IsTrue(result == true &&
                          firstOrder.Product == newProduct);
        }
Esempio n. 23
0
        //Directory don't have any mechanism to protect order.id from changing manyally.
        //TODO fix them
        //[Test]
        public void DenyChangeOrderIdTest()
        {
            bool trackingOption = true;

            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "first", Author = UserProfile1
            });
            OrderDirectory.TryAddOrder(new Order()
            {
                Product = "second", Author = UserProfile1
            });
            string newProduct = "third";

            var firstOrder = OrderDirectory.GetAllOrders(trackingOption)[0];

            firstOrder.Id++;
            firstOrder.Product = newProduct;
            bool result = OrderDirectory.TryPutOrder(firstOrder);

            firstOrder = OrderDirectory.GetAllOrders(trackingOption)[0];
            Assert.IsTrue(result == false);
            Assert.IsTrue(firstOrder.Product != newProduct);
        }