Пример #1
0
        public void CreateNewValidOrder_OrderIsAddedInDatabase_ObjectIsInDatabase()
        {
            //Arrange
            var   viewModel = new OrderViewModel();
            Order order     = OrderCreator.CreateOrder("Client", 124, "Roll", 1, 12.2m);

            //Action
            viewModel.AddNewOrder(order);
            int numberOfOrders = viewModel.GetNumberOfOrders();

            //Assert
            Assert.AreEqual(1, numberOfOrders);
        }
Пример #2
0
        public void GetNumberOfOrders_OrdersExistInDatabase_NumberOfOrdersIsReturned()
        {
            //Arrange
            var viewModel   = new OrderViewModel();
            var ordersToAdd = OrderCreator.CreateOrders_TwoOrdersWithSameReuquestId();

            viewModel.AddNewOrders(ordersToAdd);

            //Action
            int numberOfOrders = viewModel.GetNumberOfOrders();

            //Assert
            Assert.AreEqual(2, numberOfOrders);
        }
Пример #3
0
        public void FetchAllOrdersForSpecificClient_OrdersExistInDatabase_OrdersForClientAreReturned()
        {
            //Arrange
            var    viewModel = new OrderViewModel();
            string clientId  = "id1";
            var    orderForSpecificCLientToAdd = OrderCreator.CreateOrders_ForSpecificCLient_TwoOrdersWithSameRequestId(clientId);

            viewModel.AddNewOrders(orderForSpecificCLientToAdd);

            //Action
            var clientOrders = viewModel.GetAllOrdersForSpecificClient(clientId);

            //Assert
            Assert.AreEqual(1, clientOrders.Count);
        }
Пример #4
0
        public void GetNumberOfRequestsGroupedByNameForSpecificClient_OrdersExistInDatabase_GrouppedRequestsAreReturned()
        {
            //Arrange
            var viewModel   = new OrderViewModel();
            var ordersToAdd = OrderCreator.CreateOrdersForGroupByNameTest();

            viewModel.AddNewOrders(ordersToAdd);


            var groupedOrdersForClient = viewModel.GetNumberOfOrdersGroupedByNameForSpecificClient("id1");

            // Assert
            // Only 2 orders should be returned because two orders referee to same name
            Assert.AreEqual(2, groupedOrdersForClient.Count);
        }
Пример #5
0
        public void GetNumberOfRequestsGroupedByName_OrdersExistInDatabase_GrouppedRequestsAreReturned()
        {
            //Arrange
            var viewModel   = new OrderViewModel();
            var ordersToAdd = OrderCreator.CreateOrdersForGroupByNameTest();

            viewModel.AddNewOrders(ordersToAdd);

            //Action
            var groupedOrders = viewModel.GetNumberOfOrdersGroupedByName();

            //Assert
            // only 3 orders should be returned because two orders referee to same name
            Assert.AreEqual(3, groupedOrders.Count);
        }
Пример #6
0
        public void GetAveragePriceOfOrder_OrdersExistInDatabase_AveragePriceIsReturned()
        {
            //Arrange
            var viewModel   = new OrderViewModel();
            var ordersToAdd = OrderCreator.CreateOrders_TwoOrdersWithSameReuquestId();

            viewModel.AddNewOrders(ordersToAdd);
            decimal average = 269.6m;  // calculated based on the orders added into database
                                       // first request => 12 * 12.2 + 10 * 10 = 246.4, second request => 24 * 12.2 = 292.8
                                       // Average = 269.6
            decimal averagePrice = viewModel.GetAveragePriceOfOrder();

            //Assert
            Assert.AreEqual(average, averagePrice);
        }
Пример #7
0
        public void FetchAllOrders_OrdersAreInDatabase_AllOrdersAreReturned()
        {
            //Arrange
            var viewModel = new OrderViewModel();
            // create three orders where 2 refere to same request id
            var ordersToAdd = OrderCreator.CreateOrders_TwoOrdersWithSameReuquestId();

            // add them to database
            viewModel.AddNewOrders(ordersToAdd);

            //Action
            var orders = viewModel.GetAllOrders();

            //Assert
            Assert.IsTrue(2 == orders.Count);
        }
