public async Task <IActionResult> BuyProducts(int[] productIds) { if (!productIds.Any()) { return(new BadRequestObjectResult("You must chose some items to perchause")); } var checkInventoryCommand = new CheckInventoryCommand(productIds.ToList()); var inventoryResult = await this._mediator.Send(checkInventoryCommand); if (inventoryResult == null || !inventoryResult.Succes) { return(new BadRequestObjectResult("Some items wher out of stock")); } var buycommand = new BuyProductsCommand((List <InventoryProduct>)inventoryResult.Payload); var perchauseResult = await this._mediator.Send(buycommand); if (!perchauseResult) { return(new BadRequestObjectResult("Something went wrong")); } return(new OkObjectResult("Yai")); }
public async void ReturnTrue_AllProductsWasInStock() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ReturnTrue_AllProductsWasInStock") .Options; using (var context = new ApplicationDbContext(options)) { var unitOfWork = new UnitOfWork <ApplicationDbContext>(context); unitOfWork.Repository.Add(new InventoryProduct() { Amount = 5, Id = 1, ProductId = 1, Price = 10.0 }); await unitOfWork.SaveChanges(); var command = new CheckInventoryCommand(new List <int>() { 1 }); var handler = new CheckInventoryCommandHandler(unitOfWork); var result = handler.Handle(command, new CancellationToken()).Result; Assert.True(result.Succes); } }
public void ArgumentOutOfRangeException_ProductIdsEmpty() { var command = new CheckInventoryCommand(new List <int>()); var handler = new CheckInventoryCommandHandler(this._unitOfwork.Object); Assert.ThrowsAnyAsync <ArgumentOutOfRangeException>(() => handler.Handle(command, new CancellationToken())); }
public void ThrowArgumentNullException_ProductIdsNull() { var command = new CheckInventoryCommand(null); var handler = new CheckInventoryCommandHandler(this._unitOfwork.Object); Assert.ThrowsAnyAsync <ArgumentNullException>(() => handler.Handle(command, new CancellationToken())); }
public void GivenIHaveAddedItemIntoTheCartAndIWantThisAmount(int p0, int p1) { _itemId = p0; var tempList = new List <int>(); for (int i = 0; i < p1; i++) { tempList.Add(_itemId); } _checkInventory = new CheckInventoryCommand(tempList); }
public void ReturnNull_NullReturFromDB() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ReturnNull_NullReturFromDB") .Options; using (var context = new ApplicationDbContext(options)) { var unitOfWork = new UnitOfWork <ApplicationDbContext>(context); var command = new CheckInventoryCommand(new List <int>() { 1, 2, 3 }); var handler = new CheckInventoryCommandHandler(unitOfWork); Assert.Null(handler.Handle(command, new CancellationToken()).Result); } }