public async Task Handle(DomainCreated message) { string domainName = message.Id.ToLower(); MxEntityState state = await _dao.Get(domainName); if (state != null) { _log.LogInformation($"Ignoring {nameof(DomainCreated)} as MxEntity already exists for {domainName}."); return; } await _dao.Save(new MxEntityState(domainName)); _log.LogInformation($"Created MxEntity for {domainName}."); MxEntityCreated mxEntityCreated = new MxEntityCreated(domainName); _dispatcher.Dispatch(mxEntityCreated, _mxEntityConfig.SnsTopicArn); _log.LogInformation( $"An MxEntityCreated message for Domain: {domainName} has been dispatched to SnsTopic: {_mxEntityConfig.SnsTopicArn}"); Message createScheduledReminder = new CreateScheduledReminder(Guid.NewGuid().ToString(), "Mx", domainName, _clock.GetDateTimeUtc()); _dispatcher.Dispatch(createScheduledReminder, _mxEntityConfig.SnsTopicArn); _log.LogInformation( $"A CreateScheduledReminder message for Domain: {domainName} has been dispatched to SnsTopic: {_mxEntityConfig.SnsTopicArn}"); }
public async Task ShouldThrowWhenDomainCreatedReceivedAndDomainAlreadyExists() { string domainName = "testDomainName"; A.CallTo(() => _dao.Get(domainName)).Returns(Task.FromResult(new MxEntityState(""))); await _mxEntity.Handle(new DomainCreated(domainName, string.Empty, DateTime.MaxValue)); A.CallTo(() => _dao.Save(A <MxEntityState> .Ignored)).MustNotHaveHappened(); }