예제 #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_WasteDisposalExists_ChangeToImporter_DeletesBoth()
        {
            var wasteRecovery = new WasteRecovery(NotificationId, null, null, null);
            var wasteDisposal = new WasteDisposal(NotificationId, "Test", null);

            A.CallTo(() => recoveryRepository.GetByNotificationId(NotificationId)).Returns(wasteRecovery);
            A.CallTo(() => disposalRepository.GetByNotificationId(NotificationId)).Returns(wasteDisposal);

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

            A.CallTo(() => recoveryRepository.Delete(wasteRecovery)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => disposalRepository.Delete(wasteDisposal)).MustHaveHappened(Repeated.Exactly.Once);
        }
        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();
            }
        }
        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();
            }
        }