public IActionResult Get(int id) { try { var result = taskLogic.GetTask(id); if (result == null) { _logger.LogWarning($"No data available for GET Task by ID - {id}."); return(NotFound()); } return(Ok(result)); } catch (Exception ex) { _logger.LogError(ex, $"Error during GET Task by Id - {id}."); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public void Test_For_Get_Task_By_Id() { // Arrange var testTaskId = 5; var testTaskVM = new Models.ViewModels.Task() { TaskId = testTaskId, TaskName = "TestTask1", Priority = 20, ProjectName = "TestProject100", OwnerFullName = "First Last", StartDate = DateTime.Today }; mockTaskRepo.Setup(repo => repo.GetById(testTaskId)).Returns(testTaskVM.AsDataModel()); // Act var actualTask = tasksLogicTest.GetTask(testTaskId); // Assert Assert.NotNull(actualTask); Assert.Equal(testTaskVM.TaskName, actualTask.TaskName); }