public async Task TestSuccessfulResponseMapping(TitleInsuranceResponse titleInsuranceResponse, string policyNumber, decimal premium, decimal gSTOnPremium, decimal stampDuty)
        {
            var mappedResponse = await _mapper.MapFromFirstTitleResponse(titleInsuranceResponse);

            Assert.Equal(policyNumber, mappedResponse.PolicyNumber);
            Assert.Equal(premium, mappedResponse.Price.Premium);
            Assert.Equal(gSTOnPremium, mappedResponse.Price.GSTOnPremium);
            Assert.Equal(stampDuty, mappedResponse.Price.StampDuty);
        }
示例#2
0
        public async Task <SendFirstTitlePolicyRequestResponse> MapFromFirstTitleResponse(TitleInsuranceResponse titleInsuranceResponse)
        {
            if (titleInsuranceResponse is null)
            {
                throw new System.ArgumentNullException(nameof(titleInsuranceResponse));
            }

            if (titleInsuranceResponse.Message[0].MessageBody[0].Status[0].Name == StatusName.Succeeded)
            {
                var prices   = titleInsuranceResponse.Message[0].TitleInsuranceResponseSegment.Price;
                var response = new SendFirstTitlePolicyRequestResponse
                {
                    PolicyNumber = titleInsuranceResponse.Message[0].TitleInsuranceResponseSegment.Policy.PolicyCode,
                    Price        = new FirstTitlePrice
                    {
                        Premium      = prices.First(p => p.PriceType == PricePriceType.Premium).Value,
                        GSTOnPremium = prices.First(p => p.PriceType == PricePriceType.GSTOnPremium).Value,
                        StampDuty    = prices.First(p => p.PriceType == PricePriceType.StampDuty).Value,
                    }
                };

                if (titleInsuranceResponse.AttachmentSegment != null && titleInsuranceResponse.AttachmentSegment.Length > 0)
                {
                    response.AttachmentPaths = new FTAttachment[titleInsuranceResponse.AttachmentSegment.Length];

                    for (var i = 0; i < titleInsuranceResponse.AttachmentSegment.Length; i++)
                    {
                        var attachment = titleInsuranceResponse.AttachmentSegment[i];
                        var path       = Path.Join(Path.GetTempPath(), attachment.Filename);

                        await File.WriteAllBytesAsync(path, attachment.InlineAttachment);

                        response.AttachmentPaths[i] = new FTAttachment()
                        {
                            FileName = attachment.Filename,
                            FileUrl  = path
                        };
                    }
                }

                return(response);
            }
            else if (titleInsuranceResponse.Message[0].MessageBody[0].Status[0].Name == StatusName.Pending)
            {
                var prices = titleInsuranceResponse.Message[0].TitleInsuranceResponseSegment.Price;
                return(new SendFirstTitlePolicyRequestResponse
                {
                    PolicyNumber = titleInsuranceResponse.Message[0].TitleInsuranceResponseSegment.Policy.PolicyCode,
                    Price = new FirstTitlePrice
                    {
                        Premium = prices.First(p => p.PriceType == PricePriceType.Premium).Value,
                        GSTOnPremium = prices.First(p => p.PriceType == PricePriceType.GSTOnPremium).Value,
                        StampDuty = prices.First(p => p.PriceType == PricePriceType.StampDuty).Value,
                    }
                });
            }
            else
            {
                var errorMessage = titleInsuranceResponse.Message[0].MessageBody[0].MessageAnnotation[0].Value;
                throw new FirstTitlePolicyRequestException(errorMessage);
            }
        }
        public async Task TestFailedResponseMapping(TitleInsuranceResponse titleInsuranceResponse, string errorMessage)
        {
            var ex = await Assert.ThrowsAsync <FirstTitlePolicyRequestException>(() => _mapper.MapFromFirstTitleResponse(titleInsuranceResponse));

            Assert.Equal(errorMessage, ex.Message);
        }