public async Task ItShouldSaveAndDispatchTheSpfStateIfItDoesntExist() { A.CallTo(() => _dao.Get(A <string> ._)).Returns <SpfSchedulerState>(null); await _sut.Handle(new SpfEntityCreated("ncsc.gov.uk", 1)); A.CallTo(() => _dao.Save(A <SpfSchedulerState> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _dispatcher.Dispatch(A <SpfRecordExpired> ._, A <string> ._)) .MustHaveHappenedOnceExactly(); }
public async Task Handle(SpfEntityCreated message) { string domain = message.Id.ToLower(); SpfSchedulerState state = await _dao.Get(domain); if (state == null) { state = new SpfSchedulerState(domain); await _dao.Save(state); _dispatcher.Dispatch(state.ToSpfRecordExpiredMessage(), _config.PublisherConnectionString); _log.LogInformation($"New {nameof(SpfSchedulerState)} saved for {domain}"); } else { _log.LogInformation($"{nameof(SpfSchedulerState)} already exists for {domain}"); } }