public async void DeleteEmployeeAsync(int id) { // Arrange // Act //await _positionController.DeletePosition(id); ActionResult <Position> result = null; //Exception test //Exception ex = null; //if (id == 1) //{ // ex = await Assert.ThrowsAsync<Exception>(async () => await _positionController.DeletePosition(id)); //} result = await _positionController.DeletePosition(id); // Assert if (id == 0) { Assert.Equal("Microsoft.AspNetCore.Mvc.NotFoundResult", result.Result.ToString()); } if (id == 1) { Assert.Equal("Microsoft.AspNetCore.Mvc.BadRequestObjectResult", result.Result.ToString()); } }
/// <summary> /// Remove the position from the storage /// удалить позицию из хранилища /// </summary> public void DeletePosition(Position position) { try { _positionController.DeletePosition(position); } catch (Exception error) { SendNewLogMessage(error.ToString(), LogMessageType.Error); } }
public void CangetDeletePosition_ReturnJson() { positionService.Setup(c => c.DeletePosition(It.IsAny <int?>())) .Callback <int?>(i => ListPositions.RemoveAll(c => c.Id == i.Value)); positionController = new PositionController(positionService.Object); var result = positionController.DeletePosition(1); positionService.Verify(m => m.DeletePosition(1)); Assert.IsTrue(ListPositions.Count() == 2); }
/// <summary> /// Remove the position from the storage /// удалить позицию из хранилища /// </summary> public void DeletePosition(Position position) { try { position.State = PositionStateType.Deleted; _positionController.DeletePosition(position); if (PositionStateChangeEvent != null) { PositionStateChangeEvent(position); } } catch (Exception error) { SendNewLogMessage(error.ToString(), LogMessageType.Error); } }