コード例 #1
0
        public void TwoJobsInSameDayShouldNotSendDuplicateExpiringEmails()
        {
            // Arange
            var cursorTime = new DateTimeOffset(year: 2018, month: 4, day: 10, hour: 8, minute: 2, second: 2, offset: TimeSpan.FromSeconds(0));
            var jobRunTime = cursorTime.AddHours(1);
            int warnDaysBeforeExpiration   = 2;
            var maxProcessedCredentialTime = cursorTime.AddDays(warnDaysBeforeExpiration);
            var jobMetadata             = new CredentialExpirationJobMetadata(jobRunTime, warnDaysBeforeExpiration, new JobRunTimeCursor(cursorTime, maxProcessedCredentialTime));
            var previouslyProcessedCred = new ExpiredCredentialData()
            {
                Expires = maxProcessedCredentialTime
            };
            var expiringCred = new ExpiredCredentialData()
            {
                // A datetime <= jobRunTime.AddDays(warnDaysBeforeExpiration) and larger than maxProcessedCredentialTime
                Expires = jobRunTime.AddDays(warnDaysBeforeExpiration).AddMinutes(-1)
            };
            var credentialSet = new List <ExpiredCredentialData> {
                previouslyProcessedCred, expiringCred
            };
            var testCredentials = new TestCredentialExpiration(jobMetadata, credentialSet);

            // Act
            var expiringCredentials = testCredentials.GetExpiringCredentials(credentialSet).OrderBy(c => c.Expires).ToList();

            // Assert
            Assert.Single(expiringCredentials);
            Assert.Equal(expiringCred.Expires, expiringCredentials[0].Expires);
        }
コード例 #2
0
        public void ExpiredCredentialsAreCorrectReturned()
        {
            // Arange
            var cursorTime = new DateTimeOffset(year: 2018, month: 4, day: 10, hour: 8, minute: 2, second: 2, offset: TimeSpan.FromSeconds(0));
            var jobRunTime = cursorTime.AddDays(2);
            var maxProcessedCredentialTime = cursorTime.AddDays(1);
            int warnDaysBeforeExpiration   = 2;
            var jobMetadata       = new CredentialExpirationJobMetadata(jobRunTime, warnDaysBeforeExpiration, new JobRunTimeCursor(cursorTime, cursorTime.AddDays(1)));
            var expiredCredential = new ExpiredCredentialData()
            {
                Expires = jobRunTime.AddHours(-1)
            };
            var notExpiredCredential1 = new ExpiredCredentialData()
            {
                Expires = jobRunTime
            };
            var notExpiredCredenatial2 = new ExpiredCredentialData()
            {
                Expires = jobRunTime.AddHours(1)
            };
            var credentialSet = new List <ExpiredCredentialData> {
                expiredCredential, notExpiredCredential1, notExpiredCredenatial2
            };
            var testCredentials = new TestCredentialExpiration(jobMetadata, credentialSet);

            // Act
            var expiredCredentials = testCredentials.GetExpiredCredentials(credentialSet).OrderBy(c => c.Expires).ToList();

            // Assert
            Assert.Single(expiredCredentials);
            Assert.Equal(expiredCredential.Expires, expiredCredentials[0].Expires);
        }
コード例 #3
0
        public void ExpiringCredentialsAreCorrectReturned()
        {
            // Arange
            var cursorTime = new DateTimeOffset(year: 2018, month: 4, day: 10, hour: 8, minute: 2, second: 2, offset: TimeSpan.FromSeconds(0));
            var jobRunTime = cursorTime.AddDays(2);
            var maxProcessedCredentialTime = cursorTime.AddDays(1);
            int warnDaysBeforeExpiration   = 2;
            var jobMetadata   = new CredentialExpirationJobMetadata(jobRunTime, warnDaysBeforeExpiration, new JobRunTimeCursor(cursorTime, cursorTime.AddDays(1)));
            var expiringCred1 = new ExpiredCredentialData()
            {
                Expires = jobRunTime.AddDays(warnDaysBeforeExpiration).AddHours(-1)
            };
            var expiringCred2 = new ExpiredCredentialData()
            {
                Expires = jobRunTime.AddDays(warnDaysBeforeExpiration)
            };
            var expiringOldCred = new ExpiredCredentialData()
            {
                // Time is smaller than the max of the credentials' time in the cursor
                Expires = maxProcessedCredentialTime.AddHours(-1)
            };
            var credentialSet = new List <ExpiredCredentialData> {
                expiringCred1, expiringCred2, expiringOldCred
            };
            var testCredentials = new TestCredentialExpiration(jobMetadata, credentialSet);

            // Act
            var expiringCred = testCredentials.GetExpiringCredentials(credentialSet).OrderBy(c => c.Expires).ToList();

            // Assert
            Assert.Equal(2, testCredentials.GetExpiringCredentials(credentialSet).Count);
            Assert.Equal(expiringCred1.Expires, expiringCred[0].Expires);
            Assert.Equal(expiringCred2.Expires, expiringCred[1].Expires);
        }
コード例 #4
0
 public TestCredentialExpiration(CredentialExpirationJobMetadata jobMetadata, List <ExpiredCredentialData> credentialSet)
 {
     _jobMetadata   = jobMetadata;
     _credentialSet = credentialSet;
     _galleryCredentialsExpiration = new GalleryCredentialExpiration(null, jobMetadata);
     _maxNotificationDate          = _galleryCredentialsExpiration.GetMaxNotificationDate();
     _minNotificationDate          = _galleryCredentialsExpiration.GetMinNotificationDate();
 }
コード例 #5
0
        public void GetMaxAndGetMinAreAsExpected()
        {
            // Arange
            var cursorTime = new DateTimeOffset(year: 2018, month: 4, day: 10, hour: 8, minute: 2, second: 2, offset: TimeSpan.FromSeconds(0));
            var jobRunTime = cursorTime.AddHours(1);
            int warnDaysBeforeExpiration   = 2;
            var maxProcessedCredentialTime = cursorTime.AddDays(warnDaysBeforeExpiration);
            var jobMetadata     = new CredentialExpirationJobMetadata(jobRunTime, warnDaysBeforeExpiration, new JobRunTimeCursor(cursorTime, maxProcessedCredentialTime));
            var testCredentials = new TestCredentialExpiration(jobMetadata, null);

            // Act
            var minValue = testCredentials.GetMinNotificationDate();
            var maxValue = testCredentials.GetMaxNotificationDate();

            // Assert
            Assert.Equal(cursorTime, minValue);
            Assert.Equal(jobRunTime.AddDays(warnDaysBeforeExpiration), maxValue);
        }
コード例 #6
0
 public GalleryCredentialExpiration(Job job, CredentialExpirationJobMetadata jobMetadata)
 {
     _job         = job;
     _jobMetadata = jobMetadata;
 }