public void Given_a_checklist_then_the_view_model_site_is_set()
        {
            var site = new SiteAddressResponse() {Id = 1212431241,  SiteName = "the site name", Address1 = "Address1", Postcode = "the postcode", };

            _clientDetailsService
                .Setup(x => x.GetSite(It.IsAny<int>(),It.IsAny<int>()))
                .Returns(site);

            _clientDetailsService
                .Setup(x => x.GetSites(It.IsAny<int>()))
                .Returns( new List<SiteAddressResponse>{ site} );

            _checklistRepo
                .Setup(x => x.GetByClientId(It.IsAny<long>()))
                .Returns(new List<Checklist>() { new Checklist() { SiteId = (int?) site.Id} });
                        

            //when
            var target = new ChecklistController(_dependencyFactory.Object);


            var result = target.GetByClientId(123414);
            Assert.That(result.First().Site.SiteName, Is.EqualTo(site.SiteName));
            Assert.That(result.First().Site.Postcode, Is.EqualTo(site.Postcode));
            
        }
 public SiteAddressDto Map(SiteAddressResponse siteAddressResponse)
 {
     var contact = Mapper.Map<Contact, ContactDto>(siteAddressResponse.SiteContact);
     var siteAddressDto = Mapper.Map<SiteAddressResponse, SiteAddressDto>(siteAddressResponse);
     siteAddressDto.SiteAddress = contact;
     return siteAddressDto;
 }
 public CompanyDetailsResponse()
 {
     Id = 0;
     CompanyName = string.Empty;
     CAN = string.Empty;
     Website = string.Empty;
     MainContact = new Contact();
     MainSiteAddress = new SiteAddressResponse();
     Industry = string.Empty;
 }
        public static ChecklistIndexViewModel Map(this Checklist checklist, SiteAddressResponse visitSite)
        {
            var checklistViewModel = checklist.Map();
            checklistViewModel.Site.Id = visitSite != null ? (int)visitSite.Id : -1;
            checklistViewModel.Site.Postcode = visitSite != null ? visitSite.Postcode : "";
            checklistViewModel.Site.SiteName = visitSite != null ? visitSite.SiteName : "";
            checklistViewModel.Site.Address1 = visitSite != null ? visitSite.Address1 : "";
            checklistViewModel.Site.Address2 = visitSite != null ? visitSite.Address2 : "";
            checklistViewModel.Site.Address3 = visitSite != null ? visitSite.Address3 : "";
            checklistViewModel.Site.Address4 = visitSite != null ? visitSite.Address4 : "";

            return checklistViewModel;
        }
