Exemplo n.º 1
0
        private void AddDroppedItem(InventoryItem droppedItem)
        {
            var existItem = InventoryItem.ExistItem(droppedItem, _client.Character);

            _client.Character.Map.Send(string.Format("{0}-{1};{2};0", Packet.CellObject, droppedItem.Cell,
                                                     droppedItem.ItemInfos.Id));

            if (existItem != null)
            {
                existItem.Quantity += droppedItem.Quantity;

                lock (DatabaseProvider.InventoryItems)
                    DatabaseProvider.InventoryItems.Remove(droppedItem);

                _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItem.Id,
                                                  existItem.Quantity));
            }
            else
            {
                droppedItem.Map       = null;
                droppedItem.Cell      = 0;
                droppedItem.Character = _client.Character;

                InventoryItemRepository.Create(droppedItem, true);

                _client.SendPackets(string.Format("{0}{1}", Packet.ObjectAdd, droppedItem.ItemInfo()));
            }
        }
Exemplo n.º 2
0
        public void GetStock_GivenAValidListOfWarehousesAndAProductID_ReturnsTheStocksInTheWarehouses()
        {
            // arrange
            List <Warehouse> warehouses = new List <Warehouse>();

            warehouses.Add(new Warehouse()
            {
                ID = 11
            });
            warehouses.Add(new Warehouse()
            {
                ID = 15
            });
            warehouses.Add(new Warehouse()
            {
                ID = 12
            });
            List <InventoryItem> data = new List <InventoryItem>();

            data.Add(new InventoryItem()
            {
                WarehouseID = 11, ProductID = 101
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 101
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 12, ProductID = 101
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 130
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 14, ProductID = 120
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 150
            });
            List <InventoryItem> expected = new List <InventoryItem>();

            expected.Add(data[0]);
            expected.Add(data[1]);
            expected.Add(data[2]);
            Mock <DbSet <InventoryItem> > mockSet     = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            var actual = sut.GetStocks(warehouses, 101);

            // assert
            Assert.IsTrue(Equality.AreEqual(expected, actual));
        }
        public ActionResult Edit([Bind(Include = "WorkingStandardId,WorkingStandardName,IdCode,MaxxamId,ExpiryDate")] WorkingStandardEditViewModel workingStandard)
        {
            if (ModelState.IsValid)
            {
                InventoryItemRepository inventoryRepo = _uow.InventoryItemRepository;
                var user = _uow.GetCurrentUser();

                InventoryItem invItem = inventoryRepo.Get()
                                        .Where(item => item.WorkingStandard != null && item.WorkingStandard.WorkingStandardId == workingStandard.WorkingStandardId)
                                        .FirstOrDefault();

                WorkingStandard updateStandard = invItem.WorkingStandard;
                updateStandard.IdCode = workingStandard.IdCode;
                updateStandard.WorkingStandardName = workingStandard.WorkingStandardName;
                updateStandard.LastModifiedBy      = user.UserName;
                updateStandard.DateModified        = DateTime.Today;
                updateStandard.ExpiryDate          = workingStandard.ExpiryDate;

                _uow.WorkingStandardRepository.Update(updateStandard);
                //_uow.Commit();

                return(RedirectToAction("Index"));
            }
            return(View(workingStandard));
        }
Exemplo n.º 4
0
        public void UpdateStock_GivenAValidItemIDAndANewStockValue_UpdatesTheRecord()
        {
            // arrange
            List <InventoryItem> data = new List <InventoryItem>();

            data.Add(new InventoryItem()
            {
                ID = 12, UnitsInStock = 3
            });
            data.Add(new InventoryItem()
            {
                ID = 20, UnitsInStock = 40
            });
            data.Add(new InventoryItem()
            {
                ID = 18, UnitsInStock = 31
            });
            Mock <DbSet <InventoryItem> > mockSet     = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            sut.UpdateStock(20, 50);

            // assert
            Assert.AreEqual(50, data[1].UnitsInStock);
            mockContext.Verify(c => c.SaveChanges(), Times.Once());
        }
