public void WhenOrderIsReturnedByTheRepository_ShouldReturnTheSameOrder()
        {
            int orderId = 3;
            var order   = new Order()
            {
                Id = 3
            };

            // Arange
            var orderRepo = MockRepository.GenerateStub <IRepository <Order> >();

            var list = new List <Order>();

            list.Add(order);

            orderRepo.Stub(x => x.Table).Return(list.AsQueryable());
            orderRepo.Stub(x => x.GetById(orderId)).Return(order);

            // Act
            var cut    = new OrderApiService(orderRepo);
            var result = cut.GetOrderById(orderId);

            // Assert
            Assert.AreSame(order, result);
        }
Пример #2
0
        public void WhenCalledWithDefaultParameters_GivenOnlyDeletedOrdersExist_ShouldReturnEmptyCollection()
        {
            var existingOrders = new List <Order>();

            existingOrders.Add(new Order()
            {
                Id = 1, Deleted = true
            });
            existingOrders.Add(new Order()
            {
                Id = 2, Deleted = true
            });

            // Arange
            var orderRepo = MockRepository.GenerateStub <IRepository <Order> >();

            orderRepo.Stub(x => x.TableNoTracking).Return(existingOrders.AsQueryable());

            // Act
            var cut    = new OrderApiService(orderRepo);
            var orders = cut.GetOrders();

            // Assert
            CollectionAssert.IsEmpty(orders);
        }
Пример #3
0
        public void WhenCalledWithDefaultParameters_GivenSomeOrdersExist_ShouldReturnThemSortedById()
        {
            var existingOrders = new List <Order>();

            existingOrders.Add(new Order()
            {
                Id = 2
            });
            existingOrders.Add(new Order()
            {
                Id = 3
            });
            existingOrders.Add(new Order()
            {
                Id = 1
            });

            var expectedCollection = existingOrders.Where(x => !x.Deleted).OrderBy(x => x.Id);

            // Arange
            var orderRepo = MockRepository.GenerateStub <IRepository <Order> >();

            orderRepo.Stub(x => x.TableNoTracking).Return(existingOrders.AsQueryable());

            // Act
            var cut    = new OrderApiService(orderRepo);
            var orders = cut.GetOrders();

            // Assert
            CollectionAssert.IsNotEmpty(orders);
            Assert.AreEqual(expectedCollection.Count(), orders.Count);
            Assert.IsTrue(orders.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id)));
        }
        public void WhenCalledWithDefaultParameters_GivenSomeOrdersExist_ShouldReturnTheirCount()
        {
            var existingOrders = new List <Order>();

            existingOrders.Add(new Order()
            {
                Id = 2
            });
            existingOrders.Add(new Order()
            {
                Id = 3
            });
            existingOrders.Add(new Order()
            {
                Id = 1
            });

            // Arange
            var ordersRepo = MockRepository.GenerateStub <IRepository <Order> >();

            ordersRepo.Stub(x => x.TableNoTracking).Return(existingOrders.AsQueryable());

            // Act
            var cut         = new OrderApiService(ordersRepo);
            var countResult = cut.GetOrdersCount();

            // Assert
            Assert.AreEqual(existingOrders.Count, countResult);
        }
Пример #5
0
        async void GetOrders()
        {
            OrderApiService service = new OrderApiService();

            List <OrderShowVM> list = await service.GetOrdersAsync();

            Orders.Clear();
            Orders.AddRange(list);
            FillGrid();
        }
        public void WhenNegativeOrZeroOrderIdPassed_ShouldReturnNull(int negativeOrZeroOrderId)
        {
            // Aranges
            var orderRepoStub = MockRepository.GenerateStub <IRepository <Order> >();

            // Act
            var cut    = new OrderApiService(orderRepoStub);
            var result = cut.GetOrderById(negativeOrZeroOrderId);

            // Assert
            Assert.IsNull(result);
        }
Пример #7
0
        public void WhenCalledWithDefaultParameters_GivenNoOrdersExist_ShouldReturnEmptyCollection()
        {
            // Arange
            var ordersRepo = MockRepository.GenerateStub <IRepository <Order> >();

            ordersRepo.Stub(x => x.TableNoTracking).Return(new List <Order>().AsQueryable());

            // Act
            var cut    = new OrderApiService(ordersRepo);
            var orders = cut.GetOrders();

            // Assert
            CollectionAssert.IsEmpty(orders);
        }
        public void WhenCalledWithDefaultParameters_GivenNoOrdersExist_ShouldReturnZero()
        {
            // Arange
            var orderRepo = MockRepository.GenerateStub <IRepository <Order> >();

            orderRepo.Stub(x => x.TableNoTracking).Return(new List <Order>().AsQueryable());

            // Act
            var cut         = new OrderApiService(orderRepo);
            var ordersCount = cut.GetOrdersCount();

            // Assert
            Assert.AreEqual(0, ordersCount);
        }
        public void WhenNullIsReturnedByTheRepository_ShouldReturnNull()
        {
            int orderId = 3;

            // Arange
            var orderRepo = MockRepository.GenerateStub <IRepository <Order> >();

            orderRepo.Stub(x => x.Table).Return((new List <Order>()).AsQueryable());
            orderRepo.Stub(x => x.GetById(orderId)).Return(null);

            // Act
            var cut    = new OrderApiService(orderRepo);
            var result = cut.GetOrderById(orderId);

            // Assert
            Assert.IsNull(result);
        }
Пример #10
0
 private void BtnConfirm_Click(object sender, RoutedEventArgs e)
 {
     if (Convert.ToInt32(txtCode.Text) == code)
     {
         MessageBox.Show("Замовлення успішно підтвердженно.", "Підтверження.");
         OrderApiService service = new OrderApiService();
         service.CreateAsync(new OrderAddVM {
             Car = _order.Car, Client = _order.Client, Date = DateTime.Now
         });
         ShowOrderWindow showOrderWindow = new ShowOrderWindow();
         showOrderWindow.Show();
         // this.Close();
     }
     else
     {
         MessageBox.Show("Введений код не збігається з кодом, який був відправлений.", "Підтверження.");
     }
 }