Exemplo n.º 1
0
        public void AddProduct_AddProductWithPrice18QuantityMinus3ToCurrentOrder_TotalIsMinus3Times18()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer, -3);
            Assert.That(_uut.CurrentOrder.Total, Is.EqualTo(-3 * 18));
        }
        public void AddProduct_ProductIsAddedToOrder_OrderLineContainsQuantity()
        {
            var product = new Product("Beer", 18, true);

            _salesController.AddProductToOrder(product, 1, null);

            Assert.That(_orderLines[0].Quantity, Is.EqualTo(1));
        }
        public void StartPayment_ProductIsAddedToOrderExactAmountIsPayed_CashDrawerOpenIsCalledOnce()
        {
            var product = new Product("Beer", 18, true);

            _salesController.AddProductToOrder(product, 1, null);
            _salesController.StartPayment(18, "", PaymentType.Cash);

            _cashDrawer.Received(1).Open();
        }
Exemplo n.º 4
0
        public void AddProduct_AddProductToOrderLine_OrderLineIsProduct()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer, 3);
            var uutLines = _uut.CurrentOrder.Lines.ToList();

            Assert.That(uutLines[0].Product, Is.EqualTo(beer));
        }
        public void StartPayment_ProductIsAddedToOrderExactAmountIsPayed_OrderDaoUpdateIsCalledOnce()
        {
            var product = new Product("Beer", 18, true);

            _salesController.AddProductToOrder(product, 1, null);
            _salesController.StartPayment(18, "", PaymentType.Cash);

            _orderDao.Received(1).Update(Arg.Any<SalesOrder>());
        }
Exemplo n.º 6
0
        public void AddProduct_AddProductWithPrice18_ProductIsAddedToOrderLines()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer);
            var uutLines = _uut.CurrentOrder.Lines.ToList();

            Assert.That(uutLines[0].Product, Is.EqualTo(beer));
        }
        public void AddProduct_TwoProductsAreAddedToOrder_OrderDaoAddOrderLineIsCalledTwice()
        {
            var productOne = new Product("Beer", 18, true);
            var productTwo = new Product("Vodka", 40, true);

            _salesController.AddProductToOrder(productOne, 1, null);
            _salesController.AddProductToOrder(productTwo, 1, null);

            _orderDao.Received(2).AddOrderLine(Arg.Any<OrderLine>());
        }
        public void CancelOrder_TwoProductsAreAddedToOrderThenCancelOrderIsCalled_OrderDaoClearOrderIsCalledOnce()
        {
            var productOne = new Product("Beer", 18, true);
            var productTwo = new Product("Vodka", 40, true);

            _salesController.AddProductToOrder(productOne, 1, null);
            _salesController.AddProductToOrder(productTwo, 1, null);
            _salesController.CancelOrder();

            _orderDao.Received(1).ClearOrder(Arg.Any<SalesOrder>());
        }
Exemplo n.º 9
0
        public void GetById_ProductWithId1IsRequested_ProductIsReturnedFromDbNameIsEqual()
        {
            var testProduct = new Product("Kildevand", 18, true);

            using (var context = new CashRegisterContext())
            {
                context.Products.Add(testProduct);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);
                var result = uut.GetById((long)1);
                Assert.That(result.Name, Is.EqualTo("Kildevand"));
            }
        }
Exemplo n.º 10
0
        public void Delete_ProductIsDeleted_NoProductsInDatabase()
        {
            var testProduct = new Product("Kildevand", 18, true);

            using (var context = new CashRegisterContext())
            {
                context.Products.Add(testProduct);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);

                uut.Delete(testProduct);
                context.SaveChanges();

                var result = context.Products.AsEnumerable();
                Assert.That(result, Is.Empty);
            }
        }
        public void StartPayment_ProductIsAddedToOrderExactAmountIsPayed_OrderDaoUpdateIsCalledTwice2()
        {
            var product = new Product("Beer", 18, true);

            _salesController.AddProductToOrder(product, 1, null);
            _salesController.StartPayment(10, "", PaymentType.Cash);
            _salesController.StartPayment(8, "", PaymentType.Cash);

               Assert.That(_salesController.MissingPaymentOnOrder(),Is.EqualTo(0));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Adds products to the current SalesOrder.
 /// </summary>
 /// <param name="product">The Product to be added to the SalesOrder.</param>
 /// <param name="quantity">The quantity of the Product. Can be negative.</param>
 /// <param name="discount">A discount on the product. Can be null.</param>
 public void AddProductToOrder(Product product, int quantity, Discount discount)
 {
     _orderController.AddProduct(product, quantity, discount);
     _logger.Debug("Product Added");
 }
Exemplo n.º 13
0
        public void ClearOrder_ClearsCurrentOrderLines_CurrentOrderLinesIsCleared()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer, 3);
            _uut.ClearOrder();
            Assert.That(_uut.CurrentOrder.Lines, Is.Empty);
        }
