Esempio n. 1
0
        public async Task <bool> HandleAsync(SaveWasteRecovery message)
        {
            var wasteRecovery = await repository.GetByNotificationId(message.NotificationId);

            var newPercentage     = new Percentage(message.PercentageRecoverable);
            var newEstimatedValue = new EstimatedValue(message.EstimatedValue.Unit, message.EstimatedValue.Amount);
            var newRecoveryCost   = new RecoveryCost(message.RecoveryCost.Unit, message.RecoveryCost.Amount);

            if (wasteRecovery == null)
            {
                wasteRecovery = new WasteRecovery(
                    message.NotificationId,
                    newPercentage,
                    newEstimatedValue,
                    newRecoveryCost);

                context.WasteRecoveries.Add(wasteRecovery);
            }
            else
            {
                wasteRecovery.Update(newPercentage, newEstimatedValue, newRecoveryCost);
            }

            await context.SaveChangesAsync();

            return(true);
        }
        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();
                }
            }
        }
Esempio n. 3
0
        public string CostAmountWithUnits(WasteRecovery wasteRecovery, Func <WasteRecovery, ValuePerWeight> valuePerWeight)
        {
            if (wasteRecovery == null)
            {
                return(NotApplicable);
            }

            return(string.Format("£{0} per {1}", valuePerWeight(wasteRecovery).Amount, valuePerWeight(wasteRecovery).Units));
        }
        private void AddWasteRecovery(Guid id)
        {
            var wasteRecovery = new WasteRecovery(id,
                                                  new Percentage(100),
                                                  new EstimatedValue(ValuePerWeightUnits.Kilogram, 10),
                                                  new RecoveryCost(ValuePerWeightUnits.Kilogram, 5));

            context.WasteRecoveries.Add(wasteRecovery);
        }
        public string CostAmountWithUnits(WasteRecovery wasteRecovery, Func<WasteRecovery, ValuePerWeight> valuePerWeight)
        {
            if (wasteRecovery == null)
            {
                return NotApplicable;
            }

            return string.Format("£{0} per {1}", valuePerWeight(wasteRecovery).Amount, valuePerWeight(wasteRecovery).Units);
        }
        public void CanAddWasteRecoveryValues()
        {
            var estimatedValue = new EstimatedValue(ValuePerWeightUnits.Kilogram, 10);
            var recoveryCost   = new RecoveryCost(ValuePerWeightUnits.Tonne, 50);

            var wasteRecovery = new WasteRecovery(Guid.NewGuid(), new Percentage(50), estimatedValue, recoveryCost);

            Assert.NotNull(wasteRecovery);
        }
        public void CanAddWasteRecoveryValues()
        {
            var estimatedValue = new EstimatedValue(ValuePerWeightUnits.Kilogram, 10);
            var recoveryCost = new RecoveryCost(ValuePerWeightUnits.Tonne, 50);

            var wasteRecovery = new WasteRecovery(Guid.NewGuid(), new Percentage(50), estimatedValue, recoveryCost);

            Assert.NotNull(wasteRecovery);
        }
Esempio n. 8
0
        public async Task IfWasteRecoveryDeleted_CallsSaveChanges()
        {
            var wasteRecovery = new WasteRecovery(NotificationId, null, null, null);

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

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

            Assert.Equal(1, context.SaveChangesCount);
        }
        public async Task IfWasteRecoveryDeleted_CallsSaveChanges()
        {
            var wasteRecovery = new WasteRecovery(NotificationId, null, null, null);

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

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

            Assert.Equal(1, context.SaveChangesCount);
        }
        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);
        }
Esempio n. 11
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);
        }
        private async Task<WasteRecovery> CreateWasteRecovery(NotificationApplication notification)
        {
            var estimatedValue = new EstimatedValue(ValuePerWeightUnits.Kilogram, 10);
            var recoveryCost = new RecoveryCost(ValuePerWeightUnits.Tonne, 50);

            var wasteRecovery = new WasteRecovery(notification.Id, new Percentage(50), estimatedValue, recoveryCost);

            context.WasteRecoveries.Add(wasteRecovery);
            await context.SaveChangesAsync();
            return wasteRecovery;
        }
