Example #1
0
        public async Task <IList <NotificationApplicationCopyData> > HandleAsync(GetNotificationsToCopyForUser message)
        {
            var notification = await context.GetNotificationApplication(message.DestinationNotificationId);

            var notificationData = await context.NotificationApplications
                                   .Join(context.Exporters, n => n.Id, e => e.NotificationId, (n, e) => new { Notification = n, Exporter = e })
                                   .Join(context.Importers, x => x.Notification.Id, i => i.NotificationId, (x, i) => new { Notification = x.Notification, Exporter = x.Exporter, Importer = i })
                                   .Where(x => x.Notification.UserId == userContext.UserId &&
                                          x.Notification.NotificationType == notification.NotificationType &&
                                          x.Notification.WasteType != null &&
                                          x.Notification.CompetentAuthority == notification.CompetentAuthority)
                                   .Select(x => new
            {
                id       = x.Notification.Id,
                number   = x.Notification.NotificationNumber,
                exporter = x.Exporter.Business.Name,
                importer = x.Importer.Business.Name,
                waste    = x.Notification.WasteType
            }).ToArrayAsync();

            return(notificationData.Select(n => new NotificationApplicationCopyData
            {
                Id = n.id,
                Number = n.number,
                ExporterName = n.exporter,
                ImporterName = n.importer,
                WasteName = n.waste.ChemicalCompositionType == ChemicalComposition.Other ?
                            n.waste.ChemicalCompositionName : EnumHelper.GetShortName(n.waste.ChemicalCompositionType)
            }).OrderBy(x => x.Number).ToArray());
        }
        public async Task UserHasNotifications_ReturnsNotificationsOfSameType()
        {
            var request = new GetNotificationsToCopyForUser(DestinationNotificationId);

            userContext.ReturnsId = UserWithNotificationsId;

            var result = await handler.HandleAsync(request);

            Assert.Equal(2, result.Count);
        }
        public async Task UserHasNoNotification_ReturnsEmptyList()
        {
            var request = new GetNotificationsToCopyForUser(DestinationNotificationId2);

            userContext.ReturnsId = UserWithoutNotificationsId;

            var result = await handler.HandleAsync(request);

            Assert.Empty(result);
        }
        public async Task UserHasNotifications_ReturnsNotificationsOfSameType()
        {
            var request = new GetNotificationsToCopyForUser(DestinationNotificationId);
            userContext.ReturnsId = UserWithNotificationsId;

            var result = await handler.HandleAsync(request);

            Assert.Equal(2, result.Count);
        }
        public async Task UserHasNoNotification_ReturnsEmptyList()
        {
            var request = new GetNotificationsToCopyForUser(DestinationNotificationId2);
            userContext.ReturnsId = UserWithoutNotificationsId;

            var result = await handler.HandleAsync(request);

            Assert.Empty(result);
        }