public ActionDto Map(BusinessSafe.Domain.Entities.Action entity)
        {
            var dto = new ActionDto
            {
                Id = entity.Id,
                Title = entity.Title,
                AreaOfNonCompliance = entity.AreaOfNonCompliance,
                ActionRequired = entity.ActionRequired,
                TargetTimescale = entity.TargetTimescale,
                AssignedTo = (entity.AssignedTo != null) ? (Guid?)entity.AssignedTo.Id: null,
                DueDate = entity.DueDate,       
                QuestionStatus = entity.QuestionStatus,
                Reference = entity.Reference,
                Category = entity.Category,
                GuidanceNote = entity.GuidanceNotes,
                ActionPlan = entity.ActionPlan
            };

            if (_withStatus)
            {
                dto.Status = entity.GetStatusFromTasks();
            }

            if (_withTasks)
            {
                if (entity.ActionTasks != null)
                {
                    dto.ActionTasks = entity.ActionTasks.Select(x => new ActionTaskDtoMapper().MapWithAssignedTo(x));
                }
            }

            return dto;
        }
        public void given_factory_when_get_view_model_then_result_maps_ActionPlanDto_to_viewmodel()
        {
            //given
            var actionPlan = new ActionPlanDto()
                               {
                                   Id = 1234L,
                                   CompanyId = 1L,
                                   Title = "Action Plan1",
                                   Site = new SiteDto
                                              {
                                                  SiteId = 1L,
                                                  Name = "Site1"
                                              },
                                   DateOfVisit = DateTime.Now,
                                   VisitBy = "Consultant1",
                                   SubmittedOn = DateTime.Now.AddDays(-1)                                   
                               };
            var action = new ActionDto()
                             {
                                 Id = 123123,
                                 Title = "test title"
                                 ,
                                 AreaOfNonCompliance = "area not compliaint",
                                 ActionRequired = "action required test",
                                 Category = ActionCategory.Action,
                                 QuestionStatus = ActionQuestionStatus.Red

                             };
            
            var task = new ActionTaskDto
                           {
                               Id = 1L,
                               TaskAssignedTo = new EmployeeDto
                                                    {
                                                        Id = Guid.NewGuid()
                                                    },
                               TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                               
                           };

            action.ActionTasks = new List<ActionTaskDto>() {(task)};
            actionPlan.Actions = new List<ActionDto>() { action };

            var target = GetTarget();
            _actionPlanService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(actionPlan);

            //when
            var result = target.WithActionPlanId(actionPlan.Id).GetViewModel();

            //then
            Assert.That(result.SiteName, Is.EqualTo(actionPlan.Site.Name), "Site name not mapped");
            Assert.That(result.VisitDate, Is.EqualTo(actionPlan.DateOfVisit), "Visit Date name not mapped");
            Assert.That(result.Actions.FirstOrDefault().HasTask, Is.True);
            Assert.That(result.Actions.First().AssignedTo == task.TaskAssignedTo.Id);
            Assert.That(result.Actions.First().DueDate == DateTime.Parse(task.TaskCompletionDueDate));

        }
        public void given_action_id_and_company_id_when_get_view_model_then_existing_documents_are_returned()
        {
            //given
            var companyId = 123L;
            var actionId = 1L;

            var target = GetTarget(); 
            
            var assignedTo = new EmployeeDto
                                 {
                                     Id = Guid.NewGuid(),
                                     FullName = "employee'"
                                 };

         
            var task = new ActionTaskDto
                           {
                               Id = 1L,
                               Title = "Title",
                               Description = "Description",
                               TaskAssignedTo = assignedTo                               
                           };

            var action = new ActionDto
                               {
                                   Id = actionId,
                                   ActionTasks = new List<ActionTaskDto>
                                                     {
                                                         task
                                                     },                                                     
                               };
            _actionService
                .Setup(x => x.GetByIdAndCompanyId( actionId, companyId ))
                .Returns(action);

            ExistingDocumentsViewModel existingDocumentsViewModel = new ExistingDocumentsViewModel();            

            existingDocumentsViewModel.PreviouslyAddedDocuments = new List<PreviouslyAddedDocumentGridRowViewModel>();

            PreviouslyAddedDocumentGridRowViewModel padGridRowViewModel = new PreviouslyAddedDocumentGridRowViewModel();            
            padGridRowViewModel.Id = 1234L;
            padGridRowViewModel.Filename = "somefilename.doc";
            padGridRowViewModel.Description = "";
            padGridRowViewModel.DocumentLibraryId = 765L;
            padGridRowViewModel.DocumentOriginType = DocumentOriginType.TaskUpdated;
            padGridRowViewModel.DocumentTypeName = "somedocumenttype";
            

            existingDocumentsViewModel.PreviouslyAddedDocuments.Add(padGridRowViewModel);         

            _existingDocumentsViewModelFactory
                .Setup(x => x.GetViewModel(It.IsAny<IEnumerable<TaskDocumentDto>>()))
                .Returns(existingDocumentsViewModel);

            var result = target
              .WithCompanyId(companyId)
              .WithActionId(actionId)
              .GetViewModel();

            // then
            Assert.IsNotNull(result.ExistingDocuments);
            Assert.IsNotNull(result.ExistingDocuments.PreviouslyAddedDocuments);
            Assert.AreEqual( 1, result.ExistingDocuments.PreviouslyAddedDocuments.Count);
            Assert.AreEqual(padGridRowViewModel.Id, result.ExistingDocuments.PreviouslyAddedDocuments[0].Id);
            //Assert.AreEqual( DocumentTypeEnum.Action, result.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentTypeName);
            Assert.AreEqual(DocumentOriginType.TaskUpdated, result.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentOriginType);
        }
        public void Given_SendTaskNofication_is_false_then_DoNotSendTaskAssignedNotification_equals_true()
        {
            //given
            var assignedTo = new EmployeeDto
            {
                Id = Guid.NewGuid(),
                FullName = "employee'"
            };

            var task = new ActionTaskDto
            {
                Id = 1L,
                Title = "Title",
                Description = "Description",
                TaskAssignedTo = assignedTo,
                SendTaskNotification = false
            };
            var action = new ActionDto
            {
                Id = 234234,
                ActionTasks = new List<ActionTaskDto>
                {
                    task
                }
            };

            var target = GetTarget();

            _actionService.
                Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).
                Returns(action);


            //when
            var result = target
                .WithCompanyId(123)
                .WithActionId(1123)
                .GetViewModel();

            //then
            Assert.That(result.DoNotSendTaskAssignedNotification, Is.EqualTo(true));
        }
        public void given_company_id_when_get_view_model_then_get_viewmodel_maps_corect_result()
        {
            //given
            var companyId = 123L;
            var actionPlanId = 1231L;
            var actionId = 1L;

            var assignedTo = new EmployeeDto
                                 {
                                     Id = Guid.NewGuid(),
                                     FullName = "employee'"
                                 };

            var task = new ActionTaskDto
                           {
                               Id = 1L,
                               Title = "Title",
                               Description = "Description",
                               TaskAssignedTo = assignedTo
                           };
            var action = new ActionDto
                               {
                                   Id = actionId,
                                   ActionTasks = new List<ActionTaskDto>
                                                     {
                                                         task
                                                     },
                                                     GuidanceNote = "1.1"

                               };
            
            var target = GetTarget();

            _actionService.
                Setup(x => x.GetByIdAndCompanyId(It.Is<long>(a => a == actionId), It.Is<long>(c => c == companyId))).
                Returns(action);


            //when
            var result = target
                .WithCompanyId(companyId)
                .WithActionPlanId(actionPlanId)
                .WithActionId(actionId)
                .GetViewModel();

            //then
            Assert.That(result.ActionPlanId, Is.EqualTo(actionPlanId));
            Assert.That(result.ActionId, Is.EqualTo(action.Id));
            Assert.That(result.CompanyId, Is.EqualTo(companyId));
            Assert.That(result.Title, Is.EqualTo(task.Title));
            Assert.That(result.Description, Is.EqualTo(task.Description));
            Assert.That(result.GuidanceNotes, Is.EqualTo(action.GuidanceNote));
            Assert.That(result.DueDate, Is.EqualTo(task.TaskCompletionDueDate));
            Assert.That(result.ActionTaskAssignedTo, Is.EqualTo(task.TaskAssignedTo.FullName));
            Assert.That(result.ActionTaskAssignedToId, Is.EqualTo(task.TaskAssignedTo.Id));

        }
        public void given_site_is_null_when_get_view_model_then_action_site_is_null()
        {
            //given
            var actionPlan = new ActionPlanDto() {};

            var IRNaction = new ActionDto()
            {
                Id = 123123,
                Title = "IRN test title",
                AreaOfNonCompliance = "IRN area not compliant",
                ActionRequired = "IRN action required test",
                GuidanceNote = "IRN 1-3",
                TargetTimescale = "IRN do this now",
                AssignedTo = Guid.NewGuid(),
                DueDate = DateTime.Now.AddDays(3),
                Status = DerivedTaskStatusForDisplay.None,
                Reference = "IRN The Reference",
                Category = ActionCategory.ImmediateRiskNotification
            };

            actionPlan.Actions = new List<ActionDto>() { IRNaction };

            var target = GetTarget();
            _actionPlanService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(actionPlan);

            //when
            var result = target.WithActionPlanId(actionPlan.Id).GetViewModel();

            //then
            Assert.IsNull(result.SiteId);
            Assert.IsNull(result.SiteName);
            

        }
        public void given_factory_when_get_view_model_then_result_maps_IRN_And_NonIRN_actions_to_correct_viewmodel_actions()
        {
            //given
            var actionPlan = new ActionPlanDto()
            {
                Site = new SiteDto
                {
                    SiteId = 1L,
                    Name = "Site1"
                }
            };

            var action = new ActionDto()
            {
                Id = 123123,
                Title = "test title",
                AreaOfNonCompliance = "area not compliant",
                ActionRequired = "action required test",
                GuidanceNote = "1-3",
                TargetTimescale = "do this now",
                AssignedTo = Guid.NewGuid(),
                DueDate = DateTime.Now.AddDays(10),
                Status = DerivedTaskStatusForDisplay.None,
                Reference = "The Reference",
                Category = ActionCategory.Action,
                QuestionStatus = ActionQuestionStatus.Red

            };

            var IRNaction = new ActionDto()
            {
                Id = 123123,
                Title = "IRN test title",
                AreaOfNonCompliance = "IRN area not compliant",
                ActionRequired = "IRN action required test",
                GuidanceNote = "IRN 1-3",
                TargetTimescale = "IRN do this now",
                AssignedTo = Guid.NewGuid(),
                DueDate = DateTime.Now.AddDays(3),
                Status = DerivedTaskStatusForDisplay.None,
                Reference = "IRN The Reference",
                Category = ActionCategory.ImmediateRiskNotification
            };

            actionPlan.Actions = new List<ActionDto>(){ action, IRNaction };

            var target = GetTarget();
            _actionPlanService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(actionPlan);

            //when
            var result = target.WithActionPlanId(actionPlan.Id).GetViewModel();

            //then      
            Assert.That(result.Actions.First().Id, Is.EqualTo(action.Id), "No entries in Actions");
            Assert.That(result.Actions.First().AreaOfNonCompliance, Is.EqualTo(action.AreaOfNonCompliance), "AreaOfNonCompliance not mapped");
            Assert.That(result.Actions.First().ActionRequired, Is.EqualTo(action.ActionRequired), "ActionRequired not mapped");
            Assert.That(result.Actions.First().GuidanceNote, Is.EqualTo(action.GuidanceNote), "GuidanceNote not mapped");
            Assert.That(result.Actions.First().TargetTimescale, Is.EqualTo(action.TargetTimescale), "TargetTimescale not mapped");
            Assert.That(result.Actions.First().AssignedTo, Is.EqualTo(action.AssignedTo), "AssignedTo not mapped");
            Assert.That(result.Actions.First().DueDate, Is.EqualTo(action.DueDate), "DueDate not mapped");

            Assert.That(result.ImmediateRiskNotification.Count(), Is.GreaterThan(0), "No entries in Immediate Risk Notifications");
            Assert.That(result.ImmediateRiskNotification.First().Id, Is.EqualTo(IRNaction.Id));
            Assert.That(result.ImmediateRiskNotification.First().Title, Is.EqualTo(IRNaction.Title), "Action title not mapped");
            Assert.That(result.ImmediateRiskNotification.First().Reference, Is.EqualTo(IRNaction.Reference), "Reference not mapped");
            Assert.That(result.ImmediateRiskNotification.First().AssignedTo, Is.EqualTo(IRNaction.AssignedTo), "AssignedTo not mapped");
            Assert.That(result.ImmediateRiskNotification.First().DueDate, Is.EqualTo(IRNaction.DueDate), "DueDate not mapped");
            Assert.That(result.ImmediateRiskNotification.First().RecommendedImmediateAction, Is.EqualTo(IRNaction.ActionRequired), "RecommendedImmediateAction not mapped");
            Assert.That(result.ImmediateRiskNotification.First().SignificantHazardIdentified, Is.EqualTo(IRNaction.AreaOfNonCompliance), "SignificantHazardIdentified not mapped");
        }
        public void given_factory_when_get_view_model_then_result_maps_dto_actions_to_viewmodel_actions()
        {
            //given
            var actionPlan = new ActionPlanDto()
                                 {
                                     Site = new SiteDto
                                                {
                                                    SiteId = 1L,
                                                    Name = "Site1"
                                                }
                                 };
            var action = new ActionDto()
                             {
                                 Id = 123123,
                                 Title = "test title"
                                 ,
                                 AreaOfNonCompliance = "area not compliant",
                                 ActionRequired = "action required test",
                                 GuidanceNote = "1-3",
                                 TargetTimescale = "do this now",
                                 AssignedTo = Guid.NewGuid(),
                                 DueDate = DateTime.Now.AddDays(10),
                                 Status = DerivedTaskStatusForDisplay.None,
                                 Category = ActionCategory.Action,
                                 QuestionStatus = ActionQuestionStatus.Red
                                 
                             };
            actionPlan.Actions = new List<ActionDto>() {action};

            var target = GetTarget();
            _actionPlanService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(actionPlan);

            //when
            var result = target.WithActionPlanId(actionPlan.Id).GetViewModel();

            //then
            Assert.That(result.Actions.First().Id, Is.EqualTo(action.Id));
            Assert.That(result.Actions.First().AreaOfNonCompliance, Is.EqualTo(action.AreaOfNonCompliance), "AreaOfNonCompliance not mapped");
            Assert.That(result.Actions.First().ActionRequired, Is.EqualTo(action.ActionRequired), "ActionRequired not mapped");
            Assert.That(result.Actions.First().GuidanceNote, Is.EqualTo(action.GuidanceNote), "GuidanceNote not mapped");
            Assert.That(result.Actions.First().TargetTimescale, Is.EqualTo(action.TargetTimescale), "TargetTimescale not mapped");
            Assert.That(result.Actions.First().AssignedTo, Is.EqualTo(action.AssignedTo), "AssignedTo not mapped");
            Assert.That(result.Actions.First().DueDate, Is.EqualTo(action.DueDate), "DueDate not mapped");

        }