private async Task <ProcessDigitalSupportsResponse> HandleInternal(ProcessDigitalSupportsRequest r)
        {
            if (r.FileId == null)
            {
                throw new ArgumentNullException(nameof(r.FileId));
            }
            if (r.RequestingUserId == null)
            {
                throw new ArgumentNullException(nameof(r.RequestingUserId));
            }

            var supports = mapper.Map <IEnumerable <Support> >(r.Supports);

            var processedSupports = ((CreateNewSupportsCommandResult)await supportRepository.Manage(new CreateNewSupportsCommand
            {
                FileId = r.FileId,
                Supports = supports
            })).Supports.ToArray();

            try
            {
                var printRequestId = await printRequestsRepository.Manage(new SavePrintRequest
                {
                    PrintRequest = new ReferralPrintRequest
                    {
                        FileId           = r.FileId,
                        SupportIds       = processedSupports.Select(s => s.Id).ToArray(),
                        IncludeSummary   = r.IncludeSummaryInReferralsPrintout,
                        RequestingUserId = r.RequestingUserId,
                        Type             = ReferralPrintType.New,
                        Comments         = "Process supports"
                    }
                });

                return(new ProcessDigitalSupportsResponse
                {
                    Supports = mapper.Map <IEnumerable <Shared.Contracts.Events.Support> >(processedSupports),
                    PrintRequestId = printRequestId
                });
            }
            catch (Exception)
            {
                await supportRepository.Manage(new ChangeSupportStatusCommand
                {
                    Items = processedSupports.Select(s => SupportStatusTransition.VoidSupport(s.Id, SupportVoidReason.ErrorOnPrintedReferral)).ToArray()
                });

                throw;
            }
        }
        private async Task <ProcessPaperSupportsResponse> HandleInternal(ProcessPaperSupportsRequest r)
        {
            var supports = mapper.Map <IEnumerable <Support> >(r.Supports);

            var procesedSupports = ((CreateNewSupportsCommandResult)await supportRepository.Manage(new CreateNewSupportsCommand
            {
                FileId = r.FileId,
                Supports = supports
            })).Supports.ToArray();

            return(new ProcessPaperSupportsResponse {
                Supports = mapper.Map <IEnumerable <Shared.Contracts.Events.Support> >(procesedSupports)
            });
        }
Exemple #3
0
        public async Task CanCreateSupports()
        {
            var now = DateTime.UtcNow;

            now = new DateTime(now.Ticks - (now.Ticks % TimeSpan.TicksPerSecond), now.Kind);
            var uniqueId         = Guid.NewGuid().ToString().Substring(0, 4);
            var householdMembers = TestData.HouseholdMemberIds;
            var evacuationFileId = TestData.EvacuationFileId;

            var newSupports = new Support[]
            {
                new ClothingSupport {
                    SupportDelivery = new Referral
                    {
                        SupplierId         = TestData.SupplierAId,
                        SupplierNotes      = $"{uniqueId}-notes",
                        IssuedToPersonName = "test person",
                    },
                    CreatedByTeamMemberId    = TestData.Tier4TeamMemberId,
                    IncludedHouseholdMembers = householdMembers,
                    From     = now,
                    To       = now.AddDays(3),
                    IssuedOn = now
                },
                new IncidentalsSupport {
                    SupportDelivery = new Interac
                    {
                        NotificationEmail     = $"{TestData.TestPrefix}[email protected]",
                        NotificationMobile    = "+000-000-0000",
                        ReceivingRegistrantId = TestData.ContactId
                    },
                    TotalAmount              = 100.00m,
                    CreatedByTeamMemberId    = TestData.Tier4TeamMemberId,
                    IncludedHouseholdMembers = householdMembers,
                    From     = now,
                    To       = now.AddDays(5),
                    IssuedOn = now
                },
                new TransportationTaxiSupport {
                    SupportDelivery = new Referral
                    {
                        SupplierId         = TestData.SupplierAId,
                        SupplierNotes      = $"{uniqueId}-notes",
                        IssuedToPersonName = "test person",
                    },
                    CreatedByTeamMemberId    = TestData.Tier4TeamMemberId,
                    IncludedHouseholdMembers = householdMembers,
                    From     = now,
                    To       = now.AddDays(3),
                    IssuedOn = now,
                }
            };

            var newSupportIds = ((CreateNewSupportsCommandResult)await supportRepository.Manage(new CreateNewSupportsCommand
            {
                FileId = evacuationFileId,
                Supports = newSupports
            })).Supports.Select(s => s.Id).ToArray();

            newSupportIds.Count().ShouldBe(newSupports.Length);

            var supports = ((SearchSupportQueryResult)await supportRepository.Query(new SearchSupportsQuery {
                ByEvacuationFileId = evacuationFileId
            }))
                           .Items.Where(s => newSupportIds.Contains(s.Id)).ToArray();

            supports.Length.ShouldBe(newSupports.Length);

            foreach (var support in supports)
            {
                var sourceSupport = newSupports.Single(s => s.GetType() == support.GetType());

                if (sourceSupport.IncludedHouseholdMembers.Any())
                {
                    support.IncludedHouseholdMembers.ShouldBe(sourceSupport.IncludedHouseholdMembers);
                }
                if (sourceSupport.CreatedByTeamMemberId != null)
                {
                    support.CreatedByTeamMemberId.ShouldBe(sourceSupport.CreatedByTeamMemberId);
                }

                support.To.ShouldBe(sourceSupport.To);
                support.CreatedByTeamMemberId.ShouldBe(sourceSupport.CreatedByTeamMemberId);
                support.IncludedHouseholdMembers.ShouldBe(sourceSupport.IncludedHouseholdMembers);
                support.CreatedOn.ShouldBeInRange(now.AddSeconds(-5), DateTime.UtcNow);
                support.IssuedOn.ShouldBe(support.CreatedOn);

                if (sourceSupport.SupportDelivery is Referral sourceReferral)
                {
                    support.Status.ShouldBe(sourceSupport.To < DateTime.UtcNow ? SupportStatus.Expired : SupportStatus.Active);
                    var referral = support.SupportDelivery.ShouldBeAssignableTo <Referral>().ShouldNotBeNull();
                    referral.IssuedToPersonName.ShouldBe(sourceReferral.IssuedToPersonName);
                    referral.SupplierNotes.ShouldBe(sourceReferral.SupplierNotes);
                    referral.SupplierId.ShouldBe(sourceReferral.SupplierId);
                    referral.ManualReferralId.ShouldBeNull();
                    referral.IssuedByDisplayName.ShouldBeNull();
                    if (sourceReferral.SupplierId != null)
                    {
                        referral.SupplierId.ShouldBe(sourceReferral.SupplierId);
                    }
                }
                if (sourceSupport.SupportDelivery is Interac sourceETransfer)
                {
                    support.Status.ShouldBe(SupportStatus.PendingScan);
                    var etransfer = support.SupportDelivery.ShouldBeAssignableTo <Interac>().ShouldNotBeNull();
                    etransfer.NotificationEmail.ShouldBe(sourceETransfer.NotificationEmail);
                    etransfer.NotificationMobile.ShouldBe(sourceETransfer.NotificationMobile);
                    etransfer.ReceivingRegistrantId.ShouldBe(sourceETransfer.ReceivingRegistrantId);
                }
            }
        }