Пример #1
0
        public void DeleteOlderThanAsync_MultipleOlderAndNewerNotifications_RemovesOlderNotificationsOnlyFromDatabase()
        {
            var notification = new Notification();

            var(context, notificationService) = CreateTestTools(
                nameof(DeleteOlderThanAsync_MultipleOlderAndNewerNotifications_RemovesOlderNotificationsOnlyFromDatabase)
                );

            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            NotificationDataManager.CreateNotification(context, notification, NotificationType.SEND_GRID);
            NotificationDataManager.CreateNotification(context, notification, NotificationType.SEND_GRID);

            var timeSpan = TimeSpan.FromSeconds(10);

            foreach (var not in context.Notifications.Where(n => n.Type.Equals(NotificationType.SEND_GRID)))
            {
                not.CreationTime = DateTime.Now - timeSpan;
            }

            context.SaveChanges();

            var threshold = DateTime.Now - TimeSpan.FromSeconds(2);
            var task      = notificationService.DeleteOlderThanAsync(threshold);

            task.Wait();

            foreach (var not in context.Notifications)
            {
                Assert.True(DateTime.Compare(not.CreationTime, threshold) >= 0);
            }
        }
Пример #2
0
 private static void AssertNotificationsEqual(Notification expected, Notification actual)
 {
     Assert.Equal(expected.Content, actual.Content);
     Assert.Equal(expected.ContentType, actual.ContentType);
     Assert.Equal(expected.WithAttachments, actual.WithAttachments);
     Assert.Equal(expected.RecipientsList, actual.RecipientsList);
 }
Пример #3
0
        public void DeleteOlderThanAsync_MultipleOlderNotifications_ReturnsRemovedCount()
        {
            var notification = new Notification();

            var(context, notificationService) = CreateTestTools(
                nameof(DeleteOlderThanAsync_MultipleOlderNotifications_ReturnsRemovedCount)
                );

            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            NotificationDataManager.CreateNotification(context, notification, NotificationType.SEND_GRID);

            var timeSpan = TimeSpan.FromSeconds(10);

            foreach (var not in context.Notifications)
            {
                not.CreationTime = DateTime.Now - timeSpan;
            }

            context.SaveChanges();

            int deletedCount = notificationService.DeleteOlderThanAsync(DateTime.Now).Result;

            Assert.Equal(3, deletedCount);
        }
Пример #4
0
        public void DeleteAsync_ExistingNotification_RemovesNotificationFromDatabase()
        {
            var(context, notificationService) = CreateTestTools(
                nameof(DeleteAsync_ExistingNotification_RemovesNotificationFromDatabase)
                );

            var testUser     = UserDataManager.CreateTestUser(context);
            var notification = new Notification()
            {
                Content        = "Test message",
                ContentType    = "text/plain",
                RecipientsList = new List <string> {
                    testUser.Email
                }
            };

            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            notification = new Notification(context.Notifications.First());

            var task = notificationService.DeleteAsync(notification);

            task.Wait();

            Assert.Null(context.Notifications.Find(notification.Id));
        }
Пример #5
0
 private static void AssertNotificationsEqual(Notification expected, Database.POCO.Notification actual)
 {
     Assert.Equal(expected.Content, actual.Content);
     Assert.Equal(expected.ContentType, actual.ContentType);
     Assert.Equal(expected.WithAttachments, actual.WithAttachments);
     foreach (var user in actual.RecipientsList)
     {
         Assert.Contains(user.Email, expected.RecipientsList);
     }
 }
Пример #6
0
        public void GetAll_MultipleNotificationsDifferentTypes_ReturnsAllOfGivenTypeOnly()
        {
            var n1 = new Notification()
            {
                Content        = "Message1", ContentType = "text/plain",
                RecipientsList = new List <string> {
                    "*****@*****.**"
                }
            };
            var n2 = new Notification()
            {
                Content        = "Message2", ContentType = "text/plain",
                RecipientsList = new List <string> {
                    "*****@*****.**"
                }
            };
            var n3 = new Notification()
            {
                Content        = "Message3", ContentType = "text/plain",
                RecipientsList = new List <string> {
                    "*****@*****.**"
                }
            };
            var n4 = new Notification()
            {
                Content        = "Message4", ContentType = "text/plain",
                RecipientsList = new List <string> {
                    "*****@*****.**"
                }
            };

            var(context, notificationService) = CreateTestTools(
                nameof(GetAll_MultipleNotificationsDifferentTypes_ReturnsAllOfGivenTypeOnly)
                );
            NotificationDataManager.CreateNotification(context, n1, NotificationType.API);
            NotificationDataManager.CreateNotification(context, n2, NotificationType.API);
            NotificationDataManager.CreateNotification(context, n3, NotificationType.SEND_GRID);
            NotificationDataManager.CreateNotification(context, n4, NotificationType.SEND_GRID);

            var allNotifications = notificationService.GetAll(NotificationType.API).ToList();

            Assert.NotEmpty(allNotifications.Where(n => n.Content.Contains("1")));
            Assert.NotEmpty(allNotifications.Where(n => n.Content.Contains("2")));
            Assert.Empty(allNotifications.Where(n => n.Content.Contains("3")));
            Assert.Empty(allNotifications.Where(n => n.Content.Contains("4")));
        }
Пример #7
0
        public void AddAsync_NewNotification_ReturnsAddedNotification()
        {
            var(context, notificationService) = CreateTestTools(
                nameof(AddAsync_NewNotification_ReturnsAddedNotification)
                );

            var testUser     = UserDataManager.CreateTestUser(context);
            var notification = new Notification()
            {
                Content        = "Test message",
                ContentType    = "text/plain",
                RecipientsList = new List <string> {
                    testUser.Email
                }
            };

            var added = notificationService.AddAsync(notification, NotificationType.API).Result;

            AssertNotificationsEqual(notification, added);
        }
Пример #8
0
        public void AddAsync_NewNotification_AddsNotificationToDatabase()
        {
            var(context, notificationService) = CreateTestTools(
                nameof(AddAsync_NewNotification_AddsNotificationToDatabase)
                );

            var testUser     = UserDataManager.CreateTestUser(context);
            var notification = new Notification()
            {
                Content        = "Test message",
                ContentType    = "text/plain",
                RecipientsList = new List <string> {
                    testUser.Email
                }
            };

            var id     = notificationService.AddAsync(notification, NotificationType.API).Result.Id;
            var entity = context.Notifications.Find(id);

            AssertNotificationsEqual(notification, entity);
        }
Пример #9
0
        public void DeleteAsync_ExistingNotification_ReturnsDeletedNotification()
        {
            var(context, notificationService) = CreateTestTools(
                nameof(DeleteAsync_ExistingNotification_ReturnsDeletedNotification)
                );

            var testUser     = UserDataManager.CreateTestUser(context);
            var notification = new Notification()
            {
                Content        = "Test message",
                ContentType    = "text/plain",
                RecipientsList = new List <string> {
                    testUser.Email
                }
            };

            NotificationDataManager.CreateNotification(context, notification, NotificationType.API);
            notification = new Notification(context.Notifications.First());

            var deleted = notificationService.DeleteAsync(notification).Result;

            AssertNotificationsEqual(notification, deleted);
        }