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"))); }
public static Uri AddTruncateResponse(this Uri source, bool truncateRespnse) { if (!truncateRespnse) { return(source.AddOrUpdateQueryParam("truncateResponse", "false")); } return(source); }
public static Uri AddFilterByDomain(this Uri source, string domain) { if (!string.IsNullOrEmpty(domain)) { source = source.AddOrUpdateQueryParam("domain", domain); } return(source); }
public static Uri AddIncludeUnverified(this Uri source, bool includeUnverified) { if (!includeUnverified) { return(source.AddOrUpdateQueryParam("includeUnverified", "false")); } return(source); }
public static Uri AddTagParam(this Uri source, string tag) { if (!string.IsNullOrEmpty(tag)) { return(source.AddOrUpdateQueryParam("tag", tag)); } return(source); }
public static Uri AddLanguageParam(this Uri source, Language language) { if (language != null) { return(source.AddOrUpdateQueryParam("lang", language.Code)); } return(source); }
public static Uri AddRatingParam(this Uri source, Rating rating) { if (rating != null) { return(source.AddOrUpdateQueryParam("rating", rating.Code)); } return(source); }
public static Uri AddOffsetParam(this Uri source, int offset) { if (offset != 0) { return(source.AddOrUpdateQueryParam("offset", offset.ToString())); } return(source); }
public static Uri AddLimitParam(this Uri source, int limit) { if (limit != 0) { return(source.AddOrUpdateQueryParam("limit", limit.ToString())); } return(source); }
public static Uri AddFormatParam(this Uri source, string format) { if (!string.IsNullOrEmpty(format)) { return(source.AddOrUpdateQueryParam("fmt", format)); } return(source); }
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")); }
public static Uri AddQueryParam(this Uri source, string query) { return(source.AddOrUpdateQueryParam("q", query ?? string.Empty)); }
public static Uri AddStickerPackIdParam(this Uri source, int packId) { return(source.AddOrUpdateQueryParam("pack_id", packId.ToString())); }
public static Uri AddApiKeyParam(this Uri source, string apiKey) { return(source.AddOrUpdateQueryParam("api_key", apiKey)); }