Exemple #1
0
        public void When_start_new_pos_order_should_have_new_state()
        {
            //Given...When
            var posOrder = new POSOrder();

            //Then
            Assert.Equal(OrderState.New, posOrder.State);
        }
Exemple #2
0
        /* Send order to kitchen and subsequently clear order data */
        private void DialogBoxAcceptExecute(object parameter)
        {
            POSOrder order            = new POSOrder();
            int      numOfOrderItems  = 0;
            int      iterationCounter = 0;

            // prepare order for submission to service
            for (int i = 0; i < Enum.GetNames(typeof(menuItemType)).Length; i++)
            {
                foreach (MenuItem item in menuOrderLists[i])
                {
                    numOfOrderItems++;
                }
            }
            order.menuItems = new POSMenuItem[numOfOrderItems];
            for (int i = 0; i < Enum.GetNames(typeof(menuItemType)).Length; i++)
            {
                for (int j = 0; j < menuOrderLists[i].Count; j++)
                {
                    POSMenuItem item = new POSMenuItem();
                    item.Price       = menuOrderLists[i][j].Price;
                    item.Product     = menuOrderLists[i][j].Product;
                    item.ProductType = (POSMenuItemEnum)menuOrderLists[i][j].ProductType;
                    item.Quantity    = menuOrderLists[i][j].Quantity;
                    order.menuItems[iterationCounter++] = item;
                }
            }
            order.SubTotal = float.Parse(Subtotal.Substring(1, Subtotal.Length - 1), CultureInfo.InvariantCulture.NumberFormat);
            order.Total    = float.Parse(Total.Substring(1, Total.Length - 1), CultureInfo.InvariantCulture.NumberFormat);

            // send order information to service
            eventAggregator.GetEvent <PlaceOrderEvent>().Publish(order);

            // delete all items in current order
            foreach (ObservableCollection <MenuItem> list in orderModel.menuOrderLists)
            {
                list.Clear();
            }

            // reset selected indices
            for (int i = 0; i < POSConstants.NUM_MENU_ORDER_TYPES; i++)
            {
                menuOrderListsSelectedIndex[i] = -1;
            }

            // recalculate new order price
            calcOrderPrice();

            // increment number of orders
            incrementOrder();

            // recheck order data
            removeOrderItemBtnICommand.RaiseCanExecuteChanged();

            // hide gray overlay
            takeOrderGrayOverlay = Visibility.Hidden;
            OnPropertyChanged("takeOrderGrayOverlay");
        }
Exemple #3
0
 public BaseResult <POSOrder> CreateTransaction(POSOrder transaction)
 {
     _transactionRepository.Add(transaction);
     _transactionRepository.SaveChanges();
     return(new BaseResult <POSOrder>
     {
         Success = true,
         Value = transaction
     });
 }
Exemple #4
0
        public static POSOrder GetSeedTransaction()
        {
            var product = new Core.Entities.Catalog.Product {
                Id = 1,
            };
            var posOrder     = new POSOrder();
            var quantity     = 1;
            var posOrderItem = POSOrderItem.Create(product.Id, quantity, posOrder, GetMockProductRepository());

            posOrder.AddItem(posOrderItem.Value);
            return(posOrder);
        }
Exemple #5
0
        public void When_cancel_order_order_should_be_in_cancelled_state()
        {
            // Given
            var posOrder = new POSOrder();

            //When
            posOrder.Cancel();
            //Then
            Assert.Equal(OrderState.Cancelled, posOrder.State);
            Assert.True(posOrder.HasEnded);
            Assert.False(posOrder.PaidOut);
        }
Exemple #6
0
        private POSOrder GetBasicPOSOrder()
        {
            var product = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(10, product);
            var repository = MockRepository((mock) => mock.Setup(m => m.GetBy(It.IsAny <int>()))
                                            .Returns(product));
            var posOrder = new POSOrder();

            posOrder.AddItem(product.Id, 1, repository);
            return(posOrder);
        }
Exemple #7
0
        public void If_Product_is_out_of_stock_don_t_create_item()
        {
            //Given
            var posOrder = new POSOrder();
            var product  = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(-product.QuantityInStock, product);
            // When
            var posOrderItemResult = POSOrderItem.Create(product.Id, 1, posOrder, MockRepository());

            // Then
            Assert.False(posOrderItemResult.Success);
            Assert.Null(posOrderItemResult.Value);
        }
Exemple #8
0
        public async Task <BaseResult <POSOrder> > CreateTransactionAsync(POSOrder transaction)
        {
            var validationResult = _validator.Validate(transaction);

            if (!validationResult.IsValid)
            {
                AppLogger.Log.Information("Failed to validate transaction at {className}. Validation Result:{@validationResult}", this.GetType().Name, validationResult);
                return(BaseResult <POSOrder> .Failed(validationResult.Errors.Select(e => $"validation {e.Severity} failed for property {e.PropertyName} with code {e.ErrorCode}. Reason:{e.ErrorMessage}"), transaction));
            }
            _transactionRepository.Add(transaction);
            await _transactionRepository.SaveChangesAsync();

            return(new BaseResult <POSOrder>
            {
                Success = true,
                Value = transaction
            });
        }
        public void Given_product_not_present_on_system_When_try_to_create_stock_change_Then_throw_a_exception()
        {
            // Given
            var productId   = 0;
            var impactingId = 1;
            var quantity    = 1;
            var product     = new Product
            {
                Id = productId
            };
            var posOrder = new POSOrder
            {
                Id = impactingId
            };

            // When and Then
            Assert.Throws <InvalidOperationException>(() => StockChange.CreateChange(quantity, product, posOrder));
        }
