public void WhenParamNotExists_AndValueIsNotNull_ThenAddParam(string value)
            {
                var sut = new Uri("http://localhost/myapp");

                var result = sut.AddOrUpdateQueryParam("name", value);

                Assert.That(result, Is.EqualTo(new Uri($"http://localhost/myapp?name={value}")));
            }
            public void WhenHasNoQueryString_AndTrailingSlash_ThenAddParam()
            {
                var sut = new Uri("http://api.giphy.com/v1/gifs/search/");

                var result = sut.AddOrUpdateQueryParam("api_key", "ABC123");

                Assert.That(result, Is.EqualTo(new Uri("http://api.giphy.com/v1/gifs/search/?api_key=ABC123")));
            }
            public void WhenParamNotExists_AndValueIsNull_ThenNotRemoveParam(string uri)
            {
                var sut = new Uri(uri);

                var result = sut.AddOrUpdateQueryParam("name", null);

                Assert.That(result, Is.EqualTo(new Uri(uri)));
            }
            public void WhenValueContainsSpace_ThenEncodeValue()
            {
                var sut = new Uri("http://localhost/myapp");

                var result = sut.AddOrUpdateQueryParam("name", "John Smith");

                Assert.That(result.AbsoluteUri, Is.EqualTo("http://localhost/myapp?name=John+Smith"));
            }
            public void WhenParamExists_AndValueIsNull_ThenRemoveParam()
            {
                var sut = new Uri("http://localhost/myapp?name=value");

                var result = sut.AddOrUpdateQueryParam("name", null);

                Assert.That(result, Is.EqualTo(new Uri("http://localhost/myapp")));
            }
示例#6
0
        public static Uri AddTruncateResponse(this Uri source, bool truncateRespnse)
        {
            if (!truncateRespnse)
            {
                return(source.AddOrUpdateQueryParam("truncateResponse", "false"));
            }

            return(source);
        }
示例#7
0
        public static Uri AddFilterByDomain(this Uri source, string domain)
        {
            if (!string.IsNullOrEmpty(domain))
            {
                source = source.AddOrUpdateQueryParam("domain", domain);
            }

            return(source);
        }
示例#8
0
        public static Uri AddIncludeUnverified(this Uri source, bool includeUnverified)
        {
            if (!includeUnverified)
            {
                return(source.AddOrUpdateQueryParam("includeUnverified", "false"));
            }

            return(source);
        }
示例#9
0
        public static Uri AddTagParam(this Uri source, string tag)
        {
            if (!string.IsNullOrEmpty(tag))
            {
                return(source.AddOrUpdateQueryParam("tag", tag));
            }

            return(source);
        }
示例#10
0
        public static Uri AddLanguageParam(this Uri source, Language language)
        {
            if (language != null)
            {
                return(source.AddOrUpdateQueryParam("lang", language.Code));
            }

            return(source);
        }
示例#11
0
        public static Uri AddRatingParam(this Uri source, Rating rating)
        {
            if (rating != null)
            {
                return(source.AddOrUpdateQueryParam("rating", rating.Code));
            }

            return(source);
        }
示例#12
0
        public static Uri AddOffsetParam(this Uri source, int offset)
        {
            if (offset != 0)
            {
                return(source.AddOrUpdateQueryParam("offset", offset.ToString()));
            }

            return(source);
        }
示例#13
0
        public static Uri AddLimitParam(this Uri source, int limit)
        {
            if (limit != 0)
            {
                return(source.AddOrUpdateQueryParam("limit", limit.ToString()));
            }

            return(source);
        }
示例#14
0
        public static Uri AddFormatParam(this Uri source, string format)
        {
            if (!string.IsNullOrEmpty(format))
            {
                return(source.AddOrUpdateQueryParam("fmt", format));
            }

            return(source);
        }
示例#15
0
 public static Uri AddGifIdsParam(this Uri source, IEnumerable <string> gifIds)
 {
     return(source.AddOrUpdateQueryParam("ids", gifIds.ToCsv()));
 }
            public void WhenNameIsNullorEmpty_ThenThrowException(string name)
            {
                var sut = new Uri("http://localhost/myapp");

                Assert.Throws <ArgumentException>(() => sut.AddOrUpdateQueryParam(name, "value"));
            }
示例#17
0
 public static Uri AddQueryParam(this Uri source, string query)
 {
     return(source.AddOrUpdateQueryParam("q", query ?? string.Empty));
 }
示例#18
0
 public static Uri AddStickerPackIdParam(this Uri source, int packId)
 {
     return(source.AddOrUpdateQueryParam("pack_id", packId.ToString()));
 }
示例#19
0
 public static Uri AddApiKeyParam(this Uri source, string apiKey)
 {
     return(source.AddOrUpdateQueryParam("api_key", apiKey));
 }