本文整理汇总了C#中Nancy.Responses.Negotiation.MediaRange.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MediaRange.ToString方法的具体用法?C# MediaRange.ToString怎么用?C# MediaRange.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Responses.Negotiation.MediaRange
的用法示例。
在下文中一共展示了MediaRange.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_strip_whitespace_when_calling_tostring
public void Should_strip_whitespace_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy ; a=1; b=2");
// Then
range.ToString().ShouldEqual("application/vnd.nancy;a=1;b=2");
}
示例2: Should_include_parameters_when_calling_tostring
public void Should_include_parameters_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy;a=1;b=2");
// Then
range.ToString().ShouldEqual("application/vnd.nancy;a=1;b=2");
}
示例3: Should_handle_no_parameters_when_calling_tostring
public void Should_handle_no_parameters_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy");
// Then
range.ToString().ShouldEqual("application/vnd.nancy");
}
示例4: CanDeserialize
/// <summary>
/// Whether the deserializer can deserialize the content type
/// </summary>
/// <param name="mediaRange">Content type to deserialize</param>
/// <param name="context">Current <see cref="BindingContext"/>.</param>
/// <returns>True if supported, false otherwise</returns>
public bool CanDeserialize(MediaRange mediaRange, BindingContext context)
{
if (string.IsNullOrEmpty(mediaRange))
{
return false;
}
var contentMimeType = mediaRange.ToString().Split(';')[0];
return contentMimeType.Equals("application/xml", StringComparison.OrdinalIgnoreCase) ||
contentMimeType.Equals("text/xml", StringComparison.OrdinalIgnoreCase) ||
(contentMimeType.StartsWith("application/vnd", StringComparison.OrdinalIgnoreCase) &&
contentMimeType.EndsWith("+xml", StringComparison.OrdinalIgnoreCase));
}
示例5: TestSparqlPostSucceeds
private static void TestSparqlPostSucceeds(string storeName, string query, IEnumerable<string> defaultGraphUris, IEnumerable<string> namedGraphUris, MediaRange accept, SparqlResultsFormat expectedQueryFormat, Action<Mock<IBrightstarService>> brightstarSetup)
{
// Setup
var brightstar = new Mock<IBrightstarService>();
brightstar.Setup(s => s.ExecuteQuery(storeName, query, defaultGraphUris, null, expectedQueryFormat))
.Returns(new MemoryStream(Encoding.UTF8.GetBytes("Mock Results")))
.Verifiable();
if (brightstarSetup != null) brightstarSetup(brightstar);
var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));
// Execute
var response = app.Post("/" + storeName + "/sparql", with =>
{
with.Body(query);
with.Header("Content-Type", "application/sparql-query");
if (defaultGraphUris != null)
{
foreach (var defaultGraphUri in defaultGraphUris)
{
with.Query("default-graph-uri", defaultGraphUri);
}
}
if (namedGraphUris != null)
{
foreach (var namedGraphUri in namedGraphUris)
{
with.Query("named-graph-uri", namedGraphUri);
}
}
with.Accept(accept);
});
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(response.ContentType, Is.EqualTo(accept.ToString()));
Assert.That(response.Body.AsString(), Is.EqualTo("Mock Results"));
brightstar.Verify();
}
示例6: TestGetSucceeds
private static BrowserResponse TestGetSucceeds(
string storeName, string query, IEnumerable<string> defaultGraphUris,
IEnumerable<string> namedGraphUris,
MediaRange accept,
Action<Mock<IBrightstarService>> brightstarSetup)
{
// Setup
var brightstar = new Mock<IBrightstarService>();
brightstarSetup(brightstar);
var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));
if (accept == null) accept = MediaRange.FromString("application/sparql-results+xml");
// Execute
var response = app.Get("/" + storeName + "/sparql", with =>
{
with.Query("query", query);
if (defaultGraphUris != null)
{
foreach (var defaultGraph in defaultGraphUris)
{
with.Query("default-graph-uri", defaultGraph);
}
}
if (namedGraphUris != null)
{
foreach (var namedGraph in namedGraphUris)
{
with.Query("named-graph-uri", namedGraph);
}
}
with.Accept(accept);
});
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(response.ContentType, Is.EqualTo(accept.ToString()));
brightstar.Verify();
return response;
}