Exemplo n.º 5
0
 public UnitOfWork(RestaurantContext context)
 {
     _context           = context;
     Adjustments        = new AdjustmentRepository(_context);
     AdjustmentsItems   = new AdjustmentItemRepository(_context);
     Branches           = new BranchRepository(_context);
     Categories         = new CategoryRepository(_context);
     Customers          = new CustomerRepository(_context);
     Deliveries         = new DeliveryRepository(_context);
     DeliveryItems      = new DeliveryItemRepository(_context);
     Divisions          = new DivisionRepository(_context);
     Expirations        = new ExpirationRepository(_context);
     Groups             = new GroupRepository(_context);
     Stocks             = new InventoryItemRepository(_context);
     Locations          = new LocationRepository(_context);
     Units              = new MeasurementUnitRepository(_context);
     Productions        = new ProductionRepository(_context);
     Ingredients        = new ProductionItemRepository(_context);
     Products           = new ProductRepository(_context);
     Purchases          = new PurchaseRepository(_context);
     PurchaseItems      = new PurchaseItemRepository(_context);
     PurchaseOrders     = new PurchaseOrderRepository(_context);
     PurchaseOrderItems = new PurchaseOrderItemRepository(_context);
     SalesInvoices      = new SalesInvoiceRepository(_context);
     SalesInvoiceItems  = new SalesInvoiceItemRepository(_context);
     Suppliers          = new SupplierRepository(_context);
     Transfers          = new TransferRepository(_context);
     TransferItems      = new TransferItemRepository(_context);
     Wastages           = new WastageRepository(_context);
     WastageItems       = new WastageItemRepository(_context);
     Workers            = new WorkerRepository(_context);
     ItemLocation       = new ItemLocationRepository(_context);
     StockHistory       = new StockHistoryRepository(_context);
     Currencies         = new CurrencyRepository(_context);
 }
Exemplo n.º 6
0
        public void UpdateStock_GivenAValidItemIDAndTheSameStockValue_IngnoresAndDoesNothing()
        {
            // arrange
            List <InventoryItem> data = new List <InventoryItem>();

            data.Add(new InventoryItem()
            {
                ID = 1, UnitsInStock = 1
            });
            data.Add(new InventoryItem()
            {
                ID = 2, UnitsInStock = 12
            });
            data.Add(new InventoryItem()
            {
                ID = 21, UnitsInStock = 50
            });
            data.Add(new InventoryItem()
            {
                ID = 18, UnitsInStock = 31
            });
            Mock <DbSet <InventoryItem> > mockSet     = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            sut.UpdateStock(21, 50);

            // assert
            Assert.AreEqual(50, data[2].UnitsInStock);
            mockContext.Verify(c => c.SaveChanges(), Times.Never());
        }
Exemplo n.º 7
0
        public void Generate(Character character, int quantity = 1)
        {
            var item = new InventoryItem
            {
                Id = DatabaseProvider.InventoryItems.Count > 0
                    ? DatabaseProvider.InventoryItems.OrderByDescending(x => x.Id).First().Id + 1
                    : 1,
                Character    = character,
                ItemInfos    = this,
                ItemPosition = StatsManager.Position.None,
                Stats        = ItemStats.GenerateRandomStats(Stats).ToList(),
                Quantity     = quantity
            };

            var existItem = InventoryItem.ExistItem(item, item.Character, item.ItemPosition);

            if (existItem != null)
            {
                existItem.Quantity += 1;
                InventoryItemRepository.Update(existItem);
            }
            else
            {
                InventoryItemRepository.Create(item, true);
            }
        }
        public InventoryItemController(SCMSContext _context)
        {
            var optionBuilder = new DbContextOptions <SCMSContext>();

            _inventoryItemRepository = new InventoryItemRepository(_context);
            _inventoryItemService    = new InventoryItemService(_inventoryItemRepository);
        }