Esempio n. 13
0
        private async Task <WasteRecovery> CreateWasteRecovery(NotificationApplication notification)
        {
            var estimatedValue = new EstimatedValue(ValuePerWeightUnits.Kilogram, 10);
            var recoveryCost   = new RecoveryCost(ValuePerWeightUnits.Tonne, 50);

            var wasteRecovery = new WasteRecovery(notification.Id, new Percentage(50), estimatedValue, recoveryCost);

            context.WasteRecoveries.Add(wasteRecovery);
            await context.SaveChangesAsync();

            return(wasteRecovery);
        }
        public void UpdateWasteRecovery_RaisesEvent()
        {
            var wasteRecovery = new WasteRecovery(
                Guid.NewGuid(),
                new Percentage(50m),
                new EstimatedValue(ValuePerWeightUnits.Kilogram, 50m),
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 40m));

            wasteRecovery.Update(new Percentage(60m), new EstimatedValue(ValuePerWeightUnits.Tonne, 50000m), new RecoveryCost(ValuePerWeightUnits.Tonne, 40000m));

            Assert.Equal(60m, wasteRecovery.Events.OfType <PercentageChangedEvent>().SingleOrDefault().NewPercentage.Value);
        }
        public void UpdateWasteRecovery_RaisesEvent()
        {
            var wasteRecovery = new WasteRecovery(
                Guid.NewGuid(),
                new Percentage(50m),
                new EstimatedValue(ValuePerWeightUnits.Kilogram, 50m),
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 40m));

            wasteRecovery.Update(new Percentage(60m), new EstimatedValue(ValuePerWeightUnits.Tonne, 50000m), new RecoveryCost(ValuePerWeightUnits.Tonne, 40000m));

            Assert.Equal(60m, wasteRecovery.Events.OfType<PercentageChangedEvent>().SingleOrDefault().NewPercentage.Value);
        }
        public async Task WasteRecoveryExists_ReturnsPercentage()
        {
            var wasteRecovery = new WasteRecovery(NotificationId,
                new Percentage(100m),
                new EstimatedValue(ValuePerWeightUnits.Kilogram, 5m),
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 10m));

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

            var result = await handler.HandleAsync(new GetRecoverablePercentage(NotificationId));

            Assert.Equal(100m, result);
        }
        public async Task WasteRecoveryExists_ReturnsPercentage()
        {
            var wasteRecovery = new WasteRecovery(NotificationId,
                                                  new Percentage(100m),
                                                  new EstimatedValue(ValuePerWeightUnits.Kilogram, 5m),
                                                  new RecoveryCost(ValuePerWeightUnits.Kilogram, 10m));

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

            var result = await handler.HandleAsync(new GetRecoverablePercentage(NotificationId));

            Assert.Equal(100m, result);
        }
        public async Task HasWasteRecovery_ReturnsCorrectValues()
        {
            var wasteRecovery = new WasteRecovery(NotificationId,
                new Percentage(100m),
                new EstimatedValue(ValuePerWeightUnits.Kilogram, 10m),
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 15m));

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

            var result = await handler.HandleAsync(new GetEstimatedValue(NotificationId));

            Assert.Equal(10m, result.Amount);
            Assert.Equal(ValuePerWeightUnits.Kilogram, result.Unit);
        }
Esempio n. 19
0
        public async Task HasWasteRecovery_ReturnsCorrectValues()
        {
            var wasteRecovery = new WasteRecovery(NotificationId,
                                                  new Percentage(100m),
                                                  new EstimatedValue(ValuePerWeightUnits.Kilogram, 10m),
                                                  new RecoveryCost(ValuePerWeightUnits.Kilogram, 15m));

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

            var result = await handler.HandleAsync(new GetEstimatedValue(NotificationId));

            Assert.Equal(10m, result.Amount);
            Assert.Equal(ValuePerWeightUnits.Kilogram, result.Unit);
        }
        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;
        }
Esempio n. 21
0
        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 async Task UpdatesExistingWasteRecovery()
        {
            var wasteRecovery = new WasteRecovery(
                NotificationId, 
                new Percentage(100m), 
                new EstimatedValue(ValuePerWeightUnits.Tonne, 5m), 
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 7m));

            context.WasteRecoveries.Add(wasteRecovery);
            A.CallTo(() => repository.GetByNotificationId(NotificationId)).Returns(wasteRecovery);

            await handler.HandleAsync(CreateRequest());

            var result = context.WasteRecoveries.Single(wr => wr.NotificationId == NotificationId);

            Assert.Equal(10m, result.EstimatedValue.Amount);
            Assert.Equal(ValuePerWeightUnits.Kilogram, result.EstimatedValue.Units);

            Assert.Equal(15m, result.RecoveryCost.Amount);
            Assert.Equal(ValuePerWeightUnits.Tonne, result.RecoveryCost.Units);
        }
        public async Task UpdatesExistingWasteRecovery()
        {
            var wasteRecovery = new WasteRecovery(
                NotificationId,
                new Percentage(100m),
                new EstimatedValue(ValuePerWeightUnits.Tonne, 5m),
                new RecoveryCost(ValuePerWeightUnits.Kilogram, 7m));

            context.WasteRecoveries.Add(wasteRecovery);
            A.CallTo(() => repository.GetByNotificationId(NotificationId)).Returns(wasteRecovery);

            await handler.HandleAsync(CreateRequest());

            var result = context.WasteRecoveries.Single(wr => wr.NotificationId == NotificationId);

            Assert.Equal(10m, result.EstimatedValue.Amount);
            Assert.Equal(ValuePerWeightUnits.Kilogram, result.EstimatedValue.Units);

            Assert.Equal(15m, result.RecoveryCost.Amount);
            Assert.Equal(ValuePerWeightUnits.Tonne, result.RecoveryCost.Units);
        }
 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
     };
 }
 public void Delete(WasteRecovery wasteRecovery)
 {
     context.DeleteOnCommit(wasteRecovery);
 }
Esempio n. 26
0
 public void Delete(WasteRecovery wasteRecovery)
 {
     context.DeleteOnCommit(wasteRecovery);
 }
Esempio n. 27
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();
                }
            }
        }