コード例 #1
0
        public void Given_valid_request_When_Search_Then_should_call_correct_methods()
        {

            //Given
            var target = GetTarget();

            _employeeId = Guid.NewGuid();
            _companyId = 200;

            var request = new SearchTasksRequest()
                              {
                                  CompanyId = _companyId,
                                  EmployeeIds = new List<Guid>(){_employeeId},
                                  TaskStatusId = (int) TaskStatus.Outstanding,
                                  Title = "Title to search for",
                              };

            _tasksRepository.Setup(x => x.Search(It.Is<long>(y => y == _companyId),
                                                 It.Is<IEnumerable<Guid>>(y => y.Contains(_employeeId)),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<long>(),
                                                 It.Is<int>(y => y == (int)TaskStatus.Outstanding),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<bool>(y => y == false),
                                                 It.IsAny<IEnumerable<long>>(),
                                                 It.IsAny<String>(), 0, 0, TaskOrderByColumn.None, false))
                .Returns(new List<Task>());


            //When
            target.Search(request);

            //Then
            _tasksRepository.VerifyAll();

            _tasksRepository.Verify(x => x.Search(It.Is<long>(y => y == _companyId),
                                                 It.Is<IEnumerable<Guid>>(y => y.Contains(_employeeId)),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<long>(),
                                                 It.Is<int>(y => y == (int)TaskStatus.Outstanding),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<bool>(y => y == false),
                                                 It.IsAny<IEnumerable<long>>(),
                                                 request.Title, 0, 0, TaskOrderByColumn.None, false));
        }
コード例 #2
0
        public IEnumerable<TaskDto> Search(SearchTasksRequest request)
        {
            var siteIdsToSearch = request.AllowedSiteIds;

            if (request.SiteGroupId.HasValue)
            {
                var allSiteIdsForSiteGroup = GetAllSiteIdsForSiteGroup(request);

                siteIdsToSearch = allSiteIdsForSiteGroup.Where(siteId => SiteIdIsInUsersAllowableSites(request, siteId)).ToList();
            }

            if (request.SiteId.HasValue)
            {
                if (RequestedSiteNotInUsersAllowableSites(request))
                {
                    throw new SearchTasksSpecifiedSiteIdNotInAllowableSitesForUserException();
                }

                siteIdsToSearch = new List<long> {request.SiteId.Value};
            }

            var tasks = _taskRepository.Search(
                request.CompanyId,
                request.EmployeeIds,
                request.CreatedFrom,
                request.CreatedTo,
                request.CompletedFrom,
                request.CompletedTo,
                request.TaskCategoryId,
                request.TaskStatusId,
                request.ShowDeleted,
                request.ShowCompleted,
                siteIdsToSearch,
                request.Title,
                request.Page,
                request.PageSize,
                request.OrderBy,
                request.Ascending
                );

            return new TaskDtoMapper().MapWithAssignedTo(tasks);

        }
コード例 #3
0
        public void Given_GetSummaryViewModel_Then_calls_correct_methods()
        {
            //Given
            var target = CreateTarget();

            var user = new UserDto()
            {
                CompanyId = _companyId,
                Id = Guid.NewGuid()
            };

            var passedRequest = new SearchTasksRequest();

            _taskService
                .Setup(x => x.GetOutstandingTasksSummary(It.IsAny<SearchTasksRequest>()))
                .Returns(new TaskListSummaryResponse())
                .Callback<SearchTasksRequest>(y => passedRequest = y);

            //When
            target
                .WithCompanyId(_companyId)
                .WithSiteGroupId(_siteGroupId)
                .WithSiteId(_siteId)
                .WithTaskCategoryId(_taskCategoryId)
                .WithEmployeeId(_employeeId)
                .WithAllowedSiteIds(_allowedSiteIds)
                .GetSummaryViewModel();

            //Then
            _taskService.Verify(x => x.GetOutstandingTasksSummary(It.IsAny<SearchTasksRequest>()), Times.Once());
            Assert.That(passedRequest.CompanyId, Is.EqualTo(_companyId));
            Assert.That(passedRequest.SiteGroupId, Is.EqualTo(_siteGroupId));
            Assert.That(passedRequest.SiteId, Is.EqualTo(_siteId));
            Assert.That(passedRequest.TaskCategoryId, Is.EqualTo(_taskCategoryId));
            Assert.That(passedRequest.EmployeeIds, Is.EqualTo(new List<Guid>() { _employeeId }));
            Assert.That(passedRequest.AllowedSiteIds, Is.EqualTo(_allowedSiteIds));
        }
