public WasteRecoveryBlock(IList<MergeField> mergeFields, NotificationApplication notification, WasteRecovery wasteRecovery, WasteDisposal wasteDisposal)
        {
            AnnexMergeFields = MergeFieldLocator.GetAnnexMergeFields(mergeFields, TypeName);

            CorrespondingMergeFields = MergeFieldLocator.GetCorrespondingFieldsForBlock(mergeFields, TypeName);
            data = new WasteRecoveryViewModel(notification, wasteRecovery, wasteDisposal, new WasteRecoveryFormatter());
            
            if (notification.NotificationType == NotificationType.Disposal)
            {
                HasAnnex = false;

                MergeMainDocumentBlock();
            }
            else
            {
                HasAnnex = true;

                if (notification.WasteRecoveryInformationProvidedByImporter.GetValueOrDefault())
                {
                    HasAnnex = false;

                    MergeMainDocumentBlock();
                }
            }
        }
        public string CostAmountWithUnits(WasteDisposal wasteDisposal, Func<WasteDisposal, DisposalCost> disposalCost)
        {
            if (wasteDisposal == null || disposalCost(wasteDisposal) == null)
            {
                return NotApplicable;
            }

            return string.Format("£{0} per {1}", disposalCost(wasteDisposal).Amount, disposalCost(wasteDisposal).Units);
        }
        public string CostAmountWithUnits(WasteDisposal wasteDisposal, Func <WasteDisposal, DisposalCost> disposalCost)
        {
            if (wasteDisposal == null || disposalCost(wasteDisposal) == null)
            {
                return(NotApplicable);
            }

            return(string.Format("£{0} per {1}", disposalCost(wasteDisposal).Amount, disposalCost(wasteDisposal).Units));
        }
        public async Task DisposalDeleted_CallsSaveChanges()
        {
            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)));

            Assert.Equal(1, context.SaveChangesCount);
        }
Beispiel #5
0
        public async Task PercentageChangedToLessThan100_DoesNotDeleteDisposal()
        {
            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(50)));

            A.CallTo(() => repository.Delete(A <WasteDisposal> .Ignored)).MustNotHaveHappened();
        }
        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);
        }
        public async Task PercentageChangedToLessThan100_DoesNotDeleteDisposal()
        {
            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(50)));

            A.CallTo(() => repository.Delete(A<WasteDisposal>.Ignored)).MustNotHaveHappened();
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public async Task DisposalDeleted_CallsSaveChanges()
        {
            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)));

            Assert.Equal(1, context.SaveChangesCount);
        }
        public async Task IfBothDeleted_CallsSaveChanges()
        {
            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));

            Assert.Equal(1, context.SaveChangesCount);
        }
Beispiel #11
0
        public async Task IfBothDeleted_CallsSaveChanges()
        {
            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));

            Assert.Equal(1, context.SaveChangesCount);
        }
        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);
        }
