public async Task NotifyAsync(UsageNotification notification) { var now = DateTime.UtcNow; if (!HasBeenSentBefore(notification.AppId, now)) { if (notificationSender.IsActive) { foreach (var userId in notification.Users) { var user = await userResolver.FindByIdOrEmailAsync(userId); if (user != null) { notificationSender.SendUsageAsync(user, notification.AppName, notification.Usage, notification.UsageLimit).Forget(); } } } await TrackNotifiedAsync(notification.AppId, now); } }
public async Task Should_not_send_notification_if_not_active() { SetupUser("1", null); SetupUser("2", null); var notification = new UsageNotification { AppName = "my-app", Usage = 1000, UsageLimit = 3000, Users = new[] { "1", "2" } }; await sut.NotifyAsync(notification); A.CallTo(() => notificationSender.SendUsageAsync(A <IUser> ._, "my-app", 1000, 3000)) .MustNotHaveHappened(); }