UploadImageBinaryRequest() private method

/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. ///
private UploadImageBinaryRequest ( string url, byte image, string albumId = null, string title = null, string description = null ) : HttpRequestMessage
url string
image byte
albumId string
title string
description string
return System.Net.Http.HttpRequestMessage
Ejemplo n.º 1
0
 public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException()
 {
     var client = new ImgurClient("123", "1234");
     var requestBuilder = new ImageRequestBuilder();
     var url = $"{client.EndpointUrl}image";
     requestBuilder.UploadImageBinaryRequest(url, null);
 }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
 public void UploadImageBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
 {
     var requestBuilder = new ImageRequestBuilder();
     var image = File.ReadAllBytes("banana.gif");
     requestBuilder.UploadImageBinaryRequest(null, image);
 }
Ejemplo n.º 4
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 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");
        }