Exemplo n.º 5
0
        public void Given_a_checklist_has_immediate_risk_notifications_attached_When_GetChecklist_called_Then_IRNs_are_returned()
        {
            var site = new SiteAddressResponse() { Id = 1212431241, SiteName = "the site name", Address1 = "Address1", Postcode = "the postcode", };

            var checklist1 = new Checklist();
            checklist1.Id = Guid.NewGuid();
            checklist1.ClientId = 2424;
            checklist1.SiteId = (int?)site.Id;
            var immediateRiskNotification1 = new ImmediateRiskNotification();
            immediateRiskNotification1.Id = Guid.NewGuid();
            immediateRiskNotification1.Reference = "Reference 1";
            immediateRiskNotification1.Title = "Title 1";
            immediateRiskNotification1.SignificantHazardIdentified = "Significant Hazard Identified 1";
            immediateRiskNotification1.RecommendedImmediateAction = "Recommended Imediate Action 1";
            checklist1.ImmediateRiskNotifications.Add(immediateRiskNotification1);
            var immediateRiskNotification2 = new ImmediateRiskNotification();
            immediateRiskNotification2.Id = Guid.NewGuid();
            immediateRiskNotification2.Reference = "Reference 2";
            immediateRiskNotification2.Title = "Title 2";
            immediateRiskNotification2.SignificantHazardIdentified = "Significant Hazard Identified 2";
            immediateRiskNotification2.RecommendedImmediateAction = "Recommended Imediate Action 2";
            checklist1.ImmediateRiskNotifications.Add(immediateRiskNotification2);

            checklist1.AddImmediateRiskNotification(immediateRiskNotification1);
            checklist1.AddImmediateRiskNotification(immediateRiskNotification2);

            checklistRepo
                .Setup(x => x.GetById(checklist1.Id))
                .Returns(checklist1);

            var target = new ChecklistController(dependencyFactory.Object);

            var result = target.GetChecklist(checklist1.Id);

            Assert.That(result.ImmediateRiskNotifications.Count, Is.EqualTo(2));
            Assert.That(result.ImmediateRiskNotifications[0].Id, Is.EqualTo(immediateRiskNotification1.Id));
            Assert.That(result.ImmediateRiskNotifications[0].Reference, Is.EqualTo(immediateRiskNotification1.Reference));
            Assert.That(result.ImmediateRiskNotifications[0].Title, Is.EqualTo(immediateRiskNotification1.Title));
            Assert.That(result.ImmediateRiskNotifications[0].SignificantHazard, Is.EqualTo(immediateRiskNotification1.SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[0].RecommendedImmediate, Is.EqualTo(immediateRiskNotification1.RecommendedImmediateAction));
            Assert.That(result.ImmediateRiskNotifications[1].Id, Is.EqualTo(immediateRiskNotification2.Id));
            Assert.That(result.ImmediateRiskNotifications[1].Reference, Is.EqualTo(immediateRiskNotification2.Reference));
            Assert.That(result.ImmediateRiskNotifications[1].Title, Is.EqualTo(immediateRiskNotification2.Title));
            Assert.That(result.ImmediateRiskNotifications[1].SignificantHazard, Is.EqualTo(immediateRiskNotification2.SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[1].RecommendedImmediate, Is.EqualTo(immediateRiskNotification2.RecommendedImmediateAction));
        }
Exemplo n.º 6
0
        public void Given_a_query_and_dates_are_BST_then_dates_return_as_UTC()
        {
            //given
            var BSTDate = new DateTime(2014, 04, 06);
            var clientId = 234234;
            var clientAccountNumber = "TESTACTULAR";
            var expectedStatus = "Open";
            var checklist = new Checklist(){VisitDate = BSTDate};

            var site = new SiteAddressResponse() {Id = 1212431241, SiteName = "Rekall", Postcode = "MARS 7TU"};

            _clientDetailsService
                .Setup(x => x.GetSite(clientId, (int)site.Id))
                .Returns(() => site);

            _clientDetailsService
                .Setup(x => x.GetByClientAccountNumber(clientAccountNumber))
                .Returns(() => new CompanyDetailsResponse() { CAN = clientAccountNumber, Id = clientId });

            _clientDetailsService
                .Setup(x => x.Get(It.IsAny<int>()))
                .Returns(new CompanyDetails() { CAN = "Can" });

            _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object);

            _getChecklistsQuery.Setup(x => x.Execute())
                .Returns(() => new List<ChecklistIndex>()
                                  {
                                      new ChecklistIndex() {ClientId = clientId, SiteId = (int?) site.Id, Status = expectedStatus, VisitDate = BSTDate, CompletedDate = BSTDate, SubmittedDate = BSTDate, QaAdvisorAssignedOn = BSTDate}
                                  });

            //when
            var target = new ChecklistController(_dependencyFactory.Object);

            var result = target.Query(clientAccountNumber, null, null, null, false, false, null, null);

            Assert.That(result.First().VisitDate, Is.EqualTo(BSTDate.ToUniversalTime()));
            Assert.That(result.First().CompletedOn, Is.EqualTo(BSTDate.ToUniversalTime()));
            Assert.That(result.First().SubmittedOn, Is.EqualTo(BSTDate.ToUniversalTime()));
            Assert.That(result.First().QaAdvisorAssignedOn, Is.EqualTo(BSTDate.ToUniversalTime()));
        }
Exemplo n.º 7
0
        public void Given_i_query_by_client_account_number_then_the_site_details_are_set()
        {
            var clientId = 234234;
            var clientAccountNumber = "TESTACTULAR";
            var expectedPostcode = "MARS 7TU";
            var expectedSiteName = "Rekall";
            var expectedAddress = "29 Acaciar Road";
            var expectedStatus = "Open";

            var site = new SiteAddressResponse() {Id = 1212431241, SiteName = expectedSiteName, Postcode = expectedPostcode, Address1 = expectedAddress};

            _clientDetailsService
                .Setup(x => x.GetSite(clientId, (int) site.Id))
                .Returns(() => site);

            _clientDetailsService
                .Setup(x => x.GetByClientAccountNumber(clientAccountNumber))
                .Returns(() => new CompanyDetailsResponse() {CAN = clientAccountNumber, Id = clientId});

            _clientDetailsService
                .Setup(x => x.Get(It.IsAny<int>()))
                .Returns(new CompanyDetails() { CAN = "Can" });


            _checklistRepository.Setup(x => x.Search(clientId, null, null, null, false, null))
               .Returns(() => new List<Checklist>()
                                  {
                                      new Checklist() {ClientId = clientId, SiteId = (int?) site.Id, Status = expectedStatus}
                                  });

            //when
            var target = new ChecklistController(_dependencyFactory.Object);

            var result = target.Query(clientAccountNumber, null, null, null, false);

            //Assert.That(result.All(x => string.IsNullOrEmpty(x.Postcode) == false), Is.EqualTo(false));
            Assert.That(result.First().Site.Postcode, Is.EqualTo(expectedPostcode));
            Assert.That(result.First().Site.SiteName, Is.EqualTo(expectedSiteName));
            Assert.That(result.First().Site.Address1, Is.EqualTo(expectedAddress));
            Assert.That(result.First().Status, Is.EqualTo(expectedStatus));
        }
        public static ChecklistIndexViewModel Map(this Checklist checklist, SiteAddressResponse visitSite, string clientAccountNumber, QaAdvisor qaAdvisor)
        {
            var checklistViewModel = checklist.Map(visitSite);
            checklistViewModel.CAN = clientAccountNumber;
            checklistViewModel.HasQaComments = checklist.Answers.Any(x => !string.IsNullOrEmpty(x.QaComments) && x.QaSignedOffBy == null);
            checklistViewModel.Deleted = checklist.Deleted;

            if (qaAdvisor != null)
            {
                checklistViewModel.QaAdvisor = new QaAdvisorViewModel()
                {
                    Id = qaAdvisor.Id,
                    Forename = qaAdvisor.Forename,
                    Email = qaAdvisor.Email,
                    Fullname = qaAdvisor.Forename + ' ' + qaAdvisor.Surname,
                    Initials = qaAdvisor.Forename + ' ' +  (qaAdvisor.Surname.Length > 0 ? qaAdvisor.Surname.Substring(0, 1) : "")
                };    
            }

            return checklistViewModel;
        }
        public void Given_a_checklist_with_a_valid_site_id_Then_site_details_are_returned()
        {
            var clientId = 114876;
            // GIVEN
            var siteAddressResponse = new SiteAddressResponse();
            siteAddressResponse.Id = 1234124124;
            siteAddressResponse.SiteName = "the site name";
            siteAddressResponse.Address1 = "1 main streest";
            siteAddressResponse.Address2 = "the town";
            siteAddressResponse.Address3 = "the county";
            siteAddressResponse.Address4 = "somethin else";
            siteAddressResponse.Postcode = "M21 7ND";

            _clientDetailsService.Setup(x => x.GetSite(clientId, (int) siteAddressResponse.Id))
                .Returns(siteAddressResponse);

            ChecklistViewModel chkModel = CreateChecklistViewModel();
            chkModel.SiteId = (int) siteAddressResponse.Id;
            chkModel.ClientId = clientId;

            // WHEN
            var target = GetTarget();
            ComplianceReviewReportViewModel model = target.GetViewModel(chkModel);

            // THEN
            Assert.AreEqual(siteAddressResponse.Id, model.Site.Id);
            Assert.AreEqual(siteAddressResponse.SiteName, model.Site.SiteName);

            Assert.AreEqual(siteAddressResponse.Address1, model.Site.Address1);
            Assert.AreEqual(siteAddressResponse.Address2, model.Site.Address2);
            Assert.AreEqual(siteAddressResponse.Address3, model.Site.Address3);
            Assert.AreEqual(siteAddressResponse.Address4, model.Site.Address4);
            Assert.AreEqual(siteAddressResponse.Postcode, model.Site.Postcode);
        }
Exemplo n.º 10
0
        public void given_parameters_when_query_then_execute_is_called_with_correct_parameters()
        {
            //given
            int clientId = 1234;
            string can = "CAN01";
            string checklistCreatedBy ="consultant.name";
            string visitDate = DateTime.Now.ToShortDateString();
            string checklistStatus = "Draft";
            bool includeDeleted = false;
            bool excludeSubmitted = true;
            var checklist = new Checklist();

            var site = new SiteAddressResponse() {Id = 1234L,};
                  _clientDetailsService
                .Setup(x => x.GetByClientAccountNumber(can))
                .Returns(() => new CompanyDetailsResponse() {CAN = can, Id = clientId});

            _clientDetailsService
                .Setup(x => x.Get(It.IsAny<int>()))
                .Returns(new CompanyDetails() {CAN = "Can"});

            _clientDetailsService
                .Setup(x => x.GetSite(It.IsAny<int>(), It.IsAny<int>()))
                .Returns(() => site);

            _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);

            _getChecklistsQuery
                .Setup(
                    x =>
                    x.Execute())
                .Returns(() => new List<ChecklistIndex>()
                                  {
                                      new ChecklistIndex() {ClientId = clientId, SiteId = (int?) site.Id, Status = checklistStatus}
                                  });

            _checklistRepository.Setup(x => x.GetById(It.IsAny<Guid>()))
               .Returns(checklist);
            //when
            var target = new ChecklistController(_dependencyFactory.Object);

            target.Query(can, checklistCreatedBy, visitDate, checklistStatus, includeDeleted, excludeSubmitted, null, null);

            //then
            _getChecklistsQuery
                .Verify(
                    x =>
                    x.Execute());
        }