Exemplo n.º 9
0
        public void Execution_deletes_product_and_associated_inventory_items()
        {
            var orderProxy = new Mock <IOrderDataProxy>();

            orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(Enumerable.Empty <Order>());

            var product = new Product()
            {
                ProductID = 1
            };
            var productDataProxy = new ProductRepository();

            productDataProxy.Clear();
            productDataProxy.Insert(product);

            var inventoryDataProxy = new InventoryItemRepository();

            inventoryDataProxy.Clear();
            inventoryDataProxy.Insert(new InventoryItem()
            {
                ProductID = 1
            });

            var command = new DeleteProductCommand(1, productDataProxy,
                                                   new InventoryItemService(inventoryDataProxy),
                                                   orderProxy.Object,
                                                   new TransactionContextStub());
            var result = command.Execute();

            result.Success.ShouldBe(true);
            result.Errors.ShouldBe(null);
            productDataProxy.GetAll().Count().ShouldBe(0);
            inventoryDataProxy.GetAll().Count().ShouldBe(0);
        }
Exemplo n.º 10
0
 public ReceiptService(Repository <Receipt> repository,
                       Repository <ReceiptItem> itemRepository,
                       InventoryItemRepository inventoryItemRepository) : base(repository)
 {
     _repository              = repository;
     _itemRepository          = itemRepository;
     _inventoryItemRepository = inventoryItemRepository;
 }
Exemplo n.º 11
0
        private ICommand <Product> CreateCommand(Product product)
        {
            var productDataProxy   = new ProductRepository();
            var inventoryDataProxy = new InventoryItemRepository();
            var inventoryService   = new InventoryItemService(inventoryDataProxy);

            return(new CreateProductCommand(product, productDataProxy, inventoryService, new TransactionContextStub()));
        }
Exemplo n.º 12
0
        public UnitOfWork(CoopEshopContext context)
        {
            ctx = context;

            Products        = new ProductRepository(ctx);
            InventoryItems  = new InventoryItemRepository(ctx);
            PriceComponents = new PriceComponentRepository(ctx);
        }
Exemplo n.º 13
0
 internal async void OnCurrentInventoryItemIDChanged(object sender, NotificationEventArgs <string> e)
 {
     using (InventoryItemRepository ctx = new InventoryItemRepository())
     {
         CurrentInventoryItem = await ctx.GetInventoryItem(e.Data).ConfigureAwait(continueOnCapturedContext: false);
     }
     NotifyPropertyChanged(m => CurrentInventoryItem);
 }
Exemplo n.º 14
0
        public ReceiptController(SCMSContext _context)
        {
            var optionBuilder = new DbContextOptions <SCMSContext>();

            _receiptRepository       = new ReceiptRepository(_context);
            _receiptItemRepository   = new ReceiptItemRepository(_context);
            _inventoryItemRepository = new InventoryItemRepository(_context);
            _receiptService          = new ReceiptService(_receiptRepository, _receiptItemRepository, _inventoryItemRepository);
        }
Exemplo n.º 15
0
 public MatchStatsBuilder(
     ImageRepository imageRepository,
     HeroesRepository heroesRepository,
     InventoryItemRepository inventoryItemRepository)
 {
     _imageRepository         = imageRepository;
     _heroesRepository        = heroesRepository;
     _inventoryItemRepository = inventoryItemRepository;
 }
Exemplo n.º 16
0
        public void GetInventory_GivenAValidWarehoue_ReturnsItsInventory()
        {
            Warehouse warehouse = new Warehouse()
            {
                ID = 11
            };
            List <InventoryItem> data = new List <InventoryItem>();

            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 20
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 21
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 21
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 11
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 23
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 11
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 11
            });
            data.Add(new InventoryItem()
            {
                ID = 1, WarehouseID = 25
            });
            List <InventoryItem> expected = new List <InventoryItem>();

            expected.Add(data[3]);
            expected.Add(data[5]);
            expected.Add(data[6]);
            Mock <DbSet <InventoryItem> > mockSet     = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            var actual = sut.GetInventory(warehouse);

            // assert
            Assert.IsTrue(Equality.AreEqual(expected, actual));
        }
 public UnitOfWork(MyDbContext context)
 {
     _context       = context;
     Users          = new UserRepository(_context);
     Items          = new ItemRepository(_context);
     UserDb         = new UserDbRepository(_context);
     Inventories    = new InventoryRepository(_context);
     InventoryItems = new InventoryItemRepository(_context);
 }
