Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }