示例#1
0
        public async Task <Stream> fetchBillDocument(BillDocument billDocument)
        {
            UriBuilder uri = OrangeRocklandClientImpl.apiRoot
                             .WithPathSegment("..")
                             .WithPathSegment("ViewBillImage.aspx")
                             .WithParameter("acct", billDocument.accountId.ToString())
                             .WithParameter("bill_dt", LocalDatePattern.Iso.Format(billDocument.publishingDate))
                             .WithParameter("loc", "app")
                             .WithParameter("cd_co", "9");

            try {
                HttpResponseMessage response = await httpClient.GetAsync(uri.Uri);

                // don't close the response because iTextSharp needs the stream to stay open
                return(await response.Content.ReadAsStreamAsync());
            } catch (HttpRequestException e) {
                throw new OrangeRocklandException($"Failed to download bill document from {billDocument.publishingDate:d}", e);
            }
        }
        public async void FetchBillDocument()
        {
            A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> ._)).Returns(new HttpResponseMessage
            {
                Content = new StringContent("hello")
            });

            var billDocument = new BillDocument
            {
                AccountId      = 123,
                PublishingDate = new LocalDate(2018, 3, 31)
            };

            Stream actual = await billDocumentClient.FetchBillDocument(billDocument);

            new StreamReader(actual).ReadToEnd().Should().Be("hello");

            A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> .That.Matches(message =>
                                                                                            message.Method == HttpMethod.Get &&
                                                                                            message.RequestUri.ToString()
                                                                                            .Equals("https://apps.coned.com/ORMyAccount/ViewBillImage.aspx?acct=123&bill_dt=2018-03-31&loc=app&cd_co=9")
                                                                                            ))).MustHaveHappened();
        }