Exemplo n.º 18
0
        public async Task SelectAll()
        {
            IEnumerable <InventoryItem> lst = null;

            using (var ctx = new InventoryItemRepository())
            {
                lst = await ctx.GetInventoryItemsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            SelectedInventoryItems = new ObservableCollection <InventoryItem>(lst);
        }
Exemplo n.º 19
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var productsDataProxy  = new ProductRepository();
            var inventoryDataProxy = new InventoryItemRepository();

            _inventoryService  = new InventoryItemService(inventoryDataProxy);
            _orderItemsService = new OrderItemService(new OrderItemRepository(), productsDataProxy, _inventoryService, new DTCTransactionContext());
            _ordersService     = new OrderService(new OrderRepository(), _orderItemsService, new DTCTransactionContext());
            _customersService  = new CustomerService(new CustomerRepository(), _ordersService);
            _productsService   = new ProductService(productsDataProxy, _ordersService, _inventoryService, new DTCTransactionContext());
            _categoriesService = new CategoryService(new CategoryRepository(), _productsService);
            this.DataContext   = new MainWindowVM(_eventAggregator, _customersService, _productsService, _categoriesService, _ordersService, _inventoryService);
        }
Exemplo n.º 20
0
        public void Product_and_inventory_item_should_be_created()
        {
            var product            = CreateValidProduct();
            var productDataProxy   = new ProductRepository();
            var inventoryDataProxy = new InventoryItemRepository();
            var inventoryService   = new InventoryItemService(inventoryDataProxy);
            var command            = new CreateProductCommand(product, productDataProxy, inventoryService, new TransactionContextStub());

            var newProduct = command.Execute().Value;

            productDataProxy.GetByID(newProduct.ID).ShouldNotBeNull();
            inventoryDataProxy.GetByProduct(newProduct.ID).ShouldNotBeNull();
        }
Exemplo n.º 21
0
        private void UpdateDetailedItem(InventoryItemCreated @event)
        {
            InventoryItemEntity inventoryItem = new InventoryItemEntity
            {
                Rsn                = @event.Rsn,
                Name               = @event.Name,
                CurrentCount       = 0,
                IsLogicallyDeleted = false
            };

            // As this is the first event for this instance, no existing instance will exist, thus a create operation is executed
            InventoryItemRepository.Create(inventoryItem);
        }
Exemplo n.º 22
0
        partial void OnGetByRsn(IServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceGetByRsnParameters> serviceRequest, ref IServiceResponseWithResultData <InventoryItemEntity> results)
        {
            // Define Query
            ISingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity> query = QueryFactory.CreateNewSingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity>();

            query.QueryStrategy.WithRsn(serviceRequest.Data.rsn);

            // Retrieve Data, but remember if no items exist, the value is null
            query = InventoryItemRepository.Retrieve(query);
            InventoryItemEntity inventoryItem = query.Result;

            results = new ServiceResponseWithResultData <InventoryItemEntity>(inventoryItem);
        }
Exemplo n.º 23
0
        public void Product_and_inventory_item_should_be_created()
        {
            var product = CreateValidProduct();
            var productDataProxy = new ProductRepository();
            var inventoryDataProxy = new InventoryItemRepository();
            var inventoryService = new InventoryItemService(inventoryDataProxy);
            var command = new CreateProductCommand(product, productDataProxy, inventoryService, new TransactionContextStub());

            var newProduct = command.Execute().Value;

            productDataProxy.GetByID(newProduct.ID).ShouldNotBeNull();
            inventoryDataProxy.GetByProduct(newProduct.ID).ShouldNotBeNull();
        }
Exemplo n.º 24
0
 private void ConfigureInMemoryUsage()
 {
     var productsDataProxy = new ProductRepository();
     var inventoryDataProxy = new InventoryItemRepository();
     var customerDataProxy = new CustomerRepository();
     var orderItemDataProxy = new OrderItemRepository();
     var orderRepository = new OrderRepository(customerDataProxy, orderItemDataProxy);
     var categoriesDataProxy = new CategoryRepository();
     _inventoryService = new InventoryItemService(inventoryDataProxy);
     _orderItemsService = new OrderItemService(orderItemDataProxy, productsDataProxy, inventoryDataProxy, new DTCTransactionContext());
     _ordersService = new OrderService(orderRepository, _orderItemsService, new DTCTransactionContext());
     _customersService = new CustomerService(customerDataProxy, _ordersService);
     _productsService = new ProductService(productsDataProxy, orderRepository, _inventoryService, new DTCTransactionContext());
     _categoriesService = new CategoryService(categoriesDataProxy, productsDataProxy);
     this.DataContext = new MainWindowVM(_eventAggregator, _customersService, _productsService, _categoriesService, _ordersService, _inventoryService);
 }
