public static ImmediateRiskNotificationViewModel Map(ImmediateRiskNotification immediateRiskNotification)
        {
            var immediateRiskNotificationViewModel = new ImmediateRiskNotificationViewModel
                                                         {
                                                             Id = immediateRiskNotification.Id,
                                                             Reference = immediateRiskNotification.Reference,
                                                             Title = immediateRiskNotification.Title,
                                                             SignificantHazard =
                                                                 immediateRiskNotification.SignificantHazardIdentified,
                                                             RecommendedImmediate =
                                                                 immediateRiskNotification.RecommendedImmediateAction,
                                                         };

            return immediateRiskNotificationViewModel;
        }
 private static ImmediateRiskNotificationViewModel CreateImmediateRiskNotificationViewModel()
 {
     ImmediateRiskNotificationViewModel model = new ImmediateRiskNotificationViewModel()
                                                    {
                                                        Id = Guid.NewGuid(),
                                                        Reference = "Ref 123",
                                                        Title = "IRN building is on fire",
                                                        SignificantHazard = "IRN being on fire hazard",
                                                        RecommendedImmediate = "Put out fire"
                                                    };
     return model;
 }
Пример #3
0
        public void Given_imediate_risk_notifications_exist_in_existing_checklist_When_PostChecklist_is_called_Then_IRNs_are_created_and_deleted_and_remain_accordingly()
        {
            var checklist = new Checklist();

            var immediateRiskNotification1 = ImmediateRiskNotification.Create(
                Guid.NewGuid(),
                "Reference 1",
                "Title 1",
                "Significant Hazard Identified 1",
                "Recommended Immediate Action 1",
                checklist,
                new UserForAuditing());

            var immediateRiskNotification2 = ImmediateRiskNotification.Create(
                Guid.NewGuid(),
                "Reference 2",
                "Title 2",
                "Significant Hazard Identified 2",
                "Recommended Immediate Action 2",
                checklist,
                new UserForAuditing());

            checklist.ImmediateRiskNotifications.Add(immediateRiskNotification1);
            checklist.ImmediateRiskNotifications.Add(immediateRiskNotification2);

            var checklistViewModel = new ChecklistViewModel();
            checklistViewModel.ClientId = 2323;
            checklistViewModel.SiteId = (int)_peninsulaSiteId;

            var immediateRiskNotificationViewModel1 = new ImmediateRiskNotificationViewModel();
            immediateRiskNotificationViewModel1.Id = immediateRiskNotification1.Id;
            immediateRiskNotificationViewModel1.Reference = immediateRiskNotification1.Reference;
            immediateRiskNotificationViewModel1.Title = immediateRiskNotification1.Title;
            immediateRiskNotificationViewModel1.SignificantHazard = immediateRiskNotification1.SignificantHazardIdentified;
            immediateRiskNotificationViewModel1.RecommendedImmediate = immediateRiskNotification1.RecommendedImmediateAction;

            var immediateRiskNotificationViewModel2 = new ImmediateRiskNotificationViewModel();
            immediateRiskNotificationViewModel2.Id = Guid.NewGuid();
            immediateRiskNotificationViewModel2.Reference = "Reference 3";
            immediateRiskNotificationViewModel2.Title = "Title 3";
            immediateRiskNotificationViewModel2.SignificantHazard = "Significant Hazard Identified 3";
            immediateRiskNotificationViewModel2.RecommendedImmediate = "Recommended Immediate Action 3";

            checklistViewModel.ImmediateRiskNotifications.Add(immediateRiskNotificationViewModel1);
            checklistViewModel.ImmediateRiskNotifications.Add(immediateRiskNotificationViewModel2);
            checklistViewModel.SiteId = 1;

            _checklistRepository
                .Setup(x => x.GetById(checklist.Id))
                .Returns(checklist);

            Checklist savedChecklist = null;

            _checklistRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Checklist>()))
                .Callback(
                    delegate(Checklist x)
                    {
                        savedChecklist = x;
                    }
                );

            var controller = GetTarget();
            var response = controller.PostChecklist(checklistViewModel.Id, checklistViewModel);
            Assert.That(savedChecklist, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(savedChecklist.Status, Is.EqualTo(checklistViewModel.Status));
            Assert.That(savedChecklist.Questions.Count, Is.EqualTo(0));
            Assert.That(savedChecklist.ImmediateRiskNotifications, Is.Not.Null);
            Assert.That(savedChecklist.ImmediateRiskNotifications.Count, Is.EqualTo(3));
            Assert.That(savedChecklist.ImmediateRiskNotifications.Count(x => !x.Deleted), Is.EqualTo(2));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Title, Is.EqualTo(immediateRiskNotificationViewModel1.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Reference, Is.EqualTo(immediateRiskNotificationViewModel1.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotificationViewModel1.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotificationViewModel1.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Deleted, Is.False);
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Title, Is.EqualTo(immediateRiskNotification2.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Reference, Is.EqualTo(immediateRiskNotification2.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotification2.SignificantHazardIdentified));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotification2.RecommendedImmediateAction));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Deleted, Is.True);
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Title, Is.EqualTo(immediateRiskNotificationViewModel2.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Reference, Is.EqualTo(immediateRiskNotificationViewModel2.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotificationViewModel2.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotificationViewModel2.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Deleted, Is.False);
        }
