Ejemplo n.º 1
0
        public async Task NotSuccessStatusCode_ThrowsHttpRequestException()
        {
            var mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new StickerRandomParameter();

            _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.StickerRandom(search));
        }
Ejemplo n.º 2
0
        public async Task ParameterIsNull_ThrowsNullReferenceException()
        {
            var giphy = new Giphy("test");

            StickerRandomParameter search = null;

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.StickerRandom(search));
        }
Ejemplo n.º 3
0
        public void Rating_DefaultValue_IsG()
        {
            var parameter = new StickerRandomParameter();

            var expected = Rating.G;
            var actual   = parameter.Rating;

            Assert.IsType <Rating>(actual);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public async Task WhenCalled_ReturnsGiphySingle()
        {
            var mockHttpHandler = HttpHandler.GetMockSuccessHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new StickerRandomParameter();

            var actual = await giphy.StickerRandom(search);

            Assert.NotNull(actual);
            Assert.IsType <GiphySingle>(actual);
        }
Ejemplo n.º 5
0
        public void Tag_WhenSet_EscapesUriString()
        {
            var paramter = new StickerRandomParameter
            {
                Tag = "This is a unit test!"
            };

            var expected = "This%20is%20a%20unit%20test!";
            var actual   = paramter.Tag;

            Assert.NotNull(actual);
            Assert.IsType <string>(actual);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns a random Sticker, limited by tag.
        /// Excluding the tag parameter will return a
        /// random Sticker from the GIPHY catalog.
        /// </summary>
        /// <param name="parameter">Specifies search parameters</param>
        /// <returns>Root object</returns>
        public async Task <GiphySingle> StickerRandom(StickerRandomParameter parameter)
        {
            if (parameter is null)
            {
                throw new NullReferenceException("Paramter cannot be null");
            }

            /* Finish exception checks */

            string url = $@"{ _stickersRandomUrl }?api_key={ _apiKey }";

            url += parameter.Tag != null ? $"&tag={ parameter.Tag }" : "";
            url += $"&rating={ parameter.Rating }";

            var response = await _httpHandler.GetAsync(url);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException(response.ReasonPhrase);
            }

            return(await response.Content.ReadAsAsync <GiphySingle>());
        }