コード例 #4
0
        public void Given_valid_request_with_site_group_id_specified_and_allowable_sitesids_null_When_Search_Then_should_call_correct_methods()
        {

            //Given
            var target = GetTarget();

            _employeeId = Guid.NewGuid();
            _companyId = 200;

            var request = new SearchTasksRequest()
            {
                CompanyId = _companyId,
                EmployeeIds = new List<Guid>() { _employeeId },
                TaskStatusId = (int)TaskStatus.Outstanding,
                SiteGroupId = 500,
                AllowedSiteIds = null
            };

            var siteGroup = new Mock<SiteGroup>();
            var descendents = new List<SiteStructureElement>()
                                  {
                                      new Site()
                                          {
                                              Id = 100
                                          },
                                      new Site()
                                          {
                                              Id = 200
                                          },
                                      new SiteGroup()
                                         {
                                              Id = 300
                                         }
                                  };
            siteGroup.Setup(x => x.GetThisAndAllDescendants()).Returns(descendents);

            _siteGroupRepository
                .Setup(x => x.GetByIdAndCompanyId(request.SiteGroupId.Value, request.CompanyId))
                .Returns(siteGroup.Object);


            _tasksRepository.Setup(x => x.Search(It.Is<long>(y => y == _companyId),
                                                 It.Is<IEnumerable<Guid>>(y => y.Contains(_employeeId)),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<long>(),
                                                 It.Is<int>(y => y == (int)TaskStatus.Outstanding),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<IEnumerable<long>>(y => y.Count() == 2 && y.Contains(100) && y.Contains(200)),
                                                 It.IsAny<String>(), 0, 0, TaskOrderByColumn.None, false))
                .Returns(new List<Task>());



            //When
            target.Search(request);

            //Then
            _tasksRepository.VerifyAll();
            _siteGroupRepository.VerifyAll();
        }
コード例 #5
0
        public void Given_valid_request_with_SiteId_but_SiteId_not_in_allowable_sites_When_Search_Then_should_throw_correct_exception()
        {

            //Given
            var target = GetTarget();

            _employeeId = Guid.NewGuid();
            _companyId = 200;

            var request = new SearchTasksRequest()
            {
                CompanyId = _companyId,
                EmployeeIds = new List<Guid>() { _employeeId },
                TaskStatusId = (int)TaskStatus.Outstanding,
                SiteId = 500,
                AllowedSiteIds = new List<long>()
            };

            _tasksRepository.Setup(x => x.Search(It.Is<long>(y => y == _companyId),
                                                 It.Is<IEnumerable<Guid>>(y => y.Contains(_employeeId)),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<long>(),
                                                 It.Is<int>(y => y == (int)TaskStatus.Outstanding),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<IEnumerable<long>>(y => y.Contains(request.SiteId.GetValueOrDefault())),
                                                 It.IsAny<String>(), 0, 0, TaskOrderByColumn.None, false))
                .Returns(new List<Task>());


            //When
            //Then
            Assert.Throws<SearchTasksSpecifiedSiteIdNotInAllowableSitesForUserException>(() => target.Search(request));
        }
