public static CreateUpdateResponsibilityTaskViewModel CreateFrom(long companyId,
     ResponsibilityDto responsibility,
     TaskDto task)
 {
     var model = new CreateUpdateResponsibilityTaskViewModel();
     model.CompanyId = companyId;
     model.ResponsibilityId = responsibility.Id;
     model.ResponsibilitySiteId = responsibility.Site != null ? responsibility.Site.Id : 0;
     model.ResponsibilitySite = responsibility.Site != null ? responsibility.Site.Name : string.Empty;
     model.TaskId = task != null ? task.Id : default(long);
     model.TaskStatusId = task != null ? task.TaskStatusId : default(int);
     model.Title = task != null ? task.Title : string.Empty;
     model.Description = task != null ? task.Description : string.Empty;
     model.IsRecurring = task != null && task.IsReoccurring;
     model.TaskReoccurringTypeId = task != null ? (int) task.TaskReoccurringType : default(int);
     model.TaskReoccurringType = task != null ? task.TaskReoccurringType.ToString() : string.Empty;
     model.CompletionDueDate = task != null ? task.TaskCompletionDueDate : string.Empty;
     model.ReoccurringStartDate = task != null ? task.TaskCompletionDueDate : string.Empty;
     model.ReoccurringEndDate = task != null ? task.TaskReoccurringEndDate : null;
     model.DoNotSendTaskAssignedNotification = task != null && !task.SendTaskCompletedNotification;
     model.DoNotSendTaskCompletedNotification = task != null && !task.SendTaskCompletedNotification;
     model.DoNotSendTaskOverdueNotification = task != null && !task.SendTaskOverdueNotification;
     model.DoNotSendTaskDueTomorrowNotification = task != null && !task.SendTaskDueTomorrowNotification;
     model.ResponsibilityTaskSiteId = task != null && task.Site != null ? task.Site.Id : default(long);
     model.ResponsibilityTaskSite = task != null && task.Site != null ? task.Site.Name : string.Empty;
     model.AssignedTo = task != null && task.TaskAssignedTo != null ? task.TaskAssignedTo.FullName : string.Empty;
     model.AssignedToId = task != null && task.TaskAssignedTo != null ? task.TaskAssignedTo.Id : new Guid();
     return model;
 }