Exemplo n.º 11
0
        public void Given_i_query_by_user_then_the_createBy_and_qaAdvisor_are_queried()
        {
            var clientId = 234234;
            var clientAccountNumber = "TESTACTULAR";
            var expectedPostcode = "MARS 7TU";
            var expectedSiteName = "Rekall";
            var expectedAddress = "29 Acaciar Road";
            var userName = "******";
            var qaAdvisorId = Guid.NewGuid();

            var site = new SiteAddressResponse() { Id = 1212431241, SiteName = expectedSiteName, Postcode = expectedPostcode, Address1 = expectedAddress };

            _clientDetailsService
                .Setup(x => x.GetSite(clientId, (int)site.Id))
                .Returns(() => site);

            _clientDetailsService
                .Setup(x => x.GetByClientAccountNumber(clientAccountNumber))
                .Returns(() => new CompanyDetailsResponse() { CAN = clientAccountNumber, Id = clientId });

            _clientDetailsService
                .Setup(x => x.Get(It.IsAny<int>()))
                .Returns(new CompanyDetails() { CAN = "Can" });

            _qaAdvisorRepository
                .Setup(x => x.GetByFullname(userName))
                .Returns(() => new QaAdvisor() {Id = qaAdvisorId, Forename = "Jack", Surname = "Reacher"});

            _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object);
            _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object);

            //when
            var target = new ChecklistController(_dependencyFactory.Object);

            var result = target.Query(null, userName, null, null, false, false, null, null);

            _getChecklistsQuery
                .Verify(x => x.Execute(),Times.Once);
        }