Exemple #1
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);
        }
        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();
            }
        }