Exemple #10
0
        public void Given_negative_stock_change_When_try_update_stock_quantity_with_change_bigger_than_existing_quantity_Then_exception_is_throwed()
        {
            // Given
            var product = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(StockChange.CreateChange(quantity: 0, product, new StockEntry {
                Id = 1
            }));
            var posOrder = new POSOrder
            {
                Id = 1
            };
            int quantity    = -2;
            var stockChange = StockChange.CreateChange(quantity, product, posOrder);

            // When..., then

            Assert.Throws <ArgumentException>(() => product.UpdateStock(stockChange));
        }
Exemple #11
0
        public void When_add_new_item_of_already_present_product_sum_items()
        {
            // Given
            var product = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(14, product);
            var posOrder   = new POSOrder();
            var repository = MockRepository((mock) => mock.Setup(m => m.GetBy(It.IsAny <int>()))
                                            .Returns(product));

            posOrder.AddItem(product.Id, 2, repository);
            var expectedOrderTotal = product.EndCustomerPrice * 6;

            // When
            posOrder.AddItem(product.Id, 4, repository);
            // Then
            Assert.Equal(1, posOrder.Items.Count);
            Assert.Equal(expectedOrderTotal, posOrder.OrderTotal);
        }
Exemple #12
0
        public void If_quantity_is_bigger_than_product_stock_use_remaining_stock()
        {
            //Given
            var posOrder = new POSOrder();
            var product  = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(StockChange.CreateChange(5, product, product));
            product.UpdateStock(StockChange.CreateChange(-2, product, product));
            var quantity   = 4;
            var repository = MockRepository((mock) => {
                mock.Setup(m => m.GetBy(It.IsAny <int>()))
                .Returns(product);
            });
            //When
            var posOrderItemResult = POSOrderItem.Create(product.Id, quantity, posOrder, repository);

            //Then
            Assert.NotEqual(posOrderItemResult.Value.Quantity, quantity);
            Assert.Equal(posOrderItemResult.Value.Quantity, product.QuantityInStock);
        }
Exemple #13
0
        public async Task Given_GetTodayTransactionsAsync_When_condition_Should_expect()
        {
            // Given
            var todayDate    = DateTimeOffset.UtcNow;
            var transactions = Enumerable.Range(0, 10).Select((i) => {
                var transaction = new POSOrder
                {
                    CreatedAt = i % 2 == 0 ? todayDate : DateTimeOffset.UtcNow.AddDays(-2)
                };
                return(transaction);
            });
            var transactionRepository = new FakeRepository <POSOrder>(transactions);
            var service = new POSOrderService(transactionRepository, new TransactionValidator());
            // When
            //var result = Task.Run(async () => await service.GetTodayTransactionsAsync());
            //var result = ;
            var result = await service.GetTodayTransactionsAsync().ToListAsync();

            // Then
            Assert.NotEmpty(result);
            result.ForEach(transaction => Assert.True(transaction.CreatedAt.Day >= todayDate.Day));
        }
Exemple #14
0
        public void Given_negative_stock_change_When_try_update_stock_quantity_of_a_product_Then_current_stock_quantity_should_be_actual_stock_quantity_minus_stock_change()
        {
            // Given
            var product = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(StockChange.CreateChange(4, product, new StockEntry {
                Id = 1
            }));
            var posOrder = new POSOrder
            {
                Id = 1
            };
            int quantity         = -2;
            int expectedQuantity = 2;
            var stockChange      = StockChange.CreateChange(quantity, product, posOrder);

            // When
            product.UpdateStock(stockChange);
            // Then
            Assert.Equal(expectedQuantity, product.QuantityInStock);
        }
Exemple #15
0
        public void Create_Item_from_product_id_and_quantity()
        {
            //Given
            var posOrder = new POSOrder();
            var product  = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(4, product);
            var quantity           = 4;
            var expectedOrderTotal = product.EndCustomerPrice * quantity;
            var repository         = MockRepository((mock) => {
                mock.Setup(m => m.GetBy(It.IsAny <int>()))
                .Returns(product);
            });
            //When
            var item = POSOrderItem.Create(product.Id, quantity, posOrder, repository);

            //Then
            Assert.True(item.Success);
            Assert.NotNull(item.Value);
            Assert.Equal(expectedOrderTotal, item.Value.Total);
            Assert.Equal(item.Value.POSOrderId, posOrder.Id);
        }
Exemple #16
0
        public void When_try_add_item_to_cancelled_item_shouldnt_update_object()
        {
            //Given
            var product = new ProductSeed().GetSeedObject();

            product.Id = 1;
            product.UpdateStock(3, product);

            var posOrder   = new POSOrder();
            var repository = MockRepository((mock) => mock.Setup(m => m.GetBy(It.IsAny <int>()))
                                            .Returns(product));
            var expectedQuantity = 1;

            posOrder.AddItem(product.Id, expectedQuantity, repository);
            posOrder.Cancel();

            //When
            posOrder.AddItem(product.Id, 1, repository);

            //Then
            var item = posOrder.Items.FirstOrDefault();

            Assert.Equal(expectedQuantity, item.Quantity);
        }
Exemple #17
0
 /* Send order details to service */
 public void SendOrderToService(POSOrder order)
 {
     // send order info to service
     proxy.SubmitOrder(order);
 }