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); } }
public void SendNotifications_SendAlwaysSucceeds_RemovesAllFromDatabase() { var(context, notificationService) = CreateTestTools( nameof(SendNotifications_SendAlwaysSucceeds_RemovesAllFromDatabase) ); NotificationDataManager.CreateNotification( context, new Notification() { Content = "Message1", ContentType = "text/plain" } ); NotificationDataManager.CreateNotification( context, new Notification() { Content = "Message2", ContentType = "text/plain" } ); var notifyService = new MockRetryNotifyService(notificationService, true, TimeSpan.FromMinutes(1)); notifyService.SendNotifications(new List <Notification>()); Assert.Empty(context.Notifications); }
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); }
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)); }
public bool SaveMeetingNotification(Int32 Id, string MeetingDate, string CreatedBy) { bool result = false; NotificationDataManager objDM = new NotificationDataManager(); result = objDM.SaveMeetingNotification(Id, MeetingDate, CreatedBy); return(result); }
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"))); }
public void SendNotifications_OneOlderThanMinuteInDatabase_RemovesAllFromDatabase() { var(context, notificationService) = CreateTestTools( nameof(SendNotifications_OneOlderThanMinuteInDatabase_RemovesAllFromDatabase) ); NotificationDataManager.CreateNotification(context, new Notification() { Content = "Message1", ContentType = "text/plain" }, DateTime.Now - TimeSpan.FromMinutes(2) ); var notifyService = new MockRetryNotifyService(notificationService, false, TimeSpan.FromMinutes(1)); notifyService.SendNotifications(new List <Notification>()); Assert.Empty(context.Notifications); }
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); }