public IHttpActionResult Get(int id) { OrderItemsService orderItemsService = CreateOrderItemsService(); var orderItems = orderItemsService.GetOrderItemsById(id); return(Ok(orderItems)); }
public async Task AddOrderItemsShouldUpdateQtyIfItemsIsAlreadyAdded() { var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var context = new WHMSDbContext(options); var warehouse = new Warehouse { Address = new Address { }, Name = "Test", }; var product = new Product { ProductName = "Test Product", }; var productWarehouse = new ProductWarehouse { Product = product, Warehouse = warehouse, AggregateQuantity = 0, TotalPhysicalQuanitiy = 10, ReservedQuantity = 5, }; context.Warehouses.Add(warehouse); context.Products.Add(product); context.ProductWarehouses.Add(productWarehouse); var order = new Order { WarehouseId = warehouse.Id }; context.Orders.Add(order); var orderItem = new OrderItem { OrderId = order.Id, ProductId = product.Id, Qty = 3 }; context.Orders.Add(order); context.OrderItems.Add(orderItem); await context.SaveChangesAsync(); var mockInventoryService = new Mock <IInventoryService>(); var mockOrdersService = new Mock <IOrdersService>(); var service = new OrderItemsService(context, mockInventoryService.Object, mockOrdersService.Object); var model = new AddOrderItemsInputModel { OrderId = order.Id, OrderItems = new List <AddOrderItemViewModel> { new AddOrderItemViewModel { ProductId = product.Id, Price = 100, Qty = -30 } } }; var id = await service.AddOrderItemAsync(model); var orderItemDB = context.OrderItems.FirstOrDefault(); Assert.Null(orderItemDB); }
public async Task AddOrderItemsShouldAddNewItemsToOrderWhenAddingItemsFromProduct() { var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var context = new WHMSDbContext(options); var warehouse = new Warehouse { Address = new Address { }, Name = "Test", }; var product = new Product { ProductName = "Test Product", }; var productWarehouse = new ProductWarehouse { Product = product, Warehouse = warehouse, AggregateQuantity = 0, TotalPhysicalQuanitiy = 10, ReservedQuantity = 5, }; context.Warehouses.Add(warehouse); context.Products.Add(product); context.ProductWarehouses.Add(productWarehouse); var order = new Order { WarehouseId = warehouse.Id }; context.Orders.Add(order); await context.SaveChangesAsync(); var mockInventoryService = new Mock <IInventoryService>(); var mockOrdersService = new Mock <IOrdersService>(); var service = new OrderItemsService(context, mockInventoryService.Object, mockOrdersService.Object); var model = new AddProductToOrderInputModel { OrderId = order.Id, ProductId = product.Id, Qty = 10 }; var id = await service.AddOrderItemAsync(model); var orderItemDB = context.OrderItems.FirstOrDefault(); Assert.NotNull(orderItemDB); Assert.Equal(order.Id, id); Assert.True(orderItemDB.OrderId == order.Id); Assert.True(orderItemDB.ProductId == product.Id); }
public OrderItemsServiceTest() { AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly); this.orderItemsRepo = new Mock <IDeletableEntityRepository <OrderItem> >(); this.gamesRepo = new Mock <IDeletableEntityRepository <Game> >(); this.orderItemsList = new List <OrderItem>(); this.service = new OrderItemsService(this.orderItemsRepo.Object, this.gamesRepo.Object); this.orderItemsRepo.Setup(x => x.All()).Returns(this.orderItemsList.AsQueryable()); this.orderItemsRepo.Setup(x => x.AddAsync(It.IsAny <OrderItem>())).Callback( (OrderItem item) => this.orderItemsList.Add(item)); this.orderItemsRepo.Setup(x => x.Delete(It.IsAny <OrderItem>())).Callback( (OrderItem item) => this.orderItemsList.Remove(item)); }
public OrderItemsController(IConfiguration configuration) { var connectionString = configuration.GetConnectionString("ConnectionString"); this.orderItemsService = new OrderItemsService(new OrderItemsRepository(connectionString)); }
private OrderItemsService CreateOrderItemsService() { var orderItemsService = new OrderItemsService(); return(orderItemsService); }
public OrderItemsController(OrderItemsService orderItemsService) { _context = orderItemsService; }