本文整理汇总了C#中DataServiceContext.RegisterStreamCustomizer方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.RegisterStreamCustomizer方法的具体用法?C# DataServiceContext.RegisterStreamCustomizer怎么用?C# DataServiceContext.RegisterStreamCustomizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataServiceContext
的用法示例。
在下文中一共展示了DataServiceContext.RegisterStreamCustomizer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NamedStreams_PayloadDrivenMaterialization
public void NamedStreams_PayloadDrivenMaterialization()
{
// Make sure DSSL properties can materialized and populated with the right url in non-projection cases
{
// Testing without projections (payload driven) and making sure one is able to project out the stream url
DataServiceContext context = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
context.EnableAtom = true;
context.Format.UseAtom();
context.IgnoreMissingProperties = true;
var q = context.CreateQuery<EntityWithStreamLink>("MySet1");
object entity = null;
foreach (EntityWithStreamLink o in q)
{
Assert.IsNotNull(o.Stream1, "Stream1 must have some value");
Assert.AreEqual(o.Stream1.EditLink, context.GetReadStreamUri(o, "Stream1"), "the value in the entity descriptor must match with the property value");
Assert.IsNull(o.SomeRandomProperty, "SomeRandomProperty must be null, since the payload does not have the link with the property name");
entity = o;
}
// Try updating the entity and make sure that the link is not send back in the payload.
context.UpdateObject(entity);
WrappingStream wrappingStream = null;
context.RegisterStreamCustomizer((inputStream) =>
{
wrappingStream = new WrappingStream(inputStream);
return wrappingStream;
},
null);
try
{
context.SaveChanges();
Assert.Fail("Save changes should throw an exception");
}
catch (Exception)
{
// do nothing
}
string payload = wrappingStream.GetLoggingStreamAsString();
Assert.IsTrue(payload.Contains("<d:ID m:type=\"Int32\">1</d:ID>"), "Id element must be present");
Assert.IsFalse(payload.Contains("Stream1Url"), "link url should not be sent in the payload");
}
}