コード例 #1
0
        public void WithNotificationDelayGtLastNotificationSentAtReturnsCorrectResult()
        {
            //Arrange
            var  sentAt = DateTime.UtcNow.AddMinutes(-5);
            User user   = new User {
                EmailAdress = "*****@*****.**"
            };
            Notification notification = new Notification {
                IsEnabled = true, Name = "Test Notification", Type = NotificationType.Warning
            };
            NotificationRecipient notificationRecipient = new NotificationRecipient {
                Delay = new TimeSpan(0, 0, 30), DeliveryMode = DeliveryMode.Email, Notification = notification, NotificationsPerEvent = 5, User = user
            };
            NotificationEvent notificationEvent = new NotificationEvent {
                Active = true, LastAlertTime = DateTime.UtcNow, Notification = notification, Value = "Test Failed"
            };
            NotificationEventLog notificationEventLog = new NotificationEventLog {
                NotificationEvent = notificationEvent, NotificationRecipient = notificationRecipient, SentAt = sentAt
            };
            NotificationEvent result;

            using (var context = new AppDbContext())
            {
                context.Users.Add(user);
                context.NotificationEventLogs.Add(notificationEventLog);
                context.SaveChanges();
            }
            //Act
            using (var context = new AppDbContext())
            {
                result = context.NotificationEvents.WithNotificationDelayGtLastNotificationSentAt(DateTime.UtcNow).FirstOrDefault();
            }

            using (var context = new AppDbContext())
            {
                context.NotificationEventLogs.Remove(notificationEventLog);
                context.NotificationEvents.Remove(notificationEvent);
                context.NotificationRecipients.Remove(notificationRecipient);
                context.Notifications.Remove(notification);
                context.Users.Remove(user);
                context.SaveChanges();
            }
            //Assert
            Assert.IsNotNull(result);
        }
コード例 #2
0
        public void WithNotificationDelayGtLastNotificationSentAtReturnsCorrectResult()
        {
            var sentAt       = DateTime.UtcNow.AddMinutes(-5);
            var notification = new Notification {
                IsEnabled = true
            };
            var notificationRecipient1 = new NotificationRecipient {
                Delay = new TimeSpan(0, 0, 10), Notification = notification
            };
            var notificationEvent1 = new NotificationEvent {
                Notification = notification, Active = true
            };
            var notificationEventLog1 = new NotificationEventLog
            {
                NotificationEvent     = notificationEvent1,
                NotificationRecipient = notificationRecipient1,
                SentAt = sentAt
            };
            var notificationRecipients = new List <NotificationRecipient>
            {
                notificationRecipient1
            };
            var notificationEvents = new List <NotificationEvent>
            {
                notificationEvent1
            };
            var notificationEventLogs = new List <NotificationEventLog>
            {
                notificationEventLog1
            };

            //Add collections
            notification.NotificationRecipients          = notificationRecipients;
            notification.NotificationEvents              = notificationEvents;
            notificationEvent1.NotificationEventLogs     = notificationEventLogs;
            notificationRecipient1.NotificationEventLogs = notificationEventLogs;

            var result = notificationEvents.AsQueryable().WithNotificationDelayGtLastNotificationSentAt(DateTime.UtcNow).FirstOrDefault();

            Assert.IsNotNull(result);
        }