public async Task RemoveNotifications(IEnumerable <Guid> notificationIds)
        {
            await using var db = new NotificationsApiDbContext(_dbContextOptions);
            var notifications = await db.Notifications.Where(x => notificationIds.Contains(x.Id)).ToListAsync();

            db.RemoveRange(notifications);
            await db.SaveChangesAsync();
        }
        public async Task RemoveNotification(Guid notificationId)
        {
            await using var db = new NotificationsApiDbContext(_dbContextOptions);
            var notification = await db.Notifications.SingleAsync(x => x.Id == notificationId);

            db.Remove(notification);
            await db.SaveChangesAsync();
        }
        public async Task <Notification> SeedNotification(Notification notification)
        {
            await using var db = new NotificationsApiDbContext(_dbContextOptions);
            await db.Notifications.AddAsync(notification);

            await db.SaveChangesAsync();

            return(notification);
        }
        public async Task Should_Update_Delivery_Status_To_Created()
        {
            var notification = await TestDataManager.SeedSendingNotification();

            _notifications.Add(notification);
            const DeliveryStatus expectedDeliveryStatus = DeliveryStatus.Created;
            var command = new UpdateNotificationSentCommand(notification.Id, notification.ExternalId, notification.Payload);

            await _handler.Handle(command);

            await using var db = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
            var updatedNotification = await db.Notifications.SingleOrDefaultAsync(x => x.Id == notification.Id);

            updatedNotification.Should().NotBeNull();
            updatedNotification.DeliveryStatus.Should().Be(expectedDeliveryStatus);
        }
        public async Task should_update_delivery_status_for_notification()
        {
            // Arrange
            var notification = await TestDataManager.SeedSendingNotification();

            _notifications.Add(notification);
            const DeliveryStatus deliveryStatus = DeliveryStatus.Delivered;
            var command = new UpdateNotificationDeliveryStatusCommand(notification.Id, notification.ExternalId, deliveryStatus);

            // Act
            await _handler.Handle(command);

            // Assert
            await using var db = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
            var updatedNotification = await db.Notifications.SingleOrDefaultAsync(x => x.Id == notification.Id);

            updatedNotification.Should().NotBeNull();
            updatedNotification.DeliveryStatus.Should().Be(deliveryStatus);
        }
        public async Task Should_Assign_ExternalId_And_Payload()
        {
            var notification = await TestDataManager.SeedSendingNotification();

            _notifications.Add(notification);
            const string expectedExternalId = "1234";
            const string expectedPayload    = "payload";

            notification.AssignExternalId(expectedExternalId);
            notification.AssignPayload(expectedPayload);
            var command = new UpdateNotificationSentCommand(notification.Id, notification.ExternalId, notification.Payload);

            await _handler.Handle(command);

            await using var db = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
            var updatedNotification = await db.Notifications.SingleOrDefaultAsync(x => x.Id == notification.Id);

            updatedNotification.Payload.Should().Be(expectedPayload);
            updatedNotification.ExternalId.Should().Be(expectedExternalId);
        }
示例#7
0
        public async Task Should_save_new_notification()
        {
            // Arrange
            var          notificationType = NotificationType.CreateIndividual;
            const string email            = "*****@*****.**";
            var          participantId    = Guid.NewGuid();
            var          hearingId        = Guid.NewGuid();
            var          command          = new CreateEmailNotificationCommand(notificationType, email, participantId, hearingId);

            // Act
            await _handler.Handle(command);

            // Assert
            await using var db = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
            var notification = await db.Notifications.SingleOrDefaultAsync(x => x.Id == command.NotificationId);

            notification.Should().NotBeNull();
            command.NotificationId.Should().NotBeEmpty();
            _notificationId = command.NotificationId;
        }
        public void OneTimeSetup()
        {
            var configRootBuilder = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .AddEnvironmentVariables()
                                    .AddUserSecrets <Startup>();

            var configRoot = configRootBuilder.Build();

            _databaseConnectionString = configRoot.GetConnectionString("VhNotificationsApi");

            var dbContextOptionsBuilder = new DbContextOptionsBuilder <NotificationsApiDbContext>();

            dbContextOptionsBuilder.UseSqlServer(_databaseConnectionString);
            NotifyBookingsDbContextOptions = dbContextOptionsBuilder.Options;

            var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);

            context.Database.Migrate();

            TestDataManager = new TestDataManager(NotifyBookingsDbContextOptions);
        }
示例#9
0
 public void Setup()
 {
     var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
     _handler = new GetTemplateByNotificationTypeQueryHandler(context);
 }
示例#10
0
 public CreateEmailNotificationCommandHandler(NotificationsApiDbContext notificationsApiDbContext)
 {
     _notificationsApiDbContext = notificationsApiDbContext;
 }
 public UpdateNotificationDeliveryStatusCommandHandler(NotificationsApiDbContext notificationsApiDbContext)
 {
     _notificationsApiDbContext = notificationsApiDbContext;
 }
示例#12
0
        public void SetUp()
        {
            var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);

            _handler = new CreateEmailNotificationCommandHandler(context);
        }
 public UpdateNotificationSentCommandHandler(NotificationsApiDbContext notificationsApiDbContext)
 {
     _notificationsApiDbContext = notificationsApiDbContext;
 }
示例#14
0
 public DbHealthCheckQueryHandler(NotificationsApiDbContext context)
 {
     _context = context;
 }
        public void Setup()
        {
            var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);

            _handler = new UpdateNotificationDeliveryStatusCommandHandler(context);
        }
        public void Setup()
        {
            var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);

            _handler = new DbHealthCheckQueryHandler(context);
        }
 public GetTemplateByNotificationTypeQueryHandler(NotificationsApiDbContext notificationsApiDbContext)
 {
     _notificationsApiDbContext = notificationsApiDbContext;
 }
        public void SetUp()
        {
            var context = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);

            _handler = new UpdateNotificationSentCommandHandler(context);
        }