private async Task HandleReadyToPoll(string hostName, string messageType) { TlsEntityState state = await LoadState(hostName, messageType); if (state.LastUpdated == null || _clock.GetDateTimeUtc() > state.LastUpdated.Value.AddSeconds(_tlsEntityConfig.TlsResultsCacheInSeconds)) { state.TlsState = TlsState.PollPending; await _dao.Save(state); _dispatcher.Dispatch(new TlsTestPending(hostName), _tlsEntityConfig.SnsTopicArn); _log.LogInformation($"A TlsTestPending message for host: {hostName} has been dispatched to SnsTopic: {_tlsEntityConfig.SnsTopicArn}"); } else { _log.LogInformation($"A request to re-test {hostName} was ignored as it was last tested at {state.LastUpdated.Value} and the re-test cache " + $"is {TimeSpan.FromSeconds(_tlsEntityConfig.TlsResultsCacheInSeconds):dd\\d\\:hh\\h\\:mm\\m\\:ss\\s}."); // dd/hh/mm/ss } }
public async Task ShouldUpdateAndDispatchPollPendingWhenScheduledReminderFirstReceived() { const string hostName = "testhostname"; const string snsTopicArn = "snsTopicArn"; A.CallTo(() => _dao.Get(hostName)).Returns(new TlsEntityState(hostName) { TlsState = TlsState.Created, LastUpdated = null }); A.CallTo(() => _tlsEntityConfig.SnsTopicArn).Returns(snsTopicArn); await _tlsEntity.Handle(new TlsScheduledReminder(Guid.NewGuid().ToString(), hostName)); A.CallTo(() => _dao.Save(A <TlsEntityState> .That.Matches(e => e.TlsState == TlsState.PollPending))).MustHaveHappenedOnceExactly(); A.CallTo(() => _dispatcher.Dispatch(A <TlsTestPending> .That.Matches(entity => entity.Id == hostName), snsTopicArn)).MustHaveHappenedOnceExactly(); }