public async void FetchGreenButtonData() { XDocument doc = XDocument.Load(@"Data/GreenButton_Electricity.xml"); A.CallTo(() => greenButtonClient.FetchGreenButtonData()).Returns(doc); GreenButtonData greenButtonData = await greenButtonService.FetchGreenButtonData(); greenButtonData.MeterReadings.Length.Should().Be(13, "number of ns:IntervalBlocks"); GreenButtonData.MeterReading lastReading = greenButtonData.MeterReadings.Last(); lastReading.CostCents.Should().Be(2048); lastReading.BillingInterval.Start.Should().Be(new LocalDate(2017, 7, 17)); lastReading.BillingInterval.End.Should().Be(new LocalDate(2017, 8, 16)); }
public async void FetchGreenButtonData() { A.CallTo(() => client.FetchHiddenFormData(A <Uri> ._)).Returns(new Dictionary <string, string> { ["hiddenKey1"] = "hiddenValue1", ["hiddenKey2"] = "hiddenValue2" }); var response = A.Fake <HttpResponseMessage>(); var doc = new XDocument(); string requestBody = null; A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> ._)).ReturnsLazily(async call => { requestBody = await call.Arguments[0].As <HttpRequestMessage>().Content.ReadAsStringAsync(); return(response); }); A.CallTo(() => contentHandlers.ReadContentAsXml(A <HttpResponseMessage> ._)).Returns(doc); XDocument actual = await greenButtonClient.FetchGreenButtonData(); A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> .That.Matches(message => message.Method == HttpMethod.Post && message.RequestUri.ToString() .Equals("https://apps.coned.com/ORMyAccount/Forms/Billing/GreenButtonData.aspx") ))) .MustHaveHappened(); requestBody.Should().Be("OptEnergy=E" + "&optFileFormat=XML" + "&imgGreenButton.x=1" + "&imgGreenButton.y=1" + "&hiddenKey1=hiddenValue1" + "&hiddenKey2=hiddenValue2"); actual.Should().BeSameAs(doc); }