public async Task AddStockPart_WithNonExistingName_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _partService.AddStock("name", 5)); }
public async Task AddStockPart_WithCorrectData_ShouldAddStock() { string errorMessagePrefix = "PartService AddStock() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); bool actualResult = await _partService.AddStock("Blot 10.5x2", 5); Assert.True(actualResult, errorMessagePrefix); }
public async Task <IActionResult> AddStock(PartAddStockBindingModel partAddStockBinding) { if (ModelState.IsValid) { var result = await _partService.AddStock(partAddStockBinding.Name, partAddStockBinding.Quantity); if (result == false) { this.ViewData["error"] = ControllerConstants.PartAddStockErrorMessage; return(this.Redirect($"/Part/Details?name={partAddStockBinding.Name}")); } return(this.Redirect($"/Part/Details?name={partAddStockBinding.Name}")); } this.ViewData["error"] = ControllerConstants.InputErrorMessage; return(this.Redirect($"/Part/Details?name={partAddStockBinding.Name}")); }