コード例 #6
0
        public TaskListSummaryResponse GetOutstandingTasksSummary(SearchTasksRequest request)
        {
            var siteIdsToSearch = request.AllowedSiteIds;

            if (request.SiteGroupId.HasValue)
            {
                var allSiteIdsForSiteGroup = GetAllSiteIdsForSiteGroup(request);

                siteIdsToSearch = allSiteIdsForSiteGroup.Where(siteId => SiteIdIsInUsersAllowableSites(request, siteId)).ToList();
            }

            if (request.SiteId.HasValue)
            {
                if (RequestedSiteNotInUsersAllowableSites(request))
                {
                    throw new SearchTasksSpecifiedSiteIdNotInAllowableSitesForUserException();
                }

                siteIdsToSearch = new List<long> {request.SiteId.Value};
            }

            var tasks = _taskRepository.Search(
                request.CompanyId,
                request.EmployeeIds,
                request.CreatedFrom,
                request.CreatedTo,
                request.CompletedFrom,
                request.CompletedTo,
                request.TaskCategoryId,
                request.TaskStatusId,
                request.ShowDeleted,
                request.ShowCompleted,
                siteIdsToSearch,
                request.Title, 0, 0, TaskOrderByColumn.None, true);

            var today = DateTime.Today.Date;

            return new TaskListSummaryResponse()
                       {
                           TotalOverdueTasks = tasks.Count(t => t.TaskCompletionDueDate.Value.Date < today),
                           TotalPendingTasks = tasks.Count(t => t.TaskCompletionDueDate.Value.Date >= today)
                       };

        }
コード例 #7
0
 private static SearchTasksRequest CreateSearchOutstandingTasksRequest(Guid employeeId, long companyId)
 {
     var searchTasksRequest = new SearchTasksRequest()
                                  {
                                      CompanyId = companyId,
                                      EmployeeIds = new List<Guid>()
                                                        {
                                                            employeeId
                                                        },
                                      TaskStatusId = (int)TaskStatus.Outstanding
                                  };
     return searchTasksRequest;
 }
コード例 #8
0
 private IEnumerable<long> GetAllSiteIdsForSiteGroup(SearchTasksRequest request)
 {
     var siteGroup = _siteGroupRepository.GetByIdAndCompanyId(request.SiteGroupId.GetValueOrDefault(), request.CompanyId);
     return siteGroup.GetThisAndAllDescendants().Where(x => x is Site).Select(x => x.Id);
 }
コード例 #9
0
 private static bool RequestedSiteNotInUsersAllowableSites(SearchTasksRequest request)
 {
     return request.AllowedSiteIds != null && !request.AllowedSiteIds.Contains(request.SiteId.GetValueOrDefault());
 }
コード例 #10
0
 private static bool SiteIdIsInUsersAllowableSites(SearchTasksRequest request, long siteGroupSiteId)
 {
     return request.AllowedSiteIds == null || request.AllowedSiteIds.Contains(siteGroupSiteId);
 }
コード例 #11
0
        public int Count(SearchTasksRequest request)
        {
            var siteIdsToSearch = request.AllowedSiteIds;

            if (request.SiteGroupId.HasValue)
            {
                var allSiteIdsForSiteGroup = GetAllSiteIdsForSiteGroup(request);

                siteIdsToSearch = allSiteIdsForSiteGroup.Where(siteId => SiteIdIsInUsersAllowableSites(request, siteId)).ToList();
            }

            if (request.SiteId.HasValue)
            {
                if (RequestedSiteNotInUsersAllowableSites(request))
                {
                    throw new SearchTasksSpecifiedSiteIdNotInAllowableSitesForUserException();
                }

                siteIdsToSearch = new List<long> { request.SiteId.Value };
            }

            var result = _taskRepository.Count(
                request.CompanyId,
                request.EmployeeIds,
                request.CreatedFrom,
                request.CreatedTo,
                request.CompletedFrom,
                request.CompletedTo,
                request.TaskCategoryId,
                request.TaskStatusId,
                request.ShowDeleted,
                request.ShowCompleted,
                siteIdsToSearch,
                request.Title);

            return result;
        }
コード例 #12
0
        public void Given_valid_request_When_getOustandingTasks_Then_should_calculate_pending_and_overdue_totals()
        {
            //Given
            var target = GetTarget();
            var today = DateTime.Today.Date;

            _employeeId = Guid.NewGuid();
            _companyId = 200;

            var request = new SearchTasksRequest()
            {
                CompanyId = _companyId,
                EmployeeIds = new List<Guid>() { _employeeId },
                TaskStatusId = (int)TaskStatus.Outstanding
            };

            _tasksRepository.Setup(x => x.Search(It.Is<long>(y => y == _companyId),
                                                 It.Is<IEnumerable<Guid>>(y => y.Contains(_employeeId)),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<DateTime?>(),
                                                 It.IsAny<long>(),
                                                 It.Is<int>(y => y == (int)TaskStatus.Outstanding),
                                                 It.Is<bool>(y => y == false),
                                                 It.Is<bool>(y => y == false),
                                                 It.IsAny<IEnumerable<long>>(),
                                                 It.IsAny<String>(), 0, 0, TaskOrderByColumn.None, true))
                .Returns(new List<Task>()
                             {
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(1) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(2) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(3) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(4) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(-1) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(-2) },
                                 new RiskAssessmentReviewTask() { TaskCompletionDueDate = today.AddDays(-3) }
                             });


            //When
            var result = target.GetOutstandingTasksSummary(request);

            //Then
            Assert.That(result.TotalPendingTasks, Is.EqualTo(5));
            Assert.That(result.TotalOverdueTasks, Is.EqualTo(3));
        }
コード例 #13
0
        public TaskListSummaryViewModel GetSummaryViewModel()
        {
            var employeeIds = GetEmployeeIdsToSearchFor();

            var request = new SearchTasksRequest
                              {
                                  CompanyId = _companyId,
                                  SiteGroupId = _siteGroupId,
                                  SiteId = _siteId,
                                  TaskCategoryId = _taskCategoryId,
                                  EmployeeIds = employeeIds,
                                  AllowedSiteIds = _allowedSiteIds
                              };

            var response = _taskService.GetOutstandingTasksSummary(request);

            return new TaskListSummaryViewModel()
                       {
                           TotalOverdueTasks = response.TotalOverdueTasks,
                           TotalPendingTasks = response.TotalPendingTasks
                       };
        }
コード例 #14
0
        public TaskListViewModel GetViewModel()
        {
            using (var session = _businessSafeSessionManager.Session)
            {
                session.FlushMode = FlushMode.Never;

                var employeeIds = GetEmployeeIdsToSearchFor();
                    // If the user wants to view tasks for ALL employees in there company, then retrieve the list of employeeids to find tasks for
                var sites = GetSites();
                var siteGroups = GetSiteGroups();
                var employees = GetEmployees();

                var request = new SearchTasksRequest()
                                  {
                                      CompanyId = _companyId,
                                      EmployeeIds = employeeIds,
                                      CreatedFrom = _createdFrom,
                                      CreatedTo = _createdTo,
                                      CompletedFrom = _completedFrom,
                                      CompletedTo = _completedTo,
                                      TaskCategoryId = _taskCategoryId,
                                      TaskStatusId = _taskStatusId,
                                      ShowDeleted = _showDeleted,
                                      ShowCompleted = _showCompleted,
                                      SiteId = _siteId,
                                      SiteGroupId = _siteGroupId,
                                      AllowedSiteIds = _allowedSiteIds,
                                      Title = _title,
                                      Page = _page != default(int) ? _page : 1,
                                      PageSize = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                                      OrderBy = GetOrderBy(),
                                      Ascending = Ascending()
                                  };

                var total = _taskService.Count(request);
                var employeeTasksDto = _taskService.Search(request);

                var viewModel = new TaskListViewModel
                                    {
                                        CompanyId = _companyId,
                                        EmployeeId = (_userEmployeeId.HasValue ? _userEmployeeId : _employeeId),
                                        Employees = employees,
                                        CreatedFrom = _createdFrom,
                                        CreatedTo = _createdTo,
                                        CompletedFrom = _completedFrom,
                                        CompletedTo = _completedTo,
                                        TaskCategories = GetTaskCategories(),
                                        Tasks = TaskViewModel.CreateFrom(employeeTasksDto),
                                        IsBulkReassign = _isBulkReassign,
                                        Sites = sites,
                                        SiteGroups = siteGroups,
                                        SiteId = _siteId,
                                        SiteGroupId = _siteGroupId,
                                        IsShowDeleted = _showDeleted,
                                        IsShowCompleted = _showCompleted,
                                        PageSize = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                                        Total = total
                                    };

                return viewModel;
            }
        }