Inheritance: RequestBuilderBase
 public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException()
 {
     var client = new ImgurClient("123", "1234");
     var requestBuilder = new ImageRequestBuilder();
     var url = $"{client.EndpointUrl}image";
     requestBuilder.UploadImageBinaryRequest(url, null);
 }
        public async Task UploadImageBinaryRequest_AreEqual()
        {
            var client = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url = $"{client.EndpointUrl}image";

            var image = File.ReadAllBytes("banana.gif");
            var request = requestBuilder.UploadImageBinaryRequest(url, image, "TheAlbum", "TheTitle",
                "TheDescription");

            Assert.IsNotNull(request);
            Assert.AreEqual("https://api.imgur.com/3/image", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);

            var content = (MultipartFormDataContent) request.Content;
            var imageContent =
                (ByteArrayContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "image");
            var album = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "album");
            var type = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "type");
            var title = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "title");
            var description =
                (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "description");

            Assert.IsNotNull(imageContent);
            Assert.IsNotNull(type);
            Assert.IsNotNull(album);
            Assert.IsNotNull(title);
            Assert.IsNotNull(description);

            Assert.AreEqual(image.Length, imageContent.Headers.ContentLength);
            Assert.AreEqual("file", await type.ReadAsStringAsync());
            Assert.AreEqual("TheAlbum", await album.ReadAsStringAsync());
            Assert.AreEqual("TheTitle", await title.ReadAsStringAsync());
            Assert.AreEqual("TheDescription", await description.ReadAsStringAsync());
        }
        public void UpdateImageRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();

            var exception = Record.Exception(() => requestBuilder.UpdateImageRequest(null, "1234Xyz9"));
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException) exception;
            Assert.Equal(argNullException.ParamName, "url");
        }
        public async Task UpdateImageRequest_AreEqual()
        {
            var client = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();

            var url = $"{client.EndpointUrl}image/1234Xyz9";
            var request = requestBuilder.UpdateImageRequest(url, "TheTitle", "TheDescription");

            Assert.IsNotNull(request);
            Assert.AreEqual("https://api.imgur.com/3/image/1234Xyz9", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync();

            Assert.AreEqual("title=TheTitle&description=TheDescription", expected);
        }
        public async Task UploadImageUrlRequest_AreEqual()
        {
            var client = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url = $"{client.EndpointUrl}image";

            var request = requestBuilder.UploadImageUrlRequest(url, "http://i.imgur.com/hxsPLa7.jpg",
                "TheAlbum", "TheTitle", "TheDescription");

            Assert.IsNotNull(request);
            Assert.AreEqual("https://api.imgur.com/3/image", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync();

            Assert.AreEqual(
                "type=URL&image=http%3A%2F%2Fi.imgur.com%2FhxsPLa7.jpg&album=TheAlbum&title=TheTitle&description=TheDescription",
                expected);
        }
 public void UploadImageBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
 {
     var requestBuilder = new ImageRequestBuilder();
     var image = File.ReadAllBytes("banana.gif");
     requestBuilder.UploadImageBinaryRequest(null, image);
 }
 public void UpdateImageRequest_WithUrlNull_ThrowsArgumentNullException()
 {
     var requestBuilder = new ImageRequestBuilder();
     requestBuilder.UpdateImageRequest(null, "1234Xyz9");
 }
 public void UploadStreamBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
 {
     var requestBuilder = new ImageRequestBuilder();
     using (var fs = new FileStream("banana.gif", FileMode.Open))
     {
         requestBuilder.UploadImageStreamRequest(null, fs);
     }
 }
 public void UploadStreamBinaryRequest_WithImageNull_ThrowsArgumentNullException()
 {
     var client = new ImgurClient("123", "1234");
     var requestBuilder = new ImageRequestBuilder();
     var url = $"{client.EndpointUrl}image";
     using (var fs = new FileStream("banana.gif", FileMode.Open))
     {
         requestBuilder.UploadImageStreamRequest(url, null);
     }
 }
Exemplo n.º 10
0
 public void UploadImageUrlRequest_WithUrlNull_ThrowsArgumentNullException()
 {
     var requestBuilder = new ImageRequestBuilder();
     requestBuilder.UploadImageBinaryRequest(null, null);
 }
        public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var mockUrl = $"{client.EndpointUrl}image";

            var exception = Record.Exception(() => requestBuilder.UploadImageBinaryRequest(mockUrl, null));
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException) exception;
            Assert.Equal(argNullException.ParamName, "image");
        }
        public void UploadStreamBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();
            using (var ms = new MemoryStream(new byte[9]))
            {
                // ReSharper disable once AccessToDisposedClosure
                var exception = Record.Exception(() => requestBuilder.UploadImageStreamRequest(null, ms));
                Assert.NotNull(exception);
                Assert.IsType<ArgumentNullException>(exception);

                var argNullException = (ArgumentNullException) exception;
                Assert.Equal(argNullException.ParamName, "url");
            }
        }
        public async Task UploadStreamBinaryRequest_Equal()
        {
            var client = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var mockUrl = $"{client.EndpointUrl}image";

            using (var ms = new MemoryStream(new byte[9]))
            {
                var imageLength = ms.Length;
                var request = requestBuilder.UploadImageStreamRequest(mockUrl, ms, "TheAlbum", "TheTitle",
                    "TheDescription");

                Assert.NotNull(request);
                Assert.Equal("https://api.imgur.com/3/image", request.RequestUri.ToString());
                Assert.Equal(HttpMethod.Post, request.Method);

                var content = (MultipartFormDataContent) request.Content;
                var imageContent =
                    (StreamContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "image");
                var album = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "album");
                var type = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "type");
                var title = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "title");
                var description =
                    (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "description");

                Assert.NotNull(imageContent);
                Assert.NotNull(type);
                Assert.NotNull(album);
                Assert.NotNull(title);
                Assert.NotNull(description);

                var image = await imageContent.ReadAsByteArrayAsync().ConfigureAwait(false);

                Assert.Equal(imageLength, image.Length);
                Assert.Equal("file", await type.ReadAsStringAsync().ConfigureAwait(false));
                Assert.Equal("TheAlbum", await album.ReadAsStringAsync().ConfigureAwait(false));
                Assert.Equal("TheTitle", await title.ReadAsStringAsync().ConfigureAwait(false));
                Assert.Equal("TheDescription", await description.ReadAsStringAsync().ConfigureAwait(false));
            }
        }
        public void UploadImageUrlRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();

            var exception = Record.Exception(() => requestBuilder.UploadImageBinaryRequest(null, new byte[9]));
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException) exception;
            Assert.Equal(argNullException.ParamName, "url");
        }