Пример #1
0
        public async Task PercentageChangedTo100_DeletesDisposal()
        {
            var wasteDisposal = new WasteDisposal(NotificationId, "Test", new DisposalCost(ValuePerWeightUnits.Kilogram, 10m));

            A.CallTo(() => repository.GetByNotificationId(NotificationId)).Returns(wasteDisposal);

            await handler.HandleAsync(new PercentageChangedEvent(NotificationId, new Percentage(100)));

            A.CallTo(() => repository.Delete(wasteDisposal)).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #2
0
        public async Task WasteRecoveryExists_WasteDisposalNull_ChangeToImporter_DeletesWasteRecovery()
        {
            var wasteRecovery = new WasteRecovery(NotificationId, null, null, null);

            A.CallTo(() => recoveryRepository.GetByNotificationId(NotificationId)).Returns(wasteRecovery);
            A.CallTo(() => disposalRepository.GetByNotificationId(NotificationId)).Returns <WasteDisposal>(null);

            await handler.HandleAsync(new ProviderChangedEvent(NotificationId, ProvidedBy.Importer));

            A.CallTo(() => recoveryRepository.Delete(wasteRecovery)).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #3
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetById(notificationId);

            var wasteRecovery = await wasteRecoveryRepository.GetByNotificationId(notificationId);

            var wasteDisposal = await wasteDisposalRepository.GetByNotificationId(notificationId);

            return(new WasteRecoveryBlock(mergeFields, notification, wasteRecovery, wasteDisposal));
        }
Пример #4
0
        public async Task <ValuePerWeightData> HandleAsync(GetDisposalCost message)
        {
            var disposalInfo = await wasteDisposalRepository.GetByNotificationId(message.NotificationId);

            if (disposalInfo != null)
            {
                return(wasteDisposalDataMap.Map(disposalInfo.Cost));
            }

            return(null);
        }
        public async Task HandleAsync(PercentageChangedEvent @event)
        {
            if (@event.NewPercentage.Value == 100)
            {
                var wasteDisposal = await repository.GetByNotificationId(@event.NotificationId);

                if (wasteDisposal != null)
                {
                    repository.Delete(wasteDisposal);
                }

                await context.SaveChangesAsync();
            }
        }
Пример #6
0
        public async Task <Guid> HandleAsync(SetWasteDisposal message)
        {
            var wasteDisposal = await repository.GetByNotificationId(message.NotificationId);

            if (wasteDisposal == null)
            {
                wasteDisposal = new WasteDisposal(message.NotificationId, message.Method, new DisposalCost(message.Unit, message.Amount));
                context.WasteDisposals.Add(wasteDisposal);
            }
            else
            {
                wasteDisposal.UpdateWasteDisposal(message.Method, new DisposalCost(message.Unit, message.Amount));
            }

            await context.SaveChangesAsync();

            return(message.NotificationId);
        }
        public async Task HandleAsync(ProviderChangedEvent @event)
        {
            if (@event.NewProvider == ProvidedBy.Importer)
            {
                var wasteRecovery = await recoveryRepository.GetByNotificationId(@event.NotificationId);

                var wasteDisposal = await disposalRepository.GetByNotificationId(@event.NotificationId);

                if (wasteRecovery != null)
                {
                    recoveryRepository.Delete(wasteRecovery);
                }

                if (wasteDisposal != null)
                {
                    disposalRepository.Delete(wasteDisposal);
                }

                await context.SaveChangesAsync();
            }
        }
Пример #8
0
        public async Task <string> HandleAsync(GetDisposalMethod message)
        {
            var disposalInfo = await wasteDisposalRepository.GetByNotificationId(message.NotificationId);

            return(disposalInfo == null ? string.Empty : disposalInfo.Method ?? string.Empty);
        }