コード例 #2
0
        public ResponsibilityDtoMapper(Responsibility responsibility)
        {
            _responsibility = responsibility;
            _responsibilityDto = null;

            if(responsibility != null)
            {
                _responsibilityDto = new ResponsibilityDto()
                {
                    Id = _responsibility.Id,
                    CompanyId = _responsibility.CompanyId,
                    Description = _responsibility.Description,
                    Site = _responsibility.Site != null ? new SiteStructureElementDtoMapper().Map(_responsibility.Site) : null,
                    InitialTaskReoccurringType = _responsibility.InitialTaskReoccurringType,
                    Owner = _responsibility.Owner != null ? new EmployeeDtoMapper().Map(_responsibility.Owner) : null,
                    Title = _responsibility.Title,
                    ResponsibilityCategory = new ResponsibilityCategoryDtoMapper().Map(_responsibility.ResponsibilityCategory),
                    ResponsibilityReason = _responsibility.ResponsibilityReason != null ? new ResponsibilityReasonDtoMapper().Map(_responsibility.ResponsibilityReason) : null,
                    CreatedOn = _responsibility.CreatedOn.Value,
                    Deleted = _responsibility.Deleted,
                    NextDueDate = _responsibility.NextDueDate,
                    HasMultipleFrequencies = _responsibility.HasMultipleFrequencies,
                    StatusDerivedFromTasks = _responsibility.GetStatusDerivedFromTasks()
                };
            }

        }
        public void Given_uncreated_statutory_task_with_no_site_set_when_GetViewModel_then_site_is_empty_list()
        {
            //given
            const long taskTemplateId = 12124124;
            const TaskReoccurringType expectedRecurringType = TaskReoccurringType.ThreeMonthly;

            var tasks = new List<StatutoryResponsibilityTaskTemplateDto>
                            {
                                new StatutoryResponsibilityTaskTemplateDto() {Id = taskTemplateId, TaskReoccurringType = expectedRecurringType}
                            };
            var respDtoA = new ResponsibilityDto
                               {
                                   Site = null,
                                   StatutoryResponsibilityTaskTemplates = tasks,
                                   InitialTaskReoccurringType = TaskReoccurringType.TwentyFourMonthly
                               };


            _responsibilitiesService
                .Setup(x => x.GetStatutoryResponsibilities(It.IsAny<long>()))
                .Returns(new List<ResponsibilityDto>() {respDtoA});

            var target = GetTarget();

            //when
            var result = target.WithCompanyId(123123).GetViewModel();

            //then
            Assert.That(result.SelectedSites.Count, Is.EqualTo(0));
        }
        public void Given_search_for_current_user_When_GetViewModel_is_called_Then_returns_model()
        {
            //Given
            var taskId = 124124124L;
            var target = CreateTarget();

            var site = new SiteDto() {Id = 1L, Name = "the main site"};
            var taskDocument = new TaskDocumentDto()
                                   {Id = 12312, DocumentLibraryId = 13123, Description = "doc description", Filename = "the filename"};
            var responsibility = new ResponsibilityDto{Id = 1L, CompanyId = _companyId, Title = "Responsibilty Title",Description = "Responsibilty Description"};
            var responsibilityTask = new ResponsibilityTaskDto
                                       {
                                           Id = taskId,
                                           Title = "task title",
                                           Description = "task description",
                                           TaskAssignedTo = new EmployeeDto {FullName = "Test employee name", Id=Guid.NewGuid()},
                                           CreatedDate = DateTime.Now.ToShortDateString(),
                                           TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                                           TaskStatusString = string.Empty,
                                           Site = site,
                                           Responsibility = responsibility,
                                           TaskReoccurringType = TaskReoccurringType.Monthly,
                                           TaskReoccurringEndDate = DateTime.Now.AddDays(234),
                                           IsReoccurring = true,
                                           SendTaskCompletedNotification = true,
                                           SendTaskNotification = true,
                                           SendTaskOverdueNotification = true,
                                           Documents = new List<TaskDocumentDto>(){taskDocument}
                                       };

            _responsibilityTaskService
                .Setup(x=> x.GetByIdAndCompanyId(taskId, It.IsAny<long>()))
                .Returns(() => responsibilityTask );

            //When
            var result = target
                .WithCompanyId(_companyId)
                .WithResponsibilityTaskId(taskId)
                .GetViewModel();

            //Then
            Assert.That(result.CompanyId, Is.EqualTo(responsibility.CompanyId));
            Assert.That(result.ResponsibilityTaskId, Is.EqualTo(responsibilityTask.Id));
            Assert.That(result.ResponsibilitySummary.Id, Is.EqualTo(responsibility.Id));
            Assert.That(result.ResponsibilitySummary.Title, Is.EqualTo(responsibility.Title));
            Assert.That(result.ResponsibilitySummary.Description, Is.EqualTo(responsibility.Description));

            Assert.That(result.ResponsibilityTask.CompanyId, Is.EqualTo(responsibility.CompanyId));
            Assert.That(result.ResponsibilityTask.ResponsibilityTaskId, Is.EqualTo(responsibilityTask.Id));
            Assert.That(result.ResponsibilityTask.Title, Is.EqualTo(responsibilityTask.Title));
            Assert.That(result.ResponsibilityTask.Description, Is.EqualTo(responsibilityTask.Description));
            Assert.That(result.ResponsibilityTask.IsRecurring, Is.EqualTo(responsibilityTask.IsReoccurring));
            Assert.That(result.ResponsibilityTask.TaskReoccurringType, Is.EqualTo(responsibilityTask.TaskReoccurringType));
            Assert.That(result.ResponsibilityTask.TaskReoccurringTypeId, Is.EqualTo((int)responsibilityTask.TaskReoccurringType));
            Assert.That(result.ResponsibilityTask.ReoccurringStartDate, Is.EqualTo(responsibilityTask.TaskCompletionDueDate));
            Assert.That(result.ResponsibilityTask.ReoccurringEndDate, Is.EqualTo(responsibilityTask.TaskReoccurringEndDate));
            Assert.That(result.ResponsibilityTask.CompletionDueDate, Is.EqualTo(responsibilityTask.TaskCompletionDueDate));
            Assert.That(result.ResponsibilityTask.ResponsibilityTaskSite, Is.EqualTo(responsibilityTask.Site.Name));
            Assert.That(result.ResponsibilityTask.ResponsibilityTaskSiteId, Is.EqualTo(responsibilityTask.Site.Id));
            Assert.That(result.ResponsibilityTask.AssignedTo, Is.EqualTo(responsibilityTask.TaskAssignedTo.FullName));
            Assert.That(result.ResponsibilityTask.AssignedToId, Is.EqualTo(responsibilityTask.TaskAssignedTo.Id));
            Assert.That(result.ResponsibilityTask.DoNotSendTaskAssignedNotification, Is.EqualTo(!responsibilityTask.SendTaskNotification));
            Assert.That(result.ResponsibilityTask.DoNotSendTaskCompletedNotification, Is.EqualTo(!responsibilityTask.SendTaskCompletedNotification));
            Assert.That(result.ResponsibilityTask.DoNotSendTaskOverdueNotification, Is.EqualTo(!responsibilityTask.SendTaskOverdueNotification));
            Assert.That(result.ResponsibilityTask.TaskStatusId, Is.EqualTo(responsibilityTask.TaskStatusId));
            Assert.That(result.ResponsibilityTask.ExistingDocuments.CanDeleteDocuments, Is.EqualTo(false));
            Assert.That(result.ResponsibilityTask.ExistingDocuments.DocumentTypeId, Is.EqualTo((int)DocumentTypeEnum.Responsibility));

            Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Id, Is.EqualTo(taskDocument.Id));
            Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentLibraryId, Is.EqualTo(taskDocument.DocumentLibraryId));
            Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Filename, Is.EqualTo(taskDocument.Filename));
            Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Description, Is.EqualTo(taskDocument.Description));
            Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Id, Is.EqualTo(responsibility.Id));
            Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Title, Is.EqualTo(responsibility.Title));
            Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Description, Is.EqualTo(responsibility.Description));
        }