Exemplo n.º 14
0
        public void Update_ProductIsUpdated_UpdatedProductCanBeFoundInDb()
        {
            var testProduct = new Product("Kildevand", 18, true);

            using (var context = new CashRegisterContext())
            {
                context.Products.Add(testProduct);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);

                var modifiedProduct = context.Products.FirstOrDefault(p => p.Id == 1);
                modifiedProduct.Price = 20;

                uut.Update(modifiedProduct);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var modifiedProduct = context.Products.FirstOrDefault(p => p.Id == 1);

                var result = context.Products.FirstOrDefault(p => p.Id == 1);
                Assert.That(modifiedProduct.Price, Is.EqualTo(20));
            }
        }
Exemplo n.º 15
0
        public void Insert_ProductIsInserted_ProductCanBeFoundInDb()
        {
            var product = new Product("Øl", 20, true);

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);
                uut.Insert(product);
                context.SaveChanges();

                var result = context.Products.FirstOrDefault(p => p.Id == 1);
                Assert.That(result, Is.EqualTo(product));
            }
        }
Exemplo n.º 16
0
        public void Get_ProductsIsRequested_ProductPriceIsInCollectionFromDb()
        {
            var testProduct = new Product("Kildevand", 18, true);

            using (var context = new CashRegisterContext())
            {
                context.Products.Add(testProduct);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);
                var result = uut.Get().ElementAt(0);
                Assert.That(result.Price, Is.EqualTo(18));
            }
        }
Exemplo n.º 17
0
        public void Get_ProductIsRequestedWithWhereClause_ProductId2IsReturned()
        {
            var testProduct1 = new Product("Kildevand", 18, true);
            var testProduct2 = new Product("Øl", 20, false);

            using (var context = new CashRegisterContext())
            {
                context.Products.Add(testProduct1);
                context.Products.Add(testProduct2);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<Product>(context);
                var result = uut.Get(x => x.Id == 2).ElementAt(0);
                Assert.That(result.Name, Is.EqualTo("Øl"));
            }
        }
Exemplo n.º 18
0
        public void Get_ProductIsRequestedWithFilteredClauseWithoutLazyLoading_ProductCollectionContainsNoProductList()
        {
            var testProduct1 = new Product("Kildevand", 18, true);
            var testProduct2 = new Product("Øl", 20, false);

            var testProductGroup = new ProductGroup() { Name = "Drikkevarer" };
            testProductGroup.Products.Add(testProduct1);
            testProductGroup.Products.Add(testProduct2);

            using (var context = new CashRegisterContext())
            {
                context.ProductGroups.Add(testProductGroup);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                context.Configuration.LazyLoadingEnabled = false;
                var uut = new Repository<ProductGroup>(context);
                var result = uut.Get().ElementAt(0);
                Assert.That(result.Products.Count, Is.EqualTo(0));
            }
        }
Exemplo n.º 19
0
        public void AddProduct_SetProductQuantityN_QuantityIsN(int n)
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer, n);
            var uutLines = _uut.CurrentOrder.Lines.ToList();

            Assert.That(uutLines[0].Quantity, Is.EqualTo(n));
        }
Exemplo n.º 20
0
 /// <summary>
 /// Adds an amount of products to the current SalesOrder.
 /// </summary>
 /// <param name="product">Product to be added to the SalesOrder.</param>
 public void AddProduct(Product product)
 {
     AddProduct(product, 1);
 }
Exemplo n.º 21
0
        public void MissingAmount_CurrentOrderIsPopulatedWith3Times18ProductAndTransactionFor18IsDone_MissingAmountIs36()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer, 3);

            _uut.CurrentOrder.Transactions.Add(new Transaction() {Price = 18});

            Assert.That(_uut.MissingAmount(), Is.EqualTo(36));
        }
Exemplo n.º 22
0
        public void AddProduct_AddProductWithPrice18_TotalIs18()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer);
            Assert.That(_uut.CurrentOrder.Total, Is.EqualTo(18));
        }
