Example #1
0
 public IActionResult GetAllTasksForProject(int projectId)
 {
     try
     {
         return(Ok(_taskOrhestrator.GetAllTasksForProject(projectId)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"Error during GET Tasks by ProjectId - {projectId}");
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Example #2
0
 public IHttpActionResult GetAllTasksForProject(int projectId)
 {
     try
     {
         return(Ok(taskLogic.GetAllTasksForProject(projectId)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Error during GET Tasks by ProjectId - {projectId}");
         return(InternalServerError(ex));
     }
 }
        public void Test_For_GetAllTasksForProject()
        {
            // Arrange
            int testProjectId = 10;
            var tasksList     = new Models.ViewModels.Task[] {
                new Models.ViewModels.Task()
                {
                    ProjectId = 10, ProjectName = "TestProject-10", TaskOwnerId = Guid.NewGuid(), Priority = 10, TaskId = 10, TaskName = "TestTask1"
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 2, ProjectName = "TestProject-2", TaskOwnerId = Guid.NewGuid(), Priority = 5, TaskId = 11, TaskName = "TestTask2"
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 10, ProjectName = "TestProject-10", TaskOwnerId = Guid.NewGuid(), Priority = 15, TaskId = 9, TaskName = "TestTask3"
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 4, ProjectName = "TestProject-4", TaskOwnerId = Guid.NewGuid(), Priority = 20, TaskId = 7, TaskName = "TestTask4"
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 5, ProjectName = "TestProject-5", TaskOwnerId = Guid.NewGuid(), Priority = 30, TaskId = 5, TaskName = "TestTask5", ParentTaskName = "TestParentTask1", ParentTaskId = 200
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 10, ProjectName = "TestProject-10", TaskOwnerId = Guid.NewGuid(), Priority = 30, TaskId = 5, TaskName = "TestTask6", ParentTaskName = "TestParentTask1", ParentTaskId = 200
                },
                new Models.ViewModels.Task()
                {
                    ProjectId = 5, ProjectName = "TestProject-5", TaskOwnerId = Guid.NewGuid(), Priority = 30, TaskId = 5, TaskName = "TestTask7", ParentTaskName = "TestParentTask2", ParentTaskId = 202
                },
            }.AsEnumerable();

            IEnumerable <Models.ViewModels.Task> expectedResult;

            expectedResult = tasksList.Where(p => p.ProjectId == testProjectId);
            mockTaskRepo.Setup(repo => repo.Search(It.IsAny <System.Linq.Expressions.Expression <Func <Models.DataModels.Task, bool> > >())).Returns(expectedResult.AsDataModel());
            // Act
            var actualResult = tasksLogicTest.GetAllTasksForProject(testProjectId);

            // Assert
            Assert.Equal(expectedResult.Count(), actualResult.Count());
        }