Exemplo n.º 25
0
        public void GetStock_GivenAValidWarehouseAndProductID_ReturnsItsStockInTheWarehouse()
        {
            // arrange
            Warehouse warehouse = new Warehouse()
            {
                ID = 15
            };
            List <InventoryItem> data = new List <InventoryItem>();

            data.Add(new InventoryItem()
            {
                WarehouseID = 11, ProductID = 100
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 101
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 12, ProductID = 101
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 130
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 14, ProductID = 120
            });
            data.Add(new InventoryItem()
            {
                WarehouseID = 15, ProductID = 150
            });
            InventoryItem expected = data[5];
            Mock <DbSet <InventoryItem> > mockSet     = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            var actual = sut.GetStock(warehouse, 150);

            // assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 26
0
        private void ConfigureInMemoryUsage()
        {
            var productsDataProxy   = new ProductRepository();
            var inventoryDataProxy  = new InventoryItemRepository();
            var customerDataProxy   = new CustomerRepository();
            var orderItemDataProxy  = new OrderItemRepository();
            var orderRepository     = new OrderRepository(customerDataProxy, orderItemDataProxy);
            var categoriesDataProxy = new CategoryRepository();

            _inventoryService  = new InventoryItemService(inventoryDataProxy);
            _orderItemsService = new OrderItemService(orderItemDataProxy, productsDataProxy, inventoryDataProxy, new DTCTransactionContext());
            _ordersService     = new OrderService(orderRepository, _orderItemsService, new DTCTransactionContext());
            _customersService  = new CustomerService(customerDataProxy, _ordersService);
            _productsService   = new ProductService(productsDataProxy, orderRepository, _inventoryService, new DTCTransactionContext());
            _categoriesService = new CategoryService(categoriesDataProxy, productsDataProxy);
            this.DataContext   = new MainWindowVM(_eventAggregator, _customersService, _productsService, _categoriesService, _ordersService, _inventoryService);
        }
Exemplo n.º 27
0
        private void RemoveTraderItem(InventoryItem existItemTrader, GameClient traderClient, InventoryItem item)
        {
            existItemTrader.Quantity -= item.Quantity;

            if (existItemTrader.Quantity <= 0)
            {
                traderClient.SendPackets(string.Format("{0}{1}", Packet.ObjectRemove, existItemTrader.Id));

                InventoryItemRepository.Remove(existItemTrader, true);
            }
            else
            {
                traderClient.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItemTrader.Id,
                                                       existItemTrader.Quantity));

                InventoryItemRepository.Update(existItemTrader);
            }
        }
Exemplo n.º 28
0
        private void DeleteDetailedItem(InventoryItemDeactivated @event)
        {
            // Define Query
            ISingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity> query = QueryFactory.CreateNewSingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity>();

            query.QueryStrategy.WithRsn(@event.Rsn);

            // Retrieve Data, but remember if no items exist, the value is null
            query = InventoryItemRepository.Retrieve(query, false);
            InventoryItemEntity inventoryItem = query.Result;

            // As a previous event will have created this instance we should throw an exception if it is not found.
            if (inventoryItem == null)
            {
                throw new NullReferenceException(string.Format("No entity was found by the id '{0}'", @event.Rsn));
            }

            InventoryItemRepository.Delete(inventoryItem);
        }