Exemplo n.º 23
0
 /// <summary>
 /// Adds an amount of products to the current order.
 /// </summary>
 /// <param name="product">Product to be added to the SalesOrder.</param>
 /// <param name="quantity">The quantity of the Product. Can be negative.</param>
 public void AddProduct(Product product, int quantity)
 {
     AddProduct(product, quantity, null);
 }
Exemplo n.º 24
0
        public void Get_ProductIsRequestedWithEmptyFilteredClause_ArgumentExceptionIsThrown()
        {
            var testProduct1 = new Product("Kildevand", 18, true);
            var testProduct2 = new Product("Øl", 20, false);

            var testProductGroup = new ProductGroup() { Name = "Drikkevarer" };
            testProductGroup.Products.Add(testProduct1);
            testProductGroup.Products.Add(testProduct2);

            using (var context = new CashRegisterContext())
            {
                context.ProductGroups.Add(testProductGroup);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<ProductGroup>(context);
                var filter = new[] { "" };
                Assert.That(() => uut.Get(null, null, filter).ElementAt(0), Throws.ArgumentException);
            }
        }
Exemplo n.º 25
0
        public void AddProduct_AddProductWithPrice18_QuantityIsOne()
        {
            var beer = new Product("Øl", 18, true);

            _uut.AddProduct(beer);
            var uutLines = _uut.CurrentOrder.Lines.ToList();

            Assert.That(uutLines[0].Quantity, Is.EqualTo(1));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Adds an amount of products to the current order.
        /// </summary>
        /// <param name="product">Product to be added to the SalesOrder.</param>
        /// <param name="quantity">The quantity of the product. Can be negative.</param>
        /// <param name="discount">The discount on the product. Can be null.</param>
        public void AddProduct(Product product, int quantity, Discount discount)
        {
            var orderLine = new OrderLine
            {
                SalesOrder = CurrentOrder,
                Product = product,
                Quantity = quantity,
                Discount = discount,
                UnitPrice = product.Price,
                DiscountValue = (discount == null ? 0 : discount.Percent / 100 * product.Price)
            };

            OrderDao.AddOrderLine(orderLine);
            OnPropertyChanged(nameof(CurrentOrder));
        }
        public void SetUp()
        {
            _raisedEvent = 0;
            _discount = new Discount();
            _product = new Product("Test", 100, true);

            _printer = Substitute.For<IPrinter>();
            _cashDrawer = Substitute.For<ICashDrawer>();
            _dalFacade = Substitute.For<IDalFacade>();

            _productDao = new ProductDao(_dalFacade);
            _paymentDao = new PaymentDao(_dalFacade);
            _orderDao = new OrderDao(_dalFacade);
            _receiptController = new ReceiptController(_printer);
            _productController = new ProductController(_productDao);
            var paymentProviders = new List<IPaymentProvider> { new CashPayment() };
            _paymentController = new PaymentController(paymentProviders, _receiptController, _paymentDao, _cashDrawer);
            _orderController = new OrderController(_orderDao);
            _salesController = new SalesController(_orderController, _receiptController, _productController,
                _paymentController);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="row">The row location of the TabItem.</param>
 /// <param name="column">The column location of the TabItem.</param>
 /// <param name="productType">The ProductType of the TabItem.</param>
 /// <param name="command">An ICommand implementation.</param>
 /// <param name="product">The Product that the TabItem references.</param>
 public TabItem(int row, int column, ProductType productType, ICommand command, Product product)
 {
     Row = row;
     Column = column;
     ProductType = productType;
     Command = command;
     Product = product;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Removes a Product from SalesOrder by added a OrderLine that has a negative quantity.
 /// </summary>
 /// <param name="product">The Product to be removed from the SalesOrder.</param>
 /// <param name="quantity">The quantity of the Product.</param>
 /// <param name="discount">A discount on the product. Can be null.</param>
 public void RemoveProductFromOrder(Product product, int quantity, Discount discount)
 {
     _orderController.AddProduct(product, -quantity, discount);
 }
Exemplo n.º 30
0
 /// <summary>
 /// The logic for AddProduct.
 /// </summary>
 /// <param name="product">The product to be added.</param>
 private void AddProductCommand(Product product)
 {
     _salesController.AddProductToOrder(product, _numpad.Amount, new Discount {Description = "No DISCOUNT FOR YOU", Percent = 0});
     _numpad.ClearNumpad();
 }