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 ActionPlanDto Map(ActionPlan entity) { ActionPlanDto dto = new ActionPlanDto() { Id = entity.Id, CompanyId = entity.CompanyId, Title = entity.Title, DateOfVisit = entity.DateOfVisit, VisitBy = entity.VisitBy, SubmittedOn = entity.SubmittedOn, AreasVisited = entity.AreasVisited, AreasNotVisited = entity.AreasNotVisited, ExecutiveSummaryDocumentLibraryId = entity.ExecutiveSummaryDocumentLibraryId, NoLongerRequired = entity.NoLongerRequired }; if(_withSites) { if (entity.Site != null) { dto.Site = new SiteDtoMapper().Map(entity.Site); } } if (_withActions) { if (entity.Actions != null) { if (_actionTasks) { dto.Actions = new ActionDtoMapper().WithTasks().WithStatus().Map(entity.Actions); } else { dto.Actions = new ActionDtoMapper().Map(entity.Actions); } } } if (_withStatus) { if (entity.Actions != null) { dto.Status = entity.GetStatusFromActions(); } } return dto; }
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"); }
public void given_factory_when_get_view_model_then_result_maps_dto_to_viewmodel() { //given var companyId = 123L; var expected = 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 actionPlans = new List<ActionPlanDto> {expected}; var target = GetTarget(); _actionPlanService.Setup(x => x.Search(It.IsAny<SearchActionPlanRequest>())).Returns(actionPlans); //when var result = target.WithCompanyId(companyId).GetViewModel(); var actual = result.ActionPlans.FirstOrDefault(); //then Assert.That(actual.Id,Is.EqualTo(expected.Id)); Assert.That(actual.Title,Is.EqualTo(expected.Title)); Assert.That(actual.Site,Is.EqualTo(expected.Site.Name)); Assert.That(actual.VisitDate,Is.EqualTo(expected.DateOfVisit)); Assert.That(actual.VisitBy,Is.EqualTo(expected.VisitBy)); Assert.That(actual.SubmittedDate,Is.EqualTo(expected.SubmittedOn)); //Assert.That(actual.Status,Is.EqualTo(expected.Status)); //Assert.That(actual.EvaluationReport, Is.EqualTo(expected.EvaluationReport)); }
public void given_site_is_null_when_get_view_model_then_action_plan_site_is_null() { //given var companyId = 123L; var expected = new ActionPlanDto() { Id = 1234L, CompanyId = 1L, Title = "Action Plan1", DateOfVisit = DateTime.Now, VisitBy = "Consultant1", SubmittedOn = DateTime.Now.AddDays(-1) }; var actionPlans = new List<ActionPlanDto> { expected }; var target = GetTarget(); _actionPlanService.Setup(x => x.Search(It.IsAny<SearchActionPlanRequest>())).Returns(actionPlans); //when var result = target.WithCompanyId(companyId).GetViewModel(); var actual = result.ActionPlans.FirstOrDefault(); //then Assert.IsNull(actual.Site); }