Пример #4
0
        public void Given_imediate_risk_notifications_are_included_in_request_for_new_checklist_When_PostChecklist_is_called_Then_IRNs_are_created()
        {
            var checklistViewModel = new ChecklistViewModel();
            checklistViewModel.ClientId = 161;
            checklistViewModel.SiteId = (int) _peninsulaSiteId;
            var irn1 = new ImmediateRiskNotificationViewModel();
            irn1.Id = Guid.NewGuid();
            irn1.Reference = "Reference 1";
            irn1.Title = "Title 1";
            irn1.SignificantHazard = "Significant Hazard Identified 1";
            irn1.RecommendedImmediate = "Recommended Immediate Action 1";
            var irn2 = new ImmediateRiskNotificationViewModel();
            irn2.Id = Guid.NewGuid();
            irn2.Reference = "Reference 2";
            irn2.Title = "Title 2";
            irn2.SignificantHazard = "Significant Hazard Identified 2";
            irn2.RecommendedImmediate = "Recommended Immediate Action 2";
            checklistViewModel.ImmediateRiskNotifications.Add(irn1);
            checklistViewModel.ImmediateRiskNotifications.Add(irn2);
            checklistViewModel.SiteId = 1;

            Checklist savedChecklist = null;
            _checklistRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Checklist>()))
                .Callback(
                    delegate(Checklist x)
                    {
                        savedChecklist = x;
                    }
                );

            var controller = GetTarget();
            var response = controller.PostChecklist(checklistViewModel.Id, checklistViewModel);
            Assert.That(savedChecklist, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(savedChecklist.Status, Is.EqualTo(checklistViewModel.Status));
            Assert.That(savedChecklist.Questions.Count, Is.EqualTo(0));
            Assert.That(savedChecklist.ImmediateRiskNotifications, Is.Not.Null);
            Assert.That(savedChecklist.ImmediateRiskNotifications.Count, Is.EqualTo(2));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Id, Is.EqualTo(irn1.Id));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Title, Is.EqualTo(irn1.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Reference, Is.EqualTo(irn1.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].SignificantHazardIdentified, Is.EqualTo(irn1.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].RecommendedImmediateAction, Is.EqualTo(irn1.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Id, Is.EqualTo(irn2.Id));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Title, Is.EqualTo(irn2.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Reference, Is.EqualTo(irn2.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].SignificantHazardIdentified, Is.EqualTo(irn2.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].RecommendedImmediateAction, Is.EqualTo(irn2.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Checklist, Is.EqualTo(savedChecklist));
        }