public async Task ItShouldGetTheStateIfItExists() { await Insert("ncsc.gov.uk"); TlsRptSchedulerState state = await _dao.Get("ncsc.gov.uk"); Assert.AreEqual(state.Id, "ncsc.gov.uk"); }
public async Task ItShouldSaveTheStateIfItDoesNotExist() { await _dao.Save(new TlsRptSchedulerState("ncsc.gov.uk")); await _dao.Get("ncsc.gov.uk"); TlsRptSchedulerState state = await _dao.Get("ncsc.gov.uk"); Assert.AreEqual(state.Id, "ncsc.gov.uk"); }
public async Task Save(TlsRptSchedulerState state) { int numberOfRowsAffected = await MySqlHelper.ExecuteNonQueryAsync( await _connectionInfo.GetConnectionStringAsync(), TlsRptSchedulerDaoResources.InsertTlsRptRecord, new MySqlParameter("id", state.Id.ToLower())); if (numberOfRowsAffected == 0) { throw new InvalidOperationException($"Didn't save duplicate {nameof(TlsRptSchedulerState)} for {state.Id}"); } }
public async Task Handle(TlsRptEntityCreated message) { string domain = message.Id.ToLower(); TlsRptSchedulerState state = await _dao.Get(domain); if (state == null) { state = new TlsRptSchedulerState(domain); await _dao.Save(state); _dispatcher.Dispatch(state.ToTlsRptRecordExpiredMessage(), _config.PublisherConnectionString); _log.LogInformation($"New {nameof(TlsRptSchedulerState)} saved for {domain}"); } else { _log.LogInformation($"{nameof(TlsRptSchedulerState)} already exists for {domain}"); } }
public static TlsRptRecordExpired ToTlsRptRecordExpiredMessage(this TlsRptSchedulerState state) => new TlsRptRecordExpired(state.Id);
public async Task ItShouldReturnNullIfTheStateDoesntExist() { TlsRptSchedulerState state = await _dao.Get("ncsc.gov.uk"); Assert.That(state, Is.Null); }