本文整理汇总了C#中Tavis.UriTemplates.UriTemplate.SetParameter方法的典型用法代码示例。如果您正苦于以下问题:C# UriTemplate.SetParameter方法的具体用法?C# UriTemplate.SetParameter怎么用?C# UriTemplate.SetParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tavis.UriTemplates.UriTemplate
的用法示例。
在下文中一共展示了UriTemplate.SetParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FactMethodName
public void FactMethodName()
{
UriTemplate template = new UriTemplate("https://api.github.com/search/code?q={query}{&page,per_page,sort,order}");
template.SetParameter("query", "1234");
template.SetParameter("per_page", "19");
var result = template.Resolve();
}
示例2: ShouldAllowUriTemplateWithMultiplePathSegmentParameter
public void ShouldAllowUriTemplateWithMultiplePathSegmentParameter()
{
var template = new UriTemplate("http://example.org/foo/{bar}/baz/{blar}");
template.SetParameter("bar", "yo");
template.SetParameter("blar", "yuck");
var uriString = template.Resolve();
Assert.Equal("http://example.org/foo/yo/baz/yuck", uriString);
}
示例3: ShouldAllowListAndSingleValueInQueryParam
public void ShouldAllowListAndSingleValueInQueryParam()
{
var template = new UriTemplate("http://example.org{/id*}{?fields,token}");
template.SetParameter("id", new List<string>() { "person", "albums" });
template.SetParameter("fields", new List<string>() { "id", "name", "picture" });
template.SetParameter("token", "12345");
var uriString = template.Resolve();
Assert.Equal("http://example.org/person/albums?fields=id,name,picture&token=12345", uriString);
}
示例4: ShouldAllowUriTemplateToRemoveParameter
public void ShouldAllowUriTemplateToRemoveParameter()
{
var template = new UriTemplate("http://example.org/foo{?bar,baz}");
template.SetParameter("bar", "yo");
template.SetParameter("baz", "yuck");
template.ClearParameter("bar");
var uriString = template.Resolve();
Assert.Equal("http://example.org/foo?baz=yuck", uriString);
}
示例5: Query_param_with_list_array
public void Query_param_with_list_array()
{
UriTemplate template = new UriTemplate("/foo/{foo}/baz{?haz}");
template.SetParameter("foo", "1234");
template.SetParameter("haz", new string[] { "foo", "bar" });
string uri = template.Resolve();
Assert.Equal("/foo/1234/baz?haz=foo,bar", uri);
}
示例6: ShouldResolveMatrixParameter
public void ShouldResolveMatrixParameter()
{
var template = new UriTemplate("http://example.org/foo{;lat,lng}");
double lat = 31.464, lng = 74.386;
template.SetParameter("lat", lat);
template.SetParameter("lng", lng);
var uriString = template.Resolve();
Assert.Equal("http://example.org/foo;lat=31.464;lng=74.386", uriString);
}
示例7: ShouldResolveUriTemplateWithNonStringParameter
public void ShouldResolveUriTemplateWithNonStringParameter()
{
var template = new UriTemplate("http://example.org/foo/{bar}/baz{?lat,lng}");
double lat = 31.464, lng = 74.386;
template.SetParameter("bar", "yo");
template.SetParameter("lat", lat);
template.SetParameter("lng", lng);
var uriString = template.Resolve();
Assert.Equal("http://example.org/foo/yo/baz?lat=31.464&lng=74.386", uriString);
}
示例8: ExtendedSamplesTest
public void ExtendedSamplesTest(string template, string[] results, TestSet.TestCase testCase)
{
var uriTemplate = new UriTemplate(template);
foreach (var variable in testCase.TestSet.Variables)
{
uriTemplate.SetParameter(variable.Key, variable.Value);
}
string result = null;
ArgumentException aex = null;
try
{
result = uriTemplate.Resolve();
}
catch (ArgumentException ex)
{
aex = ex;
}
if (results[0] == "False")
{
Assert.NotNull(aex);
}
else
{
Assert.True(results.Contains(result));
}
}
示例9: FailureSamplesTest
// Disabled for the moment. [Theory, PropertyData("FailureSamples")]
public void FailureSamplesTest(string template, string[] results, TestSet.TestCase testCase)
{
var uriTemplate = new UriTemplate(template);
foreach (var variable in testCase.TestSet.Variables)
{
uriTemplate.SetParameter(variable.Key, variable.Value);
}
string result = null;
ArgumentException aex = null;
try
{
result = uriTemplate.Resolve();
}
catch (ArgumentException ex)
{
aex = ex;
}
Assert.NotNull(aex);
}
示例10: LabelExpansionWithDotPrefixAndEmptyKeys
public void LabelExpansionWithDotPrefixAndEmptyKeys()
{
var template = new UriTemplate("X{.empty_keys}");
template.SetParameter("empty_keys", new Dictionary<string, string>());
var uriString = template.Resolve();
Assert.Equal("X", uriString);
}
示例11: ShouldAllowUriTemplateWithQueryParamsWithOneValue
public void ShouldAllowUriTemplateWithQueryParamsWithOneValue()
{
var template = new UriTemplate("http://example.org/foo{?bar,baz}");
template.SetParameter("baz", "yo");
var uriString = template.Resolve();
Assert.Equal("http://example.org/foo?baz=yo", uriString);
}
示例12: ResolveDocumentationUri
private static Uri ResolveDocumentationUri(ILinkObject link, string rel)
{
var template = new UriTemplate(link.Href.ToString());
template.SetParameter("rel", rel);
return new Uri(template.Resolve());
}
示例13: ResolveTemplateUrl
private static string ResolveTemplateUrl(string href, Dictionary<string, string> values)
{
var template = new UriTemplate(href);
foreach (var templateValue in values)
template.SetParameter(templateValue.Key, templateValue.Value);
return template.Resolve();
}
示例14: AsUriStr
public string AsUriStr()
{
if (_path != null)
{
return _path;
}
if (_resource._uriTemplateStr != null)
{
var template = new UriTemplate(_resource._uriTemplateStr);
var parameterNames = template.GetParameterNames();
var parameterNameList = parameterNames as IList<string> ?? parameterNames.ToList();
if (_pathElements != null)
{
if (parameterNameList.Count() != _pathElements.Count())
{
throw new ArgumentException(String.Format("Mismatch between parameters in uriTemplate and supplied elements; uriTemplate={0}, elements={1}", template.Template, _pathElements));
}
int i = 0;
foreach (var parameterName in parameterNameList)
{
template.SetParameter(parameterName, _pathElements[i++]);
}
}
else
{
var pathElementMapKeys = _pathElementMap.Keys;
var argsWithNoParams = pathElementMapKeys.Except(parameterNameList);
var paramsWithNoArgs = parameterNameList.Except(pathElementMapKeys);
if (argsWithNoParams.Any() || paramsWithNoArgs.Any())
{
throw new ArgumentException(String.Format("Mismatch between parameters in uriTemplate and supplied map; uriTemlpate={0}, map={1}", template.Template, _pathElementMap));
}
foreach (var parameterName in parameterNameList)
{
template.SetParameter(parameterName, _pathElementMap[parameterName]);
}
}
return PrefixBaseIfRequired(template.Resolve());
}
// else
return PrefixBaseIfRequired(_resource._uriStr);
}
示例15: PreserveReservedCharacterExpansion
public void PreserveReservedCharacterExpansion()
{
UriTemplate template = new UriTemplate("https://foo.com/?format={+format}");
template.SetParameter("format", "application/vnd.foo+xml");
var result = template.Resolve();
Assert.Equal("https://foo.com/?format=application/vnd.foo+xml", result);
var httpClient = new HttpClient();
var response = httpClient.GetAsync("http://yahoo.com/foo%2Fbar").Result;
}