public IActionResult GetAllTasksForUser(string UserId)
 {
     try
     {
         return(Ok(taskOrchestrator.GetAllTasksForUser(UserId)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Error during GET Tasks by User Id - {UserId}");
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Esempio n. 2
0
 public IHttpActionResult GetAllTasksForUser(string UserId)
 {
     try
     {
         return(Ok(taskLogic.GetAllTasksForUser(UserId)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Error during GET Tasks by User Id - {UserId}");
         return(InternalServerError(ex));
     }
 }
        public void Test_For_GetAllTasksForUser()
        {
            // Arrange
            Guid testUserGuid = Guid.NewGuid();
            var  tasksList    = new Models.ViewModels.Task[] {
                new Models.ViewModels.Task()
                {
                    ProjectId = 10, ProjectName = "TestProject-10", TaskOwnerId = testUserGuid, 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 = testUserGuid, 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 = testUserGuid, 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.TaskOwnerId == testUserGuid);
            mockTaskRepo.Setup(repo => repo.Search(It.IsAny <System.Linq.Expressions.Expression <Func <Models.DataModels.Task, bool> > >())).Returns(expectedResult.AsDataModel());
            // Act
            var actualResult = tasksLogicTest.GetAllTasksForUser("TestUser1");

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