public PurchaseOrderItemController(SCMSContext _context)
        {
            var optionBuilder = new DbContextOptions <SCMSContext>();

            _purchaseOrderItemRepository = new PurchaseOrderItemRepository(_context);
            _purchaseOrderItemService    = new PurchaseOrderItemService(_purchaseOrderItemRepository);
        }
        public async Task UpdatePurchaseOrderItemAsync_Throws_ConflictException()
        {
            //Arrange
            var id = 2;

            _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >()))
            .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockPurchaseOrderItemService.Setup(x => x.UpdatePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>()));

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdatePurchaseOrderItemAsync(id, new EditPurchaseOrderItemDto
            {
                PurchaseOrderId = 202,
                ItemId          = 20024,
                ItemUnitPrice   = 260,
                Quantity        = 6
            }));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict);
            exception.ErrorMessage.Should().Be("Item already available for this purchase request.");
            exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString());
        }
예제 #3
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);
 }
        public async Task GetPurchaseOrderItemAsync_Throws_NotFoundException()
        {
            //Arrange
            var id = 201;

            _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >()))
            .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression)));

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.GetPurchaseOrderItemAsync(id));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Purchase order item not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }
        public async Task DeletePurchaseOrderItemAsync_Returns_NoResult()
        {
            //Arrange
            var id = 2;

            _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >()))
            .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockPurchaseOrderItemService.Setup(x => x.DeletePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>()));

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            await repository.DeletePurchaseOrderItemAsync(id);

            // Assert
            _fixture.MockPurchaseOrderItemService.Verify(x => x.DeletePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>()), Times.Once);
        }
        public async Task CreatePurchaseOrderItemAsync_Returns_New_GetPurchaseOrderItemDto()
        {
            //Arrange
            _fixture.MockPurchaseOrderItemService.Setup(x => x.AddPurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>()))
            .ReturnsAsync(_fixture.CreatedNewPurchaseOrderItem);

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            var result = await repository.CreatePurchaseOrderItemAsync(_fixture.CreatePurchaseOrderItemDto);

            //Assert
            result.Should().BeOfType(typeof(GetPurchaseOrderItemDto));
            result.Id.Should().Be(5);
            result.ItemTypeName.Should().Be("Grocery");
            result.ItemName.Should().Be("Rice");
            result.ItemUnitPrice.Should().Be(350);
            result.Quantity.Should().Be(5);
        }
        public async Task GetPurchaseOrderItemAsync_Returns_GetPurchaseOrderItemDto()
        {
            //Arrange
            var id = 1;

            _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >()))
            .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression)));

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            var result = await repository.GetPurchaseOrderItemAsync(id);

            //Assert
            result.Should().BeOfType(typeof(GetPurchaseOrderItemDto));
            result.Id.Should().Be(id);
            result.ItemTypeName.Should().Be("Grocery");
            result.ItemName.Should().Be("Rice");
        }
        public async Task GetPurchaseOrderItemsAsync_Returns_GetPurchaseOrderItemDtos()
        {
            //Arrange
            _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemsAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >()))
            .Returns <Expression <Func <PurchaseOrderItem, bool> > >(async(expression) =>
            {
                var orders = _fixture.PurchaseOrderItems.AsQueryable().Where(expression).ToList();
                return(await Task.FromResult(orders));
            });

            var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object);

            //Act
            var result = await repository.GetPurchaseOrderItemsAsync(101);

            //Assert
            var items = result.Should().BeAssignableTo <IEnumerable <GetPurchaseOrderItemDto> >().Subject;

            items.Should().HaveCount(2);
        }
예제 #9
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context             = context;
     StockItems           = new StockRepository(_context);
     Invoices             = new InvoiceRepository(_context);
     JobCards             = new JobCardRepository(_context);
     JobStatuses          = new JobStatusRepository(_context);
     Suppliers            = new SupplierRepository(_context);
     JobTypes             = new JobTypeRepository(_context);
     Customers            = new CustomerRepository(_context);
     ServiceContracts     = new ServiceContractRepository(_context);
     MaintenanceContracts = new MaintenanceContractRepository(_context);
     Areas                     = new AreaRepository(_context);
     PurchaseOrders            = new PurchaseOrderRepository(_context);
     PurchaseOrderItems        = new PurchaseOrderItemRepository(_context);
     ApplicationUserSignatures = new ApplicationUserSignatureRepository(_context);
     CustomerSignatures        = new CustomerSignatureRepository(_context);
     JobStatusHistory          = new JobStatusHistoryRepository(_context);
     Quotes                    = new QuotationRepository(_context);
     StockItemQuantities       = new StockItemQuantityRepository(_context);
 }
 public ReceivingController()
 {
     poItemRepo = new PurchaseOrderItemRepository(context);
 }