コード例 #1
0
        public void ReportInactiveSites_MultipleInactiveOrgs_OneOrgHasNoContacts_EmailSentToOrgWithContacts()
        {
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("1234", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("2345", null, DateTime.Today, null));

            _mockContext.tbRPT_OrgSupplier.AddObject(TestHelpers.PopulateTable.AddOrgSupplierDataRow("2345", "INPS"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("2345", "Highland Health Board"));

            _mockContext.tbRPT_HealthBoardContacts.AddObject(TestHelpers.PopulateTable.AddHealthBoardContactsDataRow(1, "Highland Health Board", "*****@*****.**"));
            _mockContext.tbRPT_SupplierContacts.AddObject(TestHelpers.PopulateTable.AddSupplierContactsDataRow(1, "INPS", "*****@*****.**"));

            List<String> _supplierContact = new List<string>();
            _supplierContact.Add("*****@*****.**");
            List<String> _healthBoardContact = new List<string>();
            _healthBoardContact.Add("*****@*****.**");

            _reportInactiveSites.SendInactiveReports();
            _log.Verify(log => log.Add("WARNING: No contacts for organisation: " + "1234" + " could be found."));

            _email.Verify(email => email.Send(_supplierContact, _healthBoardContact, "2345"), Times.Exactly(1));
            _log.Verify(log => log.Add("Inactive email report was sent for site: " + "2345"));
            Assert.AreEqual(_mockContext.tbRPT_InactiveSites.ElementAt(1).DateEmailSent, DateTime.Today);
        }
コード例 #2
0
        public void ReportInactiveSites_ErrorRaisedWhenSendingEmail_ErrorCaughtAndLogged()
        {
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("2345", null, DateTime.Today, null));

            _mockContext.tbRPT_OrgSupplier.AddObject(TestHelpers.PopulateTable.AddOrgSupplierDataRow("2345", "INPS"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("2345", "Highland Health Board"));

            _mockContext.tbRPT_HealthBoardContacts.AddObject(TestHelpers.PopulateTable.AddHealthBoardContactsDataRow(1, "Highland Health Board", "*****@*****.**"));
            _mockContext.tbRPT_SupplierContacts.AddObject(TestHelpers.PopulateTable.AddSupplierContactsDataRow(1, "INPS", "*****@*****.**"));

            List<String> _supplierContact = new List<string>();
            _supplierContact.Add("*****@*****.**");
            List<String> _healthBoardContact = new List<string>();
            _healthBoardContact.Add("*****@*****.**");

            _email.Setup(email => email.Send(_supplierContact, _healthBoardContact, "2345")).Throws(new Exception("Error sending email"));

            _reportInactiveSites.SendInactiveReports();

            _email.Verify(email => email.Send(_supplierContact, _healthBoardContact, "2345"), Times.Exactly(1));
            _log.Verify(log => log.Add("ERROR: Unable to send inactive report email for organisation: " + "2345" + ". Error message: " + "Error sending email"));
        }
コード例 #3
0
        public void ReportInactiveSites_InactiveOrgHasNoContacts_NoReportsSent()
        {
            // Going to need a proper repository for this test
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("1234", null, DateTime.Today, null));
            List<String> _emptyList = new List<string>();

            _reportInactiveSites.SendInactiveReports();
            _email.Verify(email => email.Send(_emptyList, It.IsAny<string>()), Times.Never());
            _log.Verify(log => log.Add("WARNING: No contacts for organisation: " + "1234" + " could be found."));
        }
コード例 #4
0
        /// <summary>
        /// This method first checks that the tool should be run (correct day of week to avoid picking up weekend activity + tbDailyActivityGP 
        /// // has been updated in the last 24 hours) before checking for any inactive sites and sending any inactive reports.
        /// </summary>
        public void RunCheck()
        {
            // Check running tool won't issue inactive reports based on weekend activity
            if (RunningCheckWillPickUpWeekendActivity() == true)
            {
                _log.Add("Running app today would pick up weekend activity. Run aborted.");
                return;
            }

            // Check that tbDailyActivityGP has been updated
            UpdateActivityData updateActivityData = new UpdateActivityData(_repository, _log);
            if (updateActivityData.CheckActivityDataHasBeenUpdated() == false)
            {
                _log.Add("tbDailyActivityGP was not updated yesterday");
                return;
            }

            // Update tbRPT_InactiveSites
            updateActivityData.UpdateData();

            ReportInactiveSites reportInactiveSites = new ReportInactiveSites(_repository, _log);
            // if number of inactive sites per healthboard limit is to be observed
            if (_applyHealthBoardInactiveSiteLimit == true)
            {
                if (reportInactiveSites.NumberOfInactiveSitesPerHealthBoardLimitExceeded() == false)
                {
                    // Send inactive reports
                    reportInactiveSites.SendInactiveReports();
                }
            }
            else   // Ignore limit - send inactive email reports regardless of how many inactive sites there are
            {

                // Send inactive reports
                reportInactiveSites.SendInactiveReports();
            }
        }
コード例 #5
0
        public void ReportInactiveSites_NumberOfInactiveSitesPerHealthBoardLimitExceeded_NoIactiveSites_LogInfo_ReturnsFalse()
        {
            // Going to need a proper repository for this test
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("1234", DateTime.Today, DateTime.Today, null));

            bool _limitExceeded = _reportInactiveSites.NumberOfInactiveSitesPerHealthBoardLimitExceeded();

            _log.Verify(log => log.Add("No newly inactive sites"));
            Assert.IsFalse(_limitExceeded);
        }
コード例 #6
0
        public void ReportInactiveSites_NumberOfInactiveSitesPerHealthBoardLimitExceeded_LimitNotExceeded_ReturnsFalse()
        {
            // Going to need a proper repository for this test
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("1234", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("2345", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("3456", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("4567", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("5678", null, DateTime.Today, null));

            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("1234", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("2345", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("3456", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("4567", "Grampian Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("5678", "Grampian Health Board"));

            bool _limitExceeded = _reportInactiveSites.NumberOfInactiveSitesPerHealthBoardLimitExceeded();

            Assert.IsFalse(_limitExceeded);
        }
コード例 #7
0
        public void ReportInactiveSites_NumberOfInactiveSitesPerHealthBoardLimitExceeded_LimitExceeded_ReturnsTrue()
        {
            // Going to need a proper repository for this test
            ActivityMonitor.Repository.Repository _repository = new ActivityMonitor.Repository.Repository(_log.Object, _mockContext);
            _reportInactiveSites = new ReportInactiveSites(_repository, _log.Object, _email.Object);

            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("0000", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("1111", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("2222", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("3333", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("4444", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("5555", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("6666", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("7777", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("8888", null, DateTime.Today, null));
            _mockContext.tbRPT_InactiveSites.AddObject(TestHelpers.PopulateTable.AddInactiveSitesDataRow("9999", null, DateTime.Today, null));

            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("0000", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("1111", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("2222", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("3333", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("4444", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("5555", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("6666", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("7777", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("8888", "Highland Health Board"));
            _mockContext.tbEPS_Organisation.AddObject(TestHelpers.PopulateTable.AddOrganisationDataRow("9999", "Highland Health Board"));

            bool _limitExceeded = _reportInactiveSites.NumberOfInactiveSitesPerHealthBoardLimitExceeded();

            _log.Verify(log => log.Add("WARNING: Healthboard limit exceeded for : Highland Health Board : number of inactive sites: 10"));
            Assert.IsTrue(_limitExceeded);
        }
コード例 #8
0
        public void ReportInactiveSites_NoInactiveOrganisations_NoReportsSent()
        {
            Mock<IRepository> _repository = new Mock<IRepository>();
            _reportInactiveSites = new ReportInactiveSites(_repository.Object, _log.Object, _email.Object);

            _repository.Setup(rep => rep.GetNewlyInactiveSites()).Returns(new List<String>());

            _reportInactiveSites.SendInactiveReports();

            _email.Verify(email => email.Send(It.IsAny<List<string>>(), It.IsAny<string>()), Times.Never());
            _log.Verify(log => log.Add("INFO: There are no newly inactive sites to send reports to."));
        }