public async Task GenerateNotificationsAsync_With1EventFor1UsersWhoIsAttendingOtherEventsButNotThisOne_SendsOneEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); List <Event> alternateEvents = GetEventList1(); alternateEvents[0].Id = new Guid(); EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); // The user is attending all available events EventAttendeeRepository.Setup(ea => ea.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())).ReturnsAsync(alternateEvents); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Once); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Once); EventAttendeeRepository.Verify(_ => _.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Once); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task Create_ReturnsNewNotification() { string usersJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"Users.json"); var user = JsonConvert.DeserializeObject <List <User> >(usersJson).First(u => u.Id == TESTING_USER_ID); const string title = "Test title"; const string content = "Test content"; var userNotification = new UserNotification { Title = title, Content = content, IsRead = false }; UserRepository.Setup(u => u.GetByKey(TESTING_USER_ID)).Returns(user); UserNotificationRepository.Setup(n => n.Create(userNotification)).ReturnsAsync(userNotification); var resultUserNotification = await UserNotificationService.Create(userNotification); Assert.NotNull(resultUserNotification); Assert.NotNull(resultUserNotification.User); Assert.Equal(title, resultUserNotification.Title); Assert.Equal(content, resultUserNotification.Content); Assert.Equal(DateTime.Today, resultUserNotification.CreatedDate); Assert.False(resultUserNotification.IsRead); }
public async Task GenerateNotificationsAsync_With1EventFor1UsersWhereEventIsOutsideOfTravelPreference_SendsNoEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); events[0].EventDate = DateTimeOffset.UtcNow.AddDays(3); EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); // Setup a return of distance between User and Event of 50 (in whatever units) MapRepository.Setup(mr => mr.GetDistanceBetweenTwoPoints(It.IsAny <Tuple <double, double> >(), It.IsAny <Tuple <double, double> >(), It.IsAny <bool>())).ReturnsAsync(50); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Once); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Once); EventAttendeeRepository.Verify(_ => _.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public void TestInitialize() { _mockUserNotification = new Mock <DbSet <UserNotification> >(); _mockContext = new Mock <IApplicationDbContext>(); _repository = new UserNotificationRepository(_mockContext.Object); }
public async Task GenerateNotificationsAsync_With1EventFor1UsersWhereEventIsMoreThanRequiredHoursAway_SendsNoEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); // The user is attending all available events EventAttendeeRepository.Setup(ea => ea.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())).ReturnsAsync(events); events[0].EventDate = DateTimeOffset.UtcNow.AddDays(NumberOfDaysToAddForEventOutOfWindow); EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Once); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Once); EventAttendeeRepository.Verify(_ => _.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public UserNotificationController() { _context = new SportboardDbContext(); _unitOfWork = new UnitOfWork(_context); _userNotificationRepository = new UserNotificationRepository(_context); _bLLUserNotif = new BLLUserNotifications(_unitOfWork, _userNotificationRepository); }
public async Task GenerateNotificationsAsync_With1EventFor1UsersWhoHasOptedOutOfAllEmails_SendsNoEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); events[0].CreatedByUserId = users[0].Id; users[0].IsOptedOutOfAllEmails = true; // The user is attending all available events EventAttendeeRepository.Setup(ea => ea.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())).ReturnsAsync(events); EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Never); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Never); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public async Task GenerateNotificationsAsync_With1EventFor1UsersWhoHasOptedOutOfThisEmail_SendsNoEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); List <UserNotificationPreference> userNotificationPreferences = GetUserNotificationPreferences(); var unIndex = userNotificationPreferences.FindIndex(unp => unp.UserNotificationTypeId == (int)NotificationType); userNotificationPreferences[unIndex].IsOptedOut = true; EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); UserNotificationPreferenceRepository.Setup(unp => unp.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(userNotificationPreferences); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Never); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Once); EventAttendeeRepository.Verify(_ => _.GetEventsUserIsAttending(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Never); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public async Task Update_ReturnsUpdatedNotification() { string userNotificationsJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"UserNotifications.json"); var notification = JsonConvert.DeserializeObject <List <UserNotification> >(userNotificationsJson).First(u => u.User.Id == TESTING_USER_ID); const string newTitle = "Test title"; const string newContent = "Test content"; var userNotification = new UserNotification { Id = notification.Id, Title = newTitle, Content = newContent, IsRead = true }; UserNotificationRepository.Setup(u => u.GetByKey(userNotification.Id)).Returns(notification); UserNotificationRepository.Setup(n => n.Update(notification)).ReturnsAsync(notification); var resultUserNotification = await UserNotificationService.Update(userNotification); Assert.NotNull(resultUserNotification); Assert.Equal(newTitle, resultUserNotification.Title); Assert.Equal(newContent, resultUserNotification.Content); Assert.Equal(notification.CreatedDate, resultUserNotification.CreatedDate); Assert.True(resultUserNotification.IsRead); }
protected async Task <bool> UserHasAlreadyReceivedNotification(User user, Event mobEvent) { // Get list of notification events user has already received for the event var notifications = await UserNotificationRepository.GetUserNotifications(user.Id, mobEvent.Id).ConfigureAwait(false); // Verify that the user has not already received this type of notification for this event return(notifications.Any(un => un.UserNotificationTypeId == (int)NotificationType)); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Gigs = new GigRepository(_context); Genres = new GenreRepository(_context); Attendances = new AttendanceRepository(_context); Followings = new FollowingsRepository(_context); Notifications = new UserNotificationRepository(_context); }
public void SetNotificationForMultipleUsers(string message, int[] userIds, bool json) { using (var db = new GazDbContext()) { var repo = new UserNotificationRepository(db); repo.AddNotificationForMultipleUsers(userIds, message); repo.Commit(); } }
public void Initialize() { _user = new ApplicationUser(); _venue = "Blue Stage Live"; _userNotifications = new Mock <DbSet <UserNotification> >(); _context = new Mock <IApplicationDbContext>(); _context.SetupGet(c => c.UserNotifications).Returns(_userNotifications.Object); _repository = new UserNotificationRepository(_context.Object); }
public void InitializeNotificationRepository() { _mockUserNotifications = new Mock <DbSet <UserNotification> >(); var mockContext = new Mock <IApplicationDbContext>(); mockContext.SetupGet(r => r.UserNotifications).Returns(_mockUserNotifications.Object); _userNotificationRepository = new UserNotificationRepository(mockContext.Object); }
public ShareService() { _systemConfigRepository = new SystemConfigRepository(); _systemConfigDepartmentRepository = new SystemConfigDepartmentRepository(); _departmentRepository = new DepartmentRepository(); _loginHistoryRepository = new LoginHistoryRepository(); _applicationLoggingRepository = new ApplicationLoggingRepository(); _userNotificationRepository = new UserNotificationRepository(); _notificationCenterRepository = new NotificationCenterRepository(); }
public UnitOfWorkEf(ApplicationDbContext context) { this.context = context; Gigs = new GigEfRepository(context); Attendances = new AttendanceEfRepository(context); Follows = new FollowEfRepository(context); Genres = new GenreEfRepository(context); Notifications = new NotificationEfRepository(context); UserNotifications = new UserNotificationEfRepository(context); }
public UnitOfWork(ApplicationDbContext context) { _context = context; UserAvailability = new UserAvailabilityRepository(context); Appointment = new AppointmentRepository(context); AppointmentType = new AppointmentTypeRepository(context); Notifications = new NotificationRepository(context); UserNotifications = new UserNotificationRepository(context); ApplicationUsers = new ApplicationUserRepository(context); }
public void SetUp() { _mockUserNotifications = new Mock <DbSet <UserNotification> >(); var mockContext = new Mock <IApplicationDbContext>(); mockContext.SetupGet(c => c.UserNotifications).Returns(_mockUserNotifications.Object); _repository = new UserNotificationRepository(mockContext.Object); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Projects = new ProjectRepository(_context); ProjectNominations = new ProjectNominationRepository(_context); Hourages = new HourageRepository(_context); Notifications = new NotificationRepository(_context); UserNotifications = new UserNotificationRepository(_context); UserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(_context)); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Tournaments = new TournamentRepository(context); Participations = new ParticipationRepository(context); Games = new GameRepository(context); Notifications = new NotificationRepository(context); UserNotifications = new UserNotificationRepository(context); CreditCards = new CreditCardRepository(context); }
public async Task GenerateNotificationsAsync_WithNoDataAvailable_Succeeds() { // Arrange // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Gigs = new GigRepository(_context); Attendances = new AttendanceRepository(_context); Genres = new GenreRepository(_context); Relationships = new RelationshipRepository(_context); Users = new UserRepository(_context); UserNotifications = new UserNotificationRepository(_context); Notification = new NotificationRepository(_context); }
public UnitOfWork(SportboardDbContext context) { _context = context; Feeds = new FeedRepository(_context); Comments = new CommentRepository(_context); Images = new ImageRepository(_context); Posts = new PostRepository(_context); Users = new UserRepository(_context); UserPreferences = new UserPreferenceRepository(_context); DeletionRequests = new DeletionRequestRepository(_context); UserNotifications = new UserNotificationRepository(_context); }
// public IUserDescriptionRepository UserDescriptions { get; } public UnitOfWork(ApplicationDbContext context) { _context = context; Gigs = new GigRepository(_context); Attendances = new AttendanceRepository(_context); Followings = new FollowingRepository(_context); Genres = new GenreRepository(_context); UserNotifications = new UserNotificationRepository(_context); Users = new UserRepository(_context); Roles = new RoleRepository(_context); Logins = new LoginRepository(_context); // UserDescriptions = new UserDescriptionRepository(_context); }
public void GetUnreadCount_ReturnsCount() { string userNotificationsJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"UserNotifications.json"); var notifications = JsonConvert.DeserializeObject <List <UserNotification> >(userNotificationsJson) .Where(n => n.User.Id == TESTING_USER_ID && !n.IsRead); UserNotificationRepository.Setup(n => n.GetUnread()).Returns(notifications); int unreadNotificationsCount = UserNotificationService.GetUnreadCount(); Assert.Equal(notifications.Count(), unreadNotificationsCount); }
public void Create_DataCorrect_NotificationCreated() { var user = UserFaker.Create(); var title = "test title"; var content = "content here"; var notification = UserNotificationRepository.Create(user, title, content, UserNotificationType.Warning); Assert.NotNull(notification); Assert.AreEqual(title, notification.title); Assert.AreEqual(content, notification.content); Assert.AreEqual(UserNotificationType.Warning, notification.type); }
protected async Task <int> SendNotifications(User user, IEnumerable <Event> eventsToNotifyUserFor, CancellationToken cancellationToken) { // Populate email if (eventsToNotifyUserFor.Any()) { // Update the database first so that a user is not notified multiple times foreach (var mobEvent in eventsToNotifyUserFor) { var userNotification = new UserNotification { Id = Guid.NewGuid(), EventId = mobEvent.Id, UserId = user.Id, SentDate = DateTimeOffset.UtcNow, UserNotificationTypeId = (int)NotificationType, }; await UserNotificationRepository.AddUserNotification(userNotification).ConfigureAwait(false); } var emailTemplate = GetEmailTemplate(); var content = await PopulateTemplate(emailTemplate, user, eventsToNotifyUserFor).ConfigureAwait(false); var htmlEmailTemplate = GetHtmlEmailTemplate(); var htmlContent = await PopulateTemplate(htmlEmailTemplate, user, eventsToNotifyUserFor).ConfigureAwait(false); var email = new Email(); email.Addresses.Add(new EmailAddress() { Email = user.Email, Name = $"{user.GivenName} {user.SurName}" }); email.Subject = EmailSubject; email.Message = content; email.HtmlMessage = htmlContent; Logger.LogInformation("Sending email to {0}, Subject {0}", email.Addresses[0].Email, email.Subject); // send email await EmailSender.SendEmailAsync(email, cancellationToken).ConfigureAwait(false); return(1); } return(0); }
public UnitOfWork(ApplicationDbContext context) { _context = context; MarketEntries = new MarketEntryRepository(context); FinalProducts = new FinalProductRepository(context); Auctions = new AuctionRepository(context); Storages = new StorageRepository(context); Locations = new LocationRepository(context); Products = new ProductRepository(context); ProductCategories = new ProductCategoryRepository(context); Roles = new RoleRepository(context); ProductQualities = new ProductQualityRepository(context); UserNotifications = new UserNotificationRepository(context); Notifications = new NotificationRepository(context); Users = new UserRepository(context); ContactForms = new ContactFormRepository(context); TradeMatches = new TradeMatchRepository(context); }
public async Task Delete_ReturnsDeletedNotification() { string userNotificationsJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"UserNotifications.json"); var notification = JsonConvert.DeserializeObject <List <UserNotification> >(userNotificationsJson).First(u => u.User.Id == TESTING_USER_ID); UserNotificationRepository.Setup(u => u.GetByKey(notification.Id)).Returns(notification); UserNotificationRepository.Setup(n => n.Delete(notification.Id)).ReturnsAsync(notification); var resultUserNotification = await UserNotificationService.Delete(notification.Id); Assert.NotNull(resultUserNotification); Assert.Equal(notification.Title, resultUserNotification.Title); Assert.Equal(notification.Content, resultUserNotification.Content); Assert.Equal(notification.IsRead, resultUserNotification.IsRead); Assert.Equal(notification.CreatedDate, resultUserNotification.CreatedDate); }
public async Task GenerateNotificationsAsync_With1EventFor1UsersWhoIsNotHost_SendsNoEmail() { // Arrange List <Event> events = GetEventList1(); List <User> users = GetUserList1(); EventRepository.Setup(e => e.GetActiveEvents(It.IsAny <CancellationToken>())).ReturnsAsync(events); UserRepository.Setup(u => u.GetAllUsers(It.IsAny <CancellationToken>())).ReturnsAsync(users); // Act await Engine.GenerateNotificationsAsync().ConfigureAwait(false); // Assert UserRepository.Verify(_ => _.GetAllUsers(It.IsAny <CancellationToken>()), Times.Once); UserNotificationPreferenceRepository.Verify(_ => _.GetUserNotificationPreferences(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Once); EventRepository.Verify(_ => _.GetActiveEvents(It.IsAny <CancellationToken>()), Times.Once); UserNotificationRepository.Verify(_ => _.AddUserNotification(It.IsAny <UserNotification>()), Times.Never); EmailSender.Verify(_ => _.SendEmailAsync(It.IsAny <Email>(), It.IsAny <CancellationToken>()), Times.Never); }
public void Get_DataCorrect_GotNotifications() { var user = UserFaker.Create(); var title = "test title"; var content = "content here"; Assert.Zero(UserNotificationRepository.Get(user).Length); UserNotificationRepository.Create(user, title, content, UserNotificationType.Warning); var notifications = UserNotificationRepository.Get(user); Assert.AreEqual(1, notifications.Length); Assert.AreEqual(title, notifications[0].title); Assert.AreEqual(content, notifications[0].content); }