private async Task <IRokuRemote> BuildRokuDataAsync(Uri rokuUri) { var infoRequest = _requestFactory.Create(); var appsRequest = _requestFactory.Create(); using (var infoResponse = await infoRequest.GetResponseAsync(UrlUtils.DeviceInfoUrlFor(rokuUri), "GET")) using (var appsResponse = await appsRequest.GetResponseAsync(UrlUtils.AppsUrlFor(rokuUri), "GET")) { if (infoResponse.StatusCode != HttpStatusCode.OK || appsResponse.StatusCode != HttpStatusCode.OK) { return(null); //TODO: throw? } var result = new RokuRemote( requestFactory: _requestFactory, uri: rokuUri, info: ConversionUtils.XmlToInstance <RokuInfo>(infoResponse.GetResponseStream()), apps: ConversionUtils.XmlToInstance <RokuAppContainer>(appsResponse.GetResponseStream()).Apps ); return(result); } }
void InitializeMocks() { var discoveredRokus = new List <DiscoveredSsdpDevice> { new DiscoveredSsdpDevice { DescriptionLocation = new Uri(roku1), Usn = RokuDiscovery.RokuSSDPSearchTarget }, new DiscoveredSsdpDevice { DescriptionLocation = new Uri(roku2), Usn = RokuDiscovery.RokuSSDPSearchTarget } }; deviceLocator = new Mock <ISsdpDeviceLocator>(); deviceLocator.Setup(m => m.SearchAsync(RokuDiscovery.RokuSSDPSearchTarget)) .ReturnsAsync(() => discoveredRokus); deviceLocator.As <IDisposable>().Setup(m => m.Dispose()); var rokuRequest = new Mock <IRokuRequest>(); foreach (var roku in discoveredRokus) { rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.DeviceInfoUrlFor(roku.DescriptionLocation), "GET")) .ReturnsAsync(() => TestHelper.BuildRokuResponse("DeviceInfo.xml")); rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.AppsUrlFor(roku.DescriptionLocation), "GET")) .ReturnsAsync(() => TestHelper.BuildRokuResponse("Apps.xml")); } requestFactory = new Mock <IRokuRequestFactory>(); requestFactory.Setup(m => m.Create()) .Returns(() => rokuRequest.Object); }