本文整理汇总了C#中ODataFeed.SetSerializationInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ODataFeed.SetSerializationInfo方法的具体用法?C# ODataFeed.SetSerializationInfo怎么用?C# ODataFeed.SetSerializationInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataFeed
的用法示例。
在下文中一共展示了ODataFeed.SetSerializationInfo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToSetTheFeedSerializationInfo
public void ShouldBeAbleToSetTheFeedSerializationInfo()
{
ODataFeed feed = new ODataFeed();
ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.base", ExpectedTypeName = "ns.expected" };
feed.SetSerializationInfo(serializationInfo);
feed.SerializationInfo.Should().BeSameAs(serializationInfo);
}
示例2: ShouldBeAbleToWriteFeedAndEntryResponseInJsonLightWithoutModel
public void ShouldBeAbleToWriteFeedAndEntryResponseInJsonLightWithoutModel()
{
const string expectedPayload =
"{" +
"\"@odata.context\":\"http://www.example.com/$metadata#Customers/NS.VIPCustomer\"," +
"\"value\":[" +
"{" +
"\"Name\":\"Bob\"," +
"\"[email protected]\":\"MostRecentOrder\"," +
"\"MostRecentOrder\":{\"OrderId\":101}" +
"}" +
"]" +
"}";
var writerSettings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true };
writerSettings.SetContentType(ODataFormat.Json);
writerSettings.ODataUri = new ODataUri() { ServiceRoot = new Uri("http://www.example.com") };
MemoryStream stream = new MemoryStream();
IODataResponseMessage responseMessage = new InMemoryMessage { StatusCode = 200, Stream = stream };
// Write payload
using (var messageWriter = new ODataMessageWriter(responseMessage, writerSettings))
{
var odataWriter = messageWriter.CreateODataFeedWriter();
// Create customers feed with serializtion info to write odata.metadata.
var customersFeed = new ODataFeed();
customersFeed.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Customers", NavigationSourceEntityTypeName = "NS.Customer", ExpectedTypeName = "NS.VIPCustomer" });
// Write customers feed.
odataWriter.WriteStart(customersFeed);
// Write VIP customer
{
// Create VIP customer, don't need to pass in serialization info since the writer knows the context from the feed scope.
var vipCustomer = new ODataEntry { TypeName = "NS.VIPCustomer" };
var customerKey = new ODataProperty { Name = "Name", Value = "Bob" };
// Provide serialization info at the property level to compute the edit link.
customerKey.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key });
vipCustomer.Properties = new[] { customerKey };
// Write customer entry.
odataWriter.WriteStart(vipCustomer);
// Write expanded most recent order
{
// No API to set serialization info on ODataNavigationLink since what we are adding on ODataFeed and ODataEntry should be sufficient for the 5.5 release.
var navigationLink = new ODataNavigationLink { Name = "MostRecentOrder", IsCollection = false, Url = new Uri("MostRecentOrder", UriKind.Relative) };
odataWriter.WriteStart(navigationLink);
// Write the most recent customer.
{
var mostRecentOrder = new ODataEntry { TypeName = "NS.Order" };
// Add serialization info so we can computer links.
mostRecentOrder.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Orders", NavigationSourceEntityTypeName = "NS.Order", ExpectedTypeName = "NS.Order" });
var orderKey = new ODataProperty { Name = "OrderId", Value = 101 };
// Provide serialization info at the property level to compute the edit link.
orderKey.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key });
mostRecentOrder.Properties = new[] { orderKey };
// Write order entry.
odataWriter.WriteStart(mostRecentOrder);
odataWriter.WriteEnd();
}
// End navigationLink.
odataWriter.WriteEnd();
}
// End customer entry.
odataWriter.WriteEnd();
}
// End customers feed.
odataWriter.WriteEnd();
}
stream.Position = 0;
string payload = (new StreamReader(stream)).ReadToEnd();
payload.Should().Be(expectedPayload);
}
示例3: ODataFeed
public void WritingInMinimalMetadataModeWithExpandAndProjectionWithModelWhenAutoComputePayloadMetadataInJsonIsTrue()
{
const string expectedPayload =
"{" +
"\"@odata.context\":\"http://example.com/$metadata#EntitySet(StreamProp1,Namespace.AlwaysBindableAction1,Namespace.AlwaysBindableFunction1,DeferredNavLink,ExpandedNavLink,ExpandedNavLink(StreamProp1,Namespace.AlwaysBindableAction1,ExpandedNavLink,ExpandedNavLink(StreamProp2,Namespace.AlwaysBindableAction1)))\"," +
"\"value\":[" +
"{" +
"\"ID\":123," +
"\"Name\":\"Bob\"," +
"\"[email protected]\":\"http://example.com/expanded/association\"," +
"\"[email protected]\":\"http://example.com/expanded/navigation\"," +
"\"ExpandedNavLink\":[" +
"{" +
"\"ID\":234," +
"\"Name\":\"Foo\"," +
"\"ExpandedNavLink\":[" +
"{" +
"\"ID\":345," +
"\"Name\":\"Bar\"," +
"\"#Container.AlwaysBindableAction1\":{}" +
"}]," +
"\"#Container.AlwaysBindableAction1\":{}" +
"}]," +
"\"#Container.AlwaysBindableAction1\":{}," +
"\"#Container.AlwaysBindableFunction1\":{}" +
"}]" +
"}";
ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = EntitySet.Name, NavigationSourceEntityTypeName = EntityType.FullName(), ExpectedTypeName = EntityType.FullName() };
var feed = new ODataFeed();
feed.SetSerializationInfo(serializationInfo);
this.entryWithOnlyData = new ODataEntry
{
TypeName = EntityType.FullName(),
MediaResource = new ODataStreamReferenceValue(),
Properties = new[]
{
new ODataProperty { Name = "ID", Value = 123, SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key }},
new ODataProperty { Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.ETag }},
new ODataProperty { Name = "StreamProp1", Value = new ODataStreamReferenceValue() }
},
};
this.entryWithOnlyData.AddAction(new ODataAction { Metadata = new Uri("http://example.com/$metadata#Container.AlwaysBindableAction1") });
this.entryWithOnlyData.AddFunction(new ODataFunction { Metadata = new Uri("#Container.AlwaysBindableFunction1", UriKind.Relative) });
this.entryWithOnlyData2 = new ODataEntry
{
TypeName = EntityType.FullName(),
MediaResource = new ODataStreamReferenceValue(),
Properties = new[]
{
new ODataProperty { Name = "ID", Value = 234, SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key }},
new ODataProperty { Name = "Name", Value = "Foo", SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.ETag }},
new ODataProperty { Name = "StreamProp1", Value = new ODataStreamReferenceValue() }
},
};
this.entryWithOnlyData2.AddAction(new ODataAction { Metadata = new Uri("http://example.com/$metadata#Container.AlwaysBindableAction1") });
this.entryWithOnlyData3 = new ODataEntry
{
TypeName = EntityType.FullName(),
MediaResource = new ODataStreamReferenceValue(),
Properties = new[]
{
new ODataProperty { Name = "ID", Value = 345, SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key }},
new ODataProperty { Name = "Name", Value = "Bar", SerializationInfo = new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.ETag }},
new ODataProperty { Name = "StreamProp2", Value = new ODataStreamReferenceValue() }
},
};
this.entryWithOnlyData3.AddAction(new ODataAction { Metadata = new Uri("http://example.com/$metadata#Container.AlwaysBindableAction1") });
ODataItem[] itemsToWrite = new ODataItem[]
{
feed, this.entryWithOnlyData,
this.expandedNavLinkWithPayloadMetadata, feed, this.entryWithOnlyData2, this.navLinkWithoutPayloadMetadata,
this.expandedNavLinkWithoutPayloadMetadata, feed, this.entryWithOnlyData3
};
const string selectClause = "StreamProp1,Namespace.AlwaysBindableAction1,Namespace.AlwaysBindableFunction1,DeferredNavLink";
const string expandClause = "ExpandedNavLink($select=StreamProp1,Namespace.AlwaysBindableAction1;$expand=ExpandedNavLink($select=StreamProp2,Namespace.AlwaysBindableAction1))";
this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, edmModel: Model, edmEntitySet: null, edmEntityType: EntityType, selectClause: selectClause, expandClause: expandClause)
.Should().Be(expectedPayload);
}
示例4: ShouldWritePayloadWhenExpandedFeedAndEntryHasSerializationInfo
public void ShouldWritePayloadWhenExpandedFeedAndEntryHasSerializationInfo()
{
List<ODataItem> itemsToWrite = new List<ODataItem>();
var entry1 = new ODataEntry();
entry1.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MySet", NavigationSourceEntityTypeName = "NS.MyEntityType" });
itemsToWrite.Add(entry1);
itemsToWrite.Add(new ODataNavigationLink { Name = "EntitySetReferenceProperty", IsCollection = true });
var feed = new ODataFeed();
feed.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MySet", NavigationSourceEntityTypeName = "NS.MyEntityType" });
itemsToWrite.Add(feed);
var entry2 = new ODataEntry();
entry2.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MySet2", NavigationSourceEntityTypeName = "NS.MyEntityType2" });
itemsToWrite.Add(entry2);
const string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#MySet/$entity\",\"EntitySetReferenceProperty\":[{}]}";
this.WriteNestedItemsAndValidatePayload(entitySetFullName: null, derivedEntityTypeFullName: null, nestedItemToWrite: itemsToWrite.ToArray(), expectedPayload: expectedPayload, writingResponse: true);
}
示例5: ShouldWritePayloadWhenFeedAndEntryHasSerializationInfo
public void ShouldWritePayloadWhenFeedAndEntryHasSerializationInfo()
{
var feed = new ODataFeed();
feed.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MySet", NavigationSourceEntityTypeName = "NS.MyEntityType" });
var entry = new ODataEntry();
entry.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MySet2", NavigationSourceEntityTypeName = "NS.MyEntityType2" });
List<ODataItem> itemsToWrite = new List<ODataItem>() { feed, entry };
const string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#MySet\",\"value\":[{}]}";
this.WriteNestedItemsAndValidatePayload(entitySetFullName: null, derivedEntityTypeFullName: null, nestedItemToWrite: itemsToWrite.ToArray(), expectedPayload: expectedPayload, writingResponse: true);
}