Exemplo n.º 29
0
        private void DeleteItem(string data)
        {
            var itemId   = int.Parse(data.Split('|')[0]);
            var quantity = int.Parse(data.Split('|')[1]);

            var item =
                DatabaseProvider.InventoryItems.Find(
                    x => x.Id == itemId && x.Character.Id == _client.Character.Id && x.Quantity >= quantity);

            if (item == null)
            {
                return;
            }

            item.Quantity -= quantity;

            if (item.Quantity <= 0)
            {
                _client.SendPackets(string.Format("{0}{1}", Packet.ObjectRemove, item.Id));

                InventoryItemRepository.Remove(item, true);
            }
            else
            {
                item.Quantity = quantity;

                _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, item.Id, item.Quantity));

                InventoryItemRepository.Update(item);
            }

            RefreshCharacterStats();

            if (!item.IsEquiped())
            {
                return;
            }

            _client.Character.Stats.RemoveItemStats(item.Stats);

            _client.Character.Map.Send(string.Format("{0}{1}|{2}", Packet.ObjectAccessories, _client.Character.Id,
                                                     _client.Character.GetItemsWheneChooseCharacter()));
        }
Exemplo n.º 30
0
        public void AddToInventory_GivenANewItem_AddsToDatabase()
        {
            // arrange
            InventoryItem item = new InventoryItem()
            {
                ID = 2
            };
            List <InventoryItem>          data        = new List <InventoryItem>();
            Mock <DbSet <InventoryItem> > mockSet     = new Mock <DbSet <InventoryItem> >();
            Mock <InventoryDb>            mockContext = new Mock <InventoryDb>();

            mockContext.Setup(c => c.Inventories).Returns(mockSet.Object);
            InventoryItemRepository sut = new InventoryItemRepository(mockContext.Object);

            // act
            sut.AddToInventory(item);

            // assert
            mockSet.Verify(s => s.Add(It.Is <InventoryItem>(i => i.ID == 2)), Times.Once());
            mockContext.Verify(c => c.SaveChanges(), Times.Once());
        }
Exemplo n.º 31
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <InventoryItem> lst = null;

            using (var ctx = new InventoryItemRepository())
            {
                lst = await ctx.GetInventoryItemsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <InventoryItemExcelLine, List <InventoryItemExcelLine> >
            {
                dataToPrint = lst.Select(x => new InventoryItemExcelLine
                {
                    ItemNumber = x.ItemNumber,


                    Description = x.Description,


                    Category = x.Category,


                    TariffCode = x.TariffCode,


                    EntryTimeStamp = x.EntryTimeStamp
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
        public IList <InventoryItem> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            try
            {
                if (FilterExpression == null)
                {
                    FilterExpression = "All";
                }
                using (var ctx = new InventoryItemRepository())
                {
                    var r = ctx.LoadRange(startIndex, count, FilterExpression, navExp, IncludesLst);
                    overallCount = r.Result.Item2;

                    return(r.Result.Item1.ToList());
                }
            }
            catch (Exception ex)
            {
                StatusModel.Message(ex.Message);
                overallCount = 0;
                return(new List <InventoryItem>());
            }
        }
Exemplo n.º 33
0
        public void Execution_deletes_product_and_associated_inventory_items()
        {
            var orderProxy = new Mock<IOrderDataProxy>();
            orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(Enumerable.Empty<Order>());

            var product = new Product() { ProductID = 1 };
            var productDataProxy = new ProductRepository();
            productDataProxy.Clear();
            productDataProxy.Insert(product);

            var inventoryDataProxy = new InventoryItemRepository();
            inventoryDataProxy.Clear();
            inventoryDataProxy.Insert(new InventoryItem() { ProductID = 1 });

            var command = new DeleteProductCommand(1, productDataProxy,
                                                      new InventoryItemService(inventoryDataProxy), 
                                                      orderProxy.Object,
                                                      new TransactionContextStub());
            var result = command.Execute();
            result.Success.ShouldBe(true);
            result.Errors.ShouldBe(null);
            productDataProxy.GetAll().Count().ShouldBe(0);
            inventoryDataProxy.GetAll().Count().ShouldBe(0);
        }
Exemplo n.º 34
0
 private ICommand<Product> CreateCommand(Product product)
 {
     var productDataProxy = new ProductRepository();
     var inventoryDataProxy = new InventoryItemRepository();
     var inventoryService = new InventoryItemService(inventoryDataProxy);
     return new CreateProductCommand(product, productDataProxy, inventoryService, new TransactionContextStub());
 }