Beispiel #1
0
        public async Task <AppIcon> GetAppIconAsync(int appId)
        {
            var uri = $"{this.Url}query/icon/{appId}";

            var request = _requestFactory.Create();

            using (var response = await request.GetResponseAsync(UrlUtils.AppIconUrlFor(this.Url, appId), "GET"))
            {
                AppIcon result = null;
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    result = new AppIcon(response);
                }
                else
                {
                    MemoryStream localStream = new MemoryStream();
                    await response.GetResponseStream().CopyToAsync(localStream);

                    result = new AppIcon(appId, response.ContentType, localStream.ToArray(), response);
                }

                return(result);
            }
        }
Beispiel #2
0
        void GetAppIconAsync_method()
        {
            AppIcon result = null;
            int     appId  = 12345;

            describe["when the command succeeds"] = () =>
            {
                string contentType = "image/jpeg";

                it["should indicate success"] = () =>
                {
                    result.IsSuccess.Should().BeTrue();
                };

                it["should return the app Id"] = () =>
                {
                    result.AppId.Should().Be(appId);
                };

                it["should return the content type"] = () =>
                {
                    result.ContentType.Should().Be(contentType);
                };

                it["should return the image bytes"] = () =>
                {
                    result.Image.Should().NotBeEmpty();
                };

                before = () =>
                {
                    var rokuResponse = TestHelper.BuildRokuResponse("Netflix.jpg", contentType: contentType);
                    rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.AppIconUrlFor(rokuUri, appId), "GET"))
                    .ReturnsAsync(() => rokuResponse);
                };
            };

            describe["when the command fails"] = () =>
            {
                it["should indicate a failure"] = () =>
                {
                    result.IsSuccess.Should().BeFalse();
                    result.StatusCode.Should().Be(HttpStatusCode.Forbidden);
                };

                before = () =>
                {
                    var rokuResponse = TestHelper.BuildRokuResponse(statusCode: HttpStatusCode.Forbidden);
                    rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.AppIconUrlFor(rokuUri, appId), "GET"))
                    .ReturnsAsync(() => rokuResponse);
                };
            };

            before = () =>
            {
                InitializeMocks();
            };

            actAsync = async() =>
            {
                InitializeSubject();
                result = await subject.GetAppIconAsync(appId);
            };
        }