本文整理汇总了C#中System.Uri.ApplyParameters方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.ApplyParameters方法的具体用法?C# Uri.ApplyParameters怎么用?C# Uri.ApplyParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.ApplyParameters方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoesNotChangeUrlWhenParametersEmpty
public void DoesNotChangeUrlWhenParametersEmpty()
{
var uri = new Uri("https://example.com");
var uriWithEmptyParameters = uri.ApplyParameters(new Dictionary<string, string>());
var uriWithNullParameters = uri.ApplyParameters(null);
Assert.Equal(uri, uriWithEmptyParameters);
Assert.Equal(uri, uriWithNullParameters);
}
示例2: DoesNotChangePassedInDictionary
public void DoesNotChangePassedInDictionary()
{
var uri = new Uri("https://api.github.com/repositories/1/milestones?state=closed&sort=due_date&direction=asc&page=2");
var parameters = new Dictionary<string, string> { { "state", "open" }, { "sort", "other" } };
uri.ApplyParameters(parameters);
Assert.Equal(2, parameters.Count);
}
示例3: ThrowsExceptionWhenNullValueProvided
public void ThrowsExceptionWhenNullValueProvided()
{
var uri = new Uri("https://example.com");
var parameters = new Dictionary<string, string>
{
{"foo", null },
};
Assert.Throws<ArgumentNullException>(() => uri.ApplyParameters(parameters));
}
示例4: AppendsParametersAsQueryStringToRelativeUri
public void AppendsParametersAsQueryStringToRelativeUri()
{
var uri = new Uri("issues", UriKind.Relative);
var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
{
{"foo", "fooval"},
{"bar", "barval"}
});
Assert.Equal(new Uri("issues?foo=fooval&bar=barval", UriKind.Relative), uriWithParameters);
}
示例5: AppendsParametersAsQueryString
public void AppendsParametersAsQueryString()
{
var uri = new Uri("https://example.com");
var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
{
{"foo", "foo val"},
{"bar", "barval"}
});
Assert.Equal(new Uri("https://example.com?foo=foo%20val&bar=barval"), uriWithParameters);
}
示例6: OverwritesExistingParameters
public void OverwritesExistingParameters()
{
var uri = new Uri("https://example.com?crap=crapola");
var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
{
{"foo", "fooval"},
{"bar", "barval"}
});
Assert.Equal(new Uri("https://example.com?foo=fooval&bar=barval"), uriWithParameters);
}
示例7: CombinesExistingParametersWithNewParameters
public void CombinesExistingParametersWithNewParameters()
{
var uri = new Uri("https://api.github.com/repositories/1/milestones?state=closed&sort=due_date&direction=asc&page=2");
var parameters = new Dictionary<string, string> { { "state", "open" }, { "sort", "other"} };
var actual = uri.ApplyParameters(parameters);
Assert.True(actual.Query.Contains("state=open"));
Assert.True(actual.Query.Contains("sort=other"));
Assert.True(actual.Query.Contains("direction=asc"));
Assert.True(actual.Query.Contains("page=2"));
}