public async Task Handle(DomainDeleted message) { string domainName = message.Id.ToLower(); MxEntityState state = await LoadState(domainName, nameof(message)); if (state.HostMxRecords != null && state.HostMxRecords.Count > 0) { List <string> uniqueHosts = await _dao.GetHostsUniqueToDomain(domainName); if (uniqueHosts.Count > 0) { await _dao.DeleteHosts(uniqueHosts); foreach (string host in uniqueHosts) { _dispatcher.Dispatch(new MxHostDeleted(host), _mxEntityConfig.SnsTopicArn); _log.LogInformation($"An MxHostDeleted message for Host: {host} has been dispatched to the SnsTopic: {_mxEntityConfig.SnsTopicArn}"); } } } await _dao.Delete(domainName); _log.LogInformation($"Deleted MX entity with id: {message.Id}."); }
public async Task ShouldDeleteWhenDomainDeletedReceived() { string domainName = "testDomainName"; string hostName = "testHostName"; DomainDeleted message = new DomainDeleted(domainName); MxEntityState stateFromDb = new MxEntityState(domainName.ToLower()) { MxState = MxState.Created, HostMxRecords = new List <HostMxRecord> { new HostMxRecord(hostName, 0, new List <string>()) } }; A.CallTo(() => _dao.Get(domainName.ToLower())).Returns(Task.FromResult(stateFromDb)); await _mxEntity.Handle(message); A.CallTo(() => _dao.Delete(domainName.ToLower())).MustHaveHappenedOnceExactly(); }