public async Task Delete_WithValidId_ShouldReturnViewWithCorrectModel() { // Arrange const int id = 1; this.InitializeTempData(this.manufacturerController); var expectedModel = new ManufacturerUpdateServiceModel { Id = id, Name = SampleManufacturerName }; this.manufacturers .Setup(s => s.GetForUpdateAsync(It.IsAny <int>())) .ReturnsAsync(expectedModel); // Act var result = await this.manufacturerController.Delete(id) as ViewResult; var model = result?.ViewData.Model; // Assert result .Should() .NotBeNull(); model .Should() .NotBeNull() .And .BeEquivalentTo(expectedModel); }
public async Task Delete_WithValidId_ShouldReturnViewWithCorrectModel() { // Arrange this.InitializeTempData(this.controller); var expectedModel = new ManufacturerUpdateServiceModel { Id = 1, Name = "Mercedes-Benz" }; this.manufacturerService .Setup(s => s.GetForUpdateAsync(It.IsAny <int>())) .ReturnsAsync(expectedModel); // Act var result = await this.controller.Delete(1) as ViewResult; var actionModel = result?.ViewData.Model as ManufacturerUpdateServiceModel; // Assert result .Should() .NotBeNull(); actionModel .Should() .NotBeNull() .And .BeEquivalentTo(expectedModel); }
public async Task <IActionResult> Edit(ManufacturerUpdateServiceModel model) { var success = await this.manufacturers.UpdateAsync(model.Id, model.Name); if (!success) { this.ShowNotification(NotificationMessages.InvalidOperation); } else { this.ShowNotification(string.Format( NotificationMessages.ManufacturerUpdatedSuccessfull, model.Name), NotificationType.Success); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Delete(ManufacturerUpdateServiceModel model) { if (!this.ModelState.IsValid) { return(View(model)); } var success = await this.manufacturers.DeleteAsync(model.Id); if (!success) { this.ShowNotification(NotificationMessages.InvalidOperation); } else { this.ShowNotification(string.Format( NotificationMessages.ManufacturerDeletedSuccessfully, model.Name), NotificationType.Success); } return(RedirectToAction(nameof(Index))); }