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);
        }
        public void OutdatedCursorShouldNotSendExpiringToExpiredEmails()
        {
            // 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);
            int warnDaysBeforeExpiration   = 2;
            var maxProcessedCredentialTime = jobRunTime.AddDays(-1);
            var jobMetadata = new CredentialExpirationJobMetadata(jobRunTime, warnDaysBeforeExpiration, new JobRunTimeCursor(cursorTime, maxProcessedCredentialTime));

            var expiredCred = new ExpiredCredentialData()
            {
                Expires = maxProcessedCredentialTime.AddHours(1)
            };
            var expiringCred = new ExpiredCredentialData()
            {
                // A datetime <= jobRunTime.AddDays(warnDaysBeforeExpiration) and larger than maxProcessedCredentialTime
                Expires = jobRunTime.AddDays(warnDaysBeforeExpiration).AddMinutes(-1)
            };
            var credentialSet = new List <ExpiredCredentialData> {
                expiredCred, expiringCred
            };
            var testCredentials = new TestCredentialExpiration(jobMetadata, credentialSet);

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

            // Assert
            Assert.Single(expiringCredentials);
            Assert.Equal(expiringCred.Expires, expiringCredentials[0].Expires);
            Assert.Single(expiredCredentials);
            Assert.Equal(expiredCred.Expires, expiredCredentials[0].Expires);
        }