Beispiel #13
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 <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 WasteRecoveryViewModel(NotificationApplication notification,
                                      WasteRecovery wasteRecovery,
                                      WasteDisposal wasteDisposal,
                                      WasteRecoveryFormatter wasteRecoveryFormatter)
        {
            if (notification == null)
            {
                return;
            }

            if (notification.WasteRecoveryInformationProvidedByImporter.GetValueOrDefault())
            {
                annexMessage = string.Empty;
                return;
            }

            if (wasteDisposal != null)
            {
                methodOfDisposal = wasteDisposal.Method ?? string.Empty;
            }

            if (wasteRecovery != null && wasteRecovery.PercentageRecoverable != null)
            {
                percentageRecoverable    = wasteRecoveryFormatter.NullableDecimalAsPercentage(wasteRecovery.PercentageRecoverable.Value);
                percentageNonRecoverable =
                    wasteRecoveryFormatter.NullableDecimalAsPercentage(100 - wasteRecovery.PercentageRecoverable.Value);
            }

            estimatedAmountText = wasteRecoveryFormatter
                                  .CostAmountWithUnits(wasteRecovery,
                                                       ri => ri.EstimatedValue);

            costAmountText = wasteRecoveryFormatter
                             .CostAmountWithUnits(wasteRecovery,
                                                  ri => ri.RecoveryCost);

            disposalAmountText = wasteRecoveryFormatter
                                 .CostAmountWithUnits(wasteDisposal,
                                                      ri => ri.Cost);

            annexMessage = string.Empty;
        }
        public WasteRecoveryViewModel(NotificationApplication notification,
            WasteRecovery wasteRecovery,
            WasteDisposal wasteDisposal,
            WasteRecoveryFormatter wasteRecoveryFormatter)
        {
            if (notification == null)
            {
                return;
            }

            if (notification.WasteRecoveryInformationProvidedByImporter.GetValueOrDefault())
            {
                annexMessage = string.Empty;
                return;
            }

            if (wasteDisposal != null)
            {
                methodOfDisposal = wasteDisposal.Method ?? string.Empty;
            }
            
            if (wasteRecovery != null && wasteRecovery.PercentageRecoverable != null)
            {
                percentageRecoverable = wasteRecoveryFormatter.NullableDecimalAsPercentage(wasteRecovery.PercentageRecoverable.Value);
                percentageNonRecoverable =
                    wasteRecoveryFormatter.NullableDecimalAsPercentage(100 - wasteRecovery.PercentageRecoverable.Value);
            }

            estimatedAmountText = wasteRecoveryFormatter
                .CostAmountWithUnits(wasteRecovery, 
                    ri => ri.EstimatedValue);

            costAmountText = wasteRecoveryFormatter
                .CostAmountWithUnits(wasteRecovery,
                    ri => ri.RecoveryCost);

            disposalAmountText = wasteRecoveryFormatter
                .CostAmountWithUnits(wasteDisposal,
                    ri => ri.Cost);

            annexMessage = string.Empty;
        }
 public static NotificationApplicationOverview Load(NotificationApplication notification,
     NotificationAssessment assessment,
     WasteRecovery.WasteRecovery wasteRecovery,
     WasteDisposal wasteDisposal,
     Exporter.Exporter exporter,
     Importer.Importer importer,
     int charge,
     NotificationApplicationCompletionProgress progress)
 {
     return new NotificationApplicationOverview
     {
         Exporter = exporter,
         Importer = importer,
         Notification = notification,
         NotificationAssessment = assessment,
         WasteRecovery = wasteRecovery,
         WasteDisposal = wasteDisposal,
         Charge = charge,
         Progress = progress
     };
 }
Beispiel #18
0
 public static NotificationApplicationOverview Load(NotificationApplication notification,
                                                    NotificationAssessment assessment,
                                                    WasteRecovery.WasteRecovery wasteRecovery,
                                                    WasteDisposal wasteDisposal,
                                                    Exporter.Exporter exporter,
                                                    Importer.Importer importer,
                                                    int charge,
                                                    NotificationApplicationCompletionProgress progress)
 {
     return(new NotificationApplicationOverview
     {
         Exporter = exporter,
         Importer = importer,
         Notification = notification,
         NotificationAssessment = assessment,
         WasteRecovery = wasteRecovery,
         WasteDisposal = wasteDisposal,
         Charge = charge,
         Progress = progress
     });
 }
Beispiel #19
0
        public WasteRecoveryBlock(IList <MergeField> mergeFields, NotificationApplication notification, WasteRecovery wasteRecovery, WasteDisposal wasteDisposal)
        {
            AnnexMergeFields = MergeFieldLocator.GetAnnexMergeFields(mergeFields, TypeName);

            CorrespondingMergeFields = MergeFieldLocator.GetCorrespondingFieldsForBlock(mergeFields, TypeName);
            data = new WasteRecoveryViewModel(notification, wasteRecovery, wasteDisposal, new WasteRecoveryFormatter());

            if (notification.NotificationType == NotificationType.Disposal)
            {
                HasAnnex = false;

                MergeMainDocumentBlock();
            }
            else
            {
                HasAnnex = true;

                if (notification.WasteRecoveryInformationProvidedByImporter.GetValueOrDefault())
                {
                    HasAnnex = false;

                    MergeMainDocumentBlock();
                }
            }
        }
 public void Delete(WasteDisposal wasteDisposal)
 {
     context.DeleteOnCommit(wasteDisposal);
 }
 public void Delete(WasteDisposal wasteDisposal)
 {
     context.DeleteOnCommit(wasteDisposal);
 }