public async Task <ActiveAppInfo> GetActiveAppAsync() { var request = _requestFactory.Create(); using (var response = await request.GetResponseAsync(UrlUtils.ActiveAppUrlFor(this.Url), "GET")) { ActiveAppInfo result = null; if (response.StatusCode != HttpStatusCode.OK) { result = new ActiveAppInfo { IsSuccess = false, StatusCode = response.StatusCode, StatusDescription = response.StatusDescription }; } else { result = ConversionUtils.XmlToInstance <ActiveAppInfo>(response.GetResponseStream()); result.IsSuccess = true; result.StatusCode = response.StatusCode; result.StatusDescription = response.StatusDescription; } return(result); } }
void GetActiveAppAsync_method() { ActiveAppInfo result = null; describe["when the command is successful"] = () => { it["should indicate a success"] = () => { result.IsSuccess.Should().BeTrue(); }; it["should return the currently active app"] = () => { result.App.Should().NotBeNull(); }; before = () => { var rokuResponse = TestHelper.BuildRokuResponse("ActiveApp.xml"); rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.ActiveAppUrlFor(rokuUri), "GET")) .ReturnsAsync(() => rokuResponse); }; context["when the Roku is on the home screen"] = () => { it["the app id should be 0 and the app name should be \"Roku\""] = () => { result.App.Id.Should().Be(0); result.App.Text.Should().Be("Roku"); }; before = () => { var rokuResponse = TestHelper.BuildRokuResponse("OnHomeScreen.xml"); rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.ActiveAppUrlFor(rokuUri), "GET")) .ReturnsAsync(() => rokuResponse); }; }; context["when the Roku is in screensaver mode"] = () => { it["should return screensaver information along with the app information"] = () => { result.ScreenSaver.Should().NotBeNull(); result.App.Should().NotBeNull(); }; before = () => { var rokuResponse = TestHelper.BuildRokuResponse("OnScreenSaver.xml"); rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.ActiveAppUrlFor(rokuUri), "GET")) .ReturnsAsync(() => rokuResponse); }; }; }; describe["when the command fails"] = () => { it["should indicate a failure"] = () => { result.IsSuccess.Should().BeFalse(); result.StatusCode.Should().Be(HttpStatusCode.BadRequest); }; before = () => { var rokuResponse = TestHelper.BuildRokuResponse(statusCode: HttpStatusCode.BadRequest); rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.ActiveAppUrlFor(rokuUri), "GET")) .ReturnsAsync(() => rokuResponse); }; }; before = () => { InitializeMocks(); }; actAsync = async() => { InitializeSubject(); result = await subject.GetActiveAppAsync(); }; }