Пример #8
0
        public void GetOrdersInGivenRange_OrdersExistInDatabase_OrdersInGivenRangeAreReturned()
        {
            //Arrange
            var     viewModel   = new OrderViewModel();
            decimal lowerBound  = 1.5m;
            decimal upperBound  = 5.7m;
            var     ordersToAdd = OrderCreator.CreateOrders_TwoOrdersWithSameReuquestId();


            //Action
            var ordersInGivenRange = viewModel.GetOrdersInGivenRange(lowerBound, upperBound);

            // Assert
            // Orders in range( price >= lowerBound && price <= upperBound) are returned
            ordersInGivenRange.ForEach(order => Assert.IsTrue(order.Price >= lowerBound && order.Price <= upperBound));
        }
Пример #9
0
        public void GetTotalPriceOfOrders_OrdersExistInDatabase_NumberOfOrdersIsReturned()
        {
            //Arrange
            var viewModel   = new OrderViewModel();
            var ordersToAdd = OrderCreator.CreateOrders_TwoOrdersWithSameReuquestId();

            viewModel.AddNewOrders(ordersToAdd);
            decimal result = 539.2m;       // calculated based on the orders added into database
                                           // first request => 12 * 12.2m = 146.4, second request => 24 * 12.2 = 292.8, third request => 10*10 = 100
                                           // sum = 539.2
            //Action
            decimal totalPriceOfOrders = viewModel.GetTotalPriceOfOrders();

            //Assert
            Assert.AreEqual(result, totalPriceOfOrders);
        }
Пример #10
0
        public void GetNumberOfOrdersForSpecificClient_OrdersExistInDatabase_NumberOfOrdersIsReturned()
        {
            //Arrange
            var    viewModel   = new OrderViewModel();
            string clientId    = "id1";
            var    ordersToAdd = OrderCreator.CreateOrders_ForSpecificCLient_TwoOrdersWithSameRequestId(clientId);

            viewModel.AddNewOrders(ordersToAdd);

            //Action
            int numberOfOrdersForClient = viewModel.GetNumberOfOrdersForSpecificClient(clientId);

            //Assert
            // There are three orders in database, but only two refere to client id ("id1"), and those two orders
            // refere to same request_id so in fact client has only one order
            Assert.AreEqual(1, numberOfOrdersForClient);
        }
Пример #11
0
        public void GetTotalPriceOfOrdersForSpecificClient_OrdersExistInDatabase_NumberOfOrdersIsReturned()
        {
            //Arrange
            string clientId    = "id1";
            var    viewModel   = new OrderViewModel();
            var    ordersToAdd = OrderCreator.CreateOrders_ForSpecificCLient_TwoOrdersWithSameRequestId(clientId);

            viewModel.AddNewOrders(ordersToAdd);
            decimal result = 246.4m;      // calculated based on the orders added into database for specific client
                                          // first request => 12 * 12.2 + 10 * 10 = 246.4 because first and second order have same request_id
                                          // sum = 246.4


            //Action
            decimal totalPriceOfOrdersForClient = viewModel.GetTotalPriceOfOrdersForSpecificClient("id1");

            //Assert
            Assert.AreEqual(result, totalPriceOfOrdersForClient);
        }
Пример #12
0
        public void GetAveragePriceOfOrderOfSpecificClient_OrdersExistInDatabase_AveragePriceIsReturned()
        {
            //Arrange
            var    viewModel   = new OrderViewModel();
            string clientId    = "id1";
            var    ordersToAdd = OrderCreator.CreateOrders_ForSpecificCLient_TwoOrdersWithSameRequestId(clientId);
            var    orderWithDifferentRequestIdForSameClient = OrderCreator.CreateOrder(clientId, 2, "Roll", 2, 4m);

            viewModel.AddNewOrder(orderWithDifferentRequestIdForSameClient);
            viewModel.AddNewOrders(ordersToAdd);
            decimal average = 127.2m;    // calculated based on the orders added into database for specific client
                                         // first request => 12 * 12.2 + 10 * 10 = 246.4 because first and second order have same request_id
                                         // second request => 2 * 4 = 8
                                         // average = 127.2

            //Action
            decimal averagePrice = viewModel.GetAveragePriceOfOrderOfSpecificClient("id1");

            //Assert
            Assert.AreEqual(average, averagePrice);
        }