コード例 #5
0
        public void Given_search_for_current_user_When_GetViewModel_is_called_Then_returns_model()
        {
            //Given
            var target = CreateTarget();

            var responsibility = new ResponsibilityDto
                                     {
                                         Id = 1L,
                                         ResponsibilityTasks = new List<ResponsibilityTaskDto>
                                                                   {
                                                                       new ResponsibilityTaskDto
                                                                           {
                                                                               Id = 1L,
                                                                               Description = "my description",
                                                                               TaskAssignedTo = new EmployeeDto{FullName = "Test"},
                                                                               CreatedDate = DateTime.Now.ToShortDateString(),
                                                                               TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                                                                               TaskStatusString = string.Empty,
                                                                               Site = new SiteDto{Id = 1L}
                                                                           }
                                                                   }
                                     };

            var reasons = new List<ResponsibilityReasonDto>
                                 {
                                     new ResponsibilityReasonDto {Id = default(long)}
                                 };

            var categories = new List<ResponsibilityCategoryDto>
                                 {
                                     new ResponsibilityCategoryDto {Id = default(long)}
                                 };

            var employess = new List<EmployeeDto>
                                {
                                    new EmployeeDto{Id = new Guid()}
                                };

            var sites = new List<SiteDto>
                            {
                                new SiteDto{Id = 1}
                            };

            _responsibilitiesService
                .Setup(x => x.GetResponsibility(It.IsAny<long>(), _companyId))
                .Returns(() => responsibility);

            _responsibilitiesService
                .Setup(x => x.GetResponsibilityReasons())
                .Returns(() => reasons);
            
            _responsibilitiesService
                .Setup(x => x.GetResponsibilityCategories())
                .Returns(() => categories);

            _employeeService
                .Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>()))
                .Returns(() => employess);

            _employeeService
               .Setup(x => x.GetEmployeeNames(It.IsAny<long>()))
               .Returns(() => employess.Select(x => new EmployeeName(){Id = x.Id}).ToList());

            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Returns(() => sites);

            //When
            var result = target.WithCompanyId(_companyId)
                .WithResponsibilityId(_responsibilityId)
                .GetViewModel();

            //Then
            Assert.That(result.ResponsibilityId, Is.EqualTo(responsibility.Id));
            Assert.That(result.Reasons.Count(),Is.EqualTo(reasons.Count+1)); //the extra item is the default option "--select option--"
            Assert.That(result.Categories.Count(), Is.EqualTo(categories.Count + 1)); //the extra item is the default option "--select option--"
            Assert.That(result.Employees.Count(), Is.EqualTo(employess.Count + 1)); //the extra item is the default option "--select option--"
            Assert.That(result.Sites.Count(), Is.EqualTo(sites.Count + 1)); //the extra item is the default option "--select option--"
            
        }
コード例 #6
0
        public void Given_search_for_current_user_with_allowed_site_ids_When_GetViewModel_is_called_Then_returns_model()
        {
            //Given
            var target = CreateTarget();

            var responsibility = new ResponsibilityDto
            {
                Id = 1L,
                ResponsibilityTasks = new List<ResponsibilityTaskDto>
                                                                   {
                                                                       new ResponsibilityTaskDto
                                                                           {
                                                                               Id = 1L,
                                                                               Description = "my description",
                                                                               TaskAssignedTo = new EmployeeDto{FullName = "Test"},
                                                                               CreatedDate = DateTime.Now.ToShortDateString(),
                                                                               TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                                                                               TaskStatusString = string.Empty,
                                                                               Site = new SiteDto{Id = 1L}
                                                                           }
                                                                   }
            };

            var reasons = new List<ResponsibilityReasonDto>
                                 {
                                     new ResponsibilityReasonDto {Id = default(long)}
                                 };

            var categories = new List<ResponsibilityCategoryDto>
                                 {
                                     new ResponsibilityCategoryDto {Id = default(long)}
                                 };

            var employess = new List<EmployeeDto>
                                {
                                    new EmployeeDto{Id = new Guid()}
                                };
            var site1 = new SiteDto() { Id = 1L };
            var site2 = new SiteDto() { Id = 2L };
            var site3 = new SiteDto() { Id = 3L };

            var allowedSites = new List<long>() { 1L, 2L };

            var sites = new List<SiteDto>
                            {
                                site1, site2, site3
                            };

            _responsibilitiesService
                .Setup(x => x.GetResponsibility(It.IsAny<long>(), _companyId))
                .Returns(() => responsibility);

            _responsibilitiesService
                .Setup(x => x.GetResponsibilityReasons())
                .Returns(() => reasons);

            _responsibilitiesService
                .Setup(x => x.GetResponsibilityCategories())
                .Returns(() => categories);

            _employeeService
                .Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>()))
                .Returns(() => employess);

            _employeeService
               .Setup(x => x.GetEmployeeNames(It.IsAny<long>()))
               .Returns(() => employess.Select(x => new EmployeeName() { Id = x.Id }).ToList());

            var searchSitesRequest = new SearchSitesRequest();
            _siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>())).Returns(sites).Callback<SearchSitesRequest>(y => searchSitesRequest = y);

            //When
            var result = target.WithCompanyId(_companyId)
                .WithResponsibilityId(_responsibilityId)
                .WithAllowedSiteIds(allowedSites)
                .GetViewModel();

            //Then
            Assert.That(searchSitesRequest.AllowedSiteIds.Count, Is.EqualTo(allowedSites.Count));

        }