public async Task WhenUpdatingRecordWithOldVersionShouldThrowException() { DkimSchedulerState oldRecord = new DkimSchedulerState("abc.com"); await _dkimSchedulerDao.Save(oldRecord); InvalidOperationException exception = Assert.ThrowsAsync <InvalidOperationException>(() => _dkimSchedulerDao.Save(oldRecord)); Assert.That(exception.Message, Is.EqualTo($"Didn't save duplicate DkimSchedulerState for abc.com")); }
public async Task InsertRecordTest() { DkimSchedulerState record = new DkimSchedulerState("abc.com"); await _dkimSchedulerDao.Save(record); List <DkimSchedulerState> results = await GetValues(); Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results.First().Id, Is.EqualTo(record.Id)); }
public async Task Save(DkimSchedulerState state) { string connectionString = await _connectionInfo.GetConnectionStringAsync(); int numberOfRowsAffected = await MySqlHelper.ExecuteNonQueryAsync(connectionString, DkimSchedulerDaoResources.InsertOrUpdateRecord, new MySqlParameter("domain", state.Id.ToLower())); if (numberOfRowsAffected == 0) { throw new InvalidOperationException($"Didn't save duplicate {nameof(DkimSchedulerState)} for {state.Id}"); } }
public async Task GetDkimStatesToUpdateWhenNoOldRecordsTest() { DkimSchedulerState record = new DkimSchedulerState("abc.com"); DkimSchedulerState record2 = new DkimSchedulerState("def.com"); await _dkimSchedulerDao.Save(record); await _dkimSchedulerDao.Save(record2); var results = await _dkimPeriodicSchedulerDao.GetDkimRecordsToUpdate(); Assert.That(results.Count, Is.EqualTo(0)); }
public async Task Handle(DkimEntityCreated message) { string domain = message.Id.ToLower(); DkimSchedulerState state = await _dkimSchedulerDao.Get(domain); if (state == null) { state = new DkimSchedulerState(domain); await _dkimSchedulerDao.Save(state); _log.LogInformation($"{domain} added to DkimScheduler"); } else { _log.LogInformation($"{domain} already exists in DkimScheduler"); } }
public async Task GetDkimStatesToUpdateWhenHasOldRecordsTest() { DkimSchedulerState record = new DkimSchedulerState("abc.com"); DkimSchedulerState record2 = new DkimSchedulerState("def.com"); await _dkimSchedulerDao.Save(record); await _dkimSchedulerDao.Save(record2); await UpdateLastChecked(2); var results = await _dkimPeriodicSchedulerDao.GetDkimRecordsToUpdate(); Assert.That(results.Count, Is.EqualTo(2)); //first record Assert.That(results.First().Id, Is.EqualTo(record.Id)); //last record Assert.That(results.Last().Id, Is.EqualTo(record2.Id)); }
public static DkimRecordsExpired ToDkimPollMessage(this DkimSchedulerState dkimSchedulerRecord) { return(new DkimRecordsExpired(dkimSchedulerRecord.Id, Guid.NewGuid().ToString(), null)); }