Ejemplo n.º 1
0
        public async Task ChecksIfNeedToSend_OnlySentNotifications()
        {
            // Arrange
            var context = _serviceProvider.GetRequiredService <IDataContext>();
            await context.Notifications.AddAsync(new Notification());

            await context.SaveChangesAsync();

            var notificationService = new NotificationService(
                new Mock <ILogger <NotificationService> >().Object,
                _config,
                context,
                new Mock <IEmailService>().Object,
                new Mock <ISlackService>().Object
                );

            // Act
            var actual = Enum
                         .GetValues(typeof(NotificationSeverity))
                         .Cast <object>()
                         .Select(async severity => await notificationService.CheckIfNeedToSendAsync((NotificationSeverity)severity))
                         .Select(task => task.Result)
                         .Aggregate((self, next) => self && next);

            // Assert
            Assert.True(actual);
        }
Ejemplo n.º 2
0
        public async Task ChecksIfNeedToSend_TooRecentNotification()
        {
            // Arrange
            var context = _serviceProvider.GetRequiredService <IDataContext>();

            await context.Notifications.AddAsync(
                new Notification
            {
                IsSent   = true,
                DateSent = DateTime.UtcNow.AddSeconds(-30),
                Severity = NotificationSeverity.High
            }
                );

            await context.SaveChangesAsync();

            var notificationService = new NotificationService(
                new Mock <ILogger <NotificationService> >().Object,
                _config,
                context,
                new Mock <IEmailService>().Object,
                new Mock <ISlackService>().Object
                );

            // Act
            var actual = await notificationService.CheckIfNeedToSendAsync(NotificationSeverity.High);

            // Assert
            Assert.False(actual);
        }