public async Task UpdateManager_WhenCalled_UpdateExistingManager() { const int id = 1; const string updateName = "Unai Emery"; var managerUpdateDto = new ManagerUpdateDto { Name = updateName }; var manager = new Manager { Id = id, Name = "Josep Guardiola" }; var expectedManager = new Manager { Id = id, Name = updateName }; _managerService.Setup(m => m.GetByIdAsync(id)).ReturnsAsync(manager); _managerService.Setup(m => m.GetDetailByIdAsync(id)).ReturnsAsync(expectedManager); var result = await _managersController.UpdateManager(id, managerUpdateDto); var okObjectResult = result as OkObjectResult; var okObjectResultValue = okObjectResult.Value as ManagerDetailDto; _managerService.Verify(m => m.UpdateAsync(It.IsAny <Manager>()), Times.Once); Assert.That(result, Is.TypeOf <OkObjectResult>()); Assert.That(okObjectResultValue.Name, Is.EqualTo(updateName)); }
public async void TestUpdateManagersAsync() { var dbContext = DbContextMocker.GetContext(nameof(this.TestUpdateManagersAsync)); var managersRepository = new ManagersRepository(dbContext, AutoMapperConfiguration.ConfigureForWeb().CreateMapper()); var managersService = new ManagersService(managersRepository, null); var controller = new ManagersController(managersService, AutoMapperConfiguration.ConfigureForWeb().CreateMapper()); var parameters = new JObject() { new JProperty("customerName", "test"), new JProperty("managerId", "1"), }; var manager = dbContext.Managers.FirstOrDefault(); var updatewith = new ManagersViewModel() { Id = manager.Id, FirstName = "johnTEST", LastName = "Shon", }; var response = await controller.UpdateManager(updatewith); Assert.Equal(updatewith.FirstName, dbContext.Managers.Find(manager.Id).FirstName); dbContext.Dispose(); }