本文整理汇总了C#中System.Net.Http.ObjectContent.ReadAsStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContent.ReadAsStringAsync方法的具体用法?C# ObjectContent.ReadAsStringAsync怎么用?C# ObjectContent.ReadAsStringAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.ObjectContent
的用法示例。
在下文中一共展示了ObjectContent.ReadAsStringAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IEnumerableOfEntityTypeSerializesAsODataFeed
private void IEnumerableOfEntityTypeSerializesAsODataFeed(string expectedContent, bool json)
{
ODataMediaTypeFormatter formatter = CreateFormatter();
IEnumerable<Employee> collectionOfPerson = new Collection<Employee>()
{
(Employee)TypeInitializer.GetInstance(SupportedTypes.Employee, 0),
(Employee)TypeInitializer.GetInstance(SupportedTypes.Employee, 1),
};
ObjectContent<IEnumerable<Employee>> content = new ObjectContent<IEnumerable<Employee>>(collectionOfPerson,
formatter, json ? ODataMediaTypes.ApplicationJsonODataMinimalMetadata :
ODataMediaTypes.ApplicationAtomXmlTypeFeed);
string actualContent = content.ReadAsStringAsync().Result;
if (json)
{
JsonAssert.Equal(expectedContent, actualContent);
}
else
{
RegexReplacement replaceUpdateTime = new RegexReplacement(
"<updated>*.*</updated>", "<updated>UpdatedTime</updated>");
Assert.Xml.Equal(expectedContent, actualContent, replaceUpdateTime);
}
}
示例2: ArrayOfIntsSerializesAsOData
private void ArrayOfIntsSerializesAsOData(string expectedContent, bool json)
{
ObjectContent<int[]> content = new ObjectContent<int[]>(new int[] { 10, 20, 30, 40, 50 }, _formatter,
GetMediaType(json));
AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
}
示例3: ArrayOfBoolsSerializesAsOData
private void ArrayOfBoolsSerializesAsOData(string expectedContent, bool json)
{
ObjectContent<bool[]> content = new ObjectContent<bool[]>(new bool[] { true, false, true, false },
_formatter, GetMediaType(json));
AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
}
示例4: ComplexTypeSerializesAsOData
private void ComplexTypeSerializesAsOData(string expectedContent, bool json)
{
ObjectContent<Person> content = new ObjectContent<Person>(new Person(0, new ReferenceDepthContext(7)),
_formatter, CollectionTest.GetMediaType(json));
CollectionTest.AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
}
示例5: ArrayOfIntsSerializesAsOData
public void ArrayOfIntsSerializesAsOData()
{
// Arrange
ObjectContent<int[]> content = new ObjectContent<int[]>(new int[] { 10, 20, 30, 40, 50 }, _formatter,
ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
// Act & Assert
JsonAssert.Equal(Resources.ArrayOfInt32, content.ReadAsStringAsync().Result);
}
示例6: ArrayOfBooleansSerializesAsOData
public void ArrayOfBooleansSerializesAsOData()
{
// Arrange
ObjectContent<bool[]> content = new ObjectContent<bool[]>(new bool[] { true, false, true, false },
_formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
// Act & Assert
JsonAssert.Equal(Resources.ArrayOfBoolean, content.ReadAsStringAsync().Result);
}
示例7: EntityTypeSerializesAsODataEntry
public void EntityTypeSerializesAsODataEntry()
{
ODataMediaTypeFormatter formatter = CreateFormatter();
Employee employee = (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee);
ObjectContent<Employee> content = new ObjectContent<Employee>(employee, formatter);
RegexReplacement replaceUpdateTime = new RegexReplacement("<updated>*.*</updated>", "<updated>UpdatedTime</updated>");
Assert.Xml.Equal(BaselineResource.TestEntityTypeBasic, content.ReadAsStringAsync().Result, regexReplacements: replaceUpdateTime);
}
示例8: render_simple_template
public void render_simple_template()
{
var view = new View("Test1", new {Name = "foo"});
var content = new ObjectContent<View>(view, _formatter);
var output = content.ReadAsStringAsync().Result;
Assert.AreEqual("Hello foo! Welcome to Razor!", output);
}
示例9: ComplexTypeSerializesAsOData
public void ComplexTypeSerializesAsOData()
{
// Arrange
ObjectContent<Person> content = new ObjectContent<Person>(new Person(0, new ReferenceDepthContext(7)),
_formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
// Act & Assert
JsonAssert.Equal(Resources.PersonComplexType, content.ReadAsStringAsync().Result);
}
示例10: render_template_with_embedded_layout
public void render_template_with_embedded_layout()
{
var view = new View("Test2", new { Name = "foo" });
var content = new ObjectContent<View>(view, _formatter);
var output = content.ReadAsStringAsync().Result;
Assert.AreEqual("<html>Hello foo! Welcome to Razor!</html>", output);
}
示例11: render_template_with_specified_resolver
public void render_template_with_specified_resolver()
{
var resolver = new EmbeddedResolver(this.GetType());
var formatter = new HtmlMediaTypeViewFormatter(null, new RazorViewLocator(), new RazorViewParser(resolver));
var view = new View("Test2", new { Name = "foo" });
var content = new ObjectContent<View>(view, formatter);
var output = content.ReadAsStringAsync().Result;
Assert.AreEqual("<html>Hello foo! Welcome to Razor!</html>", output);
}
示例12: EntityTypeSerializesAsODataEntry
public void EntityTypeSerializesAsODataEntry()
{
// Arrange
ODataMediaTypeFormatter formatter = CreateFormatter();
Employee employee = (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee);
ObjectContent<Employee> content = new ObjectContent<Employee>(employee, formatter,
ODataMediaTypes.ApplicationJsonODataMinimalMetadata);
// Act & Assert
JsonAssert.Equal(Resources.EmployeeEntry, content.ReadAsStringAsync().Result);
}
示例13: ListOfStringsSerializesAsOData
public void ListOfStringsSerializesAsOData()
{
List<string> listOfStrings = new List<string>();
listOfStrings.Add("Frank");
listOfStrings.Add("Steve");
listOfStrings.Add("Tom");
listOfStrings.Add("Chandler");
ObjectContent<List<string>> content = new ObjectContent<List<string>>(listOfStrings, _formatter);
Assert.Xml.Equal(BaselineResource.TestListOfStrings, content.ReadAsStringAsync().Result);
}
示例14: CollectionOfObjectsSerializesAsOData
public void CollectionOfObjectsSerializesAsOData()
{
Collection<object> collectionOfObjects = new Collection<object>();
collectionOfObjects.Add(1);
collectionOfObjects.Add("Frank");
collectionOfObjects.Add(TypeInitializer.GetInstance(SupportedTypes.Person, 2));
collectionOfObjects.Add(TypeInitializer.GetInstance(SupportedTypes.Employee, 3));
ObjectContent<Collection<object>> content = new ObjectContent<Collection<object>>(collectionOfObjects, _formatter);
Assert.Throws<ODataException>(() => content.ReadAsStringAsync().Result);
}
示例15: CollectionOfComplexTypeSerializesAsOData
public void CollectionOfComplexTypeSerializesAsOData()
{
IEnumerable<Person> collectionOfPerson = new Collection<Person>()
{
(Person)TypeInitializer.GetInstance(SupportedTypes.Person, 0),
(Person)TypeInitializer.GetInstance(SupportedTypes.Person, 1),
(Person)TypeInitializer.GetInstance(SupportedTypes.Person, 2)
};
ObjectContent<IEnumerable<Person>> content = new ObjectContent<IEnumerable<Person>>(collectionOfPerson, _formatter);
Assert.Xml.Equal(BaselineResource.TestCollectionOfPerson, content.ReadAsStringAsync().Result);
}