public async Task Should_send_email_for_new_user() { var @event = CreateEvent(RefTokenType.Subject, true); await sut.On(@event); A.CallTo(() => emailSender.SendContributorEmailAsync(assigner, assignee, appName, true)) .MustHaveHappened(); }
public async Task On(Envelope <IEvent> @event) { if (!emailSender.IsActive) { return; } if (@event.Headers.EventStreamNumber() <= 1) { return; } var now = SystemClock.Instance.GetCurrentInstant(); var timestamp = @event.Headers.Timestamp(); if (now - timestamp > MaxAge) { return; } if (@event.Payload is AppContributorAssigned appContributorAssigned) { if (!appContributorAssigned.Actor.IsSubject || !appContributorAssigned.IsAdded) { return; } var assignerId = appContributorAssigned.Actor.Identifier; var assigneeId = appContributorAssigned.ContributorId; var assigner = await userResolver.FindByIdOrEmailAsync(assignerId); if (assigner == null) { LogWarning($"Assigner {assignerId} not found"); return; } var assignee = await userResolver.FindByIdOrEmailAsync(appContributorAssigned.ContributorId); if (assignee == null) { LogWarning($"Assignee {assigneeId} not found"); return; } var appName = appContributorAssigned.AppId.Name; var isCreated = appContributorAssigned.IsCreated; await emailSender.SendContributorEmailAsync(assigner, assignee, appName, isCreated); } }