本文整理汇总了C#中Microsoft.OData.Core.ODataNavigationLink类的典型用法代码示例。如果您正苦于以下问题:C# ODataNavigationLink类的具体用法?C# ODataNavigationLink怎么用?C# ODataNavigationLink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataNavigationLink类属于Microsoft.OData.Core命名空间,在下文中一共展示了ODataNavigationLink类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitTest
public void InitTest()
{
this.navigationLink = new ODataNavigationLink();
var entry = new ODataEntry
{
TypeName = "ns.DerivedType",
Properties = new[]
{
new ODataProperty{Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo{PropertyKind = ODataPropertyKind.Key}},
new ODataProperty{Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo{PropertyKind = ODataPropertyKind.ETag}}
}
};
var serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType" };
var typeContext = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
var metadataContext = new TestMetadataContext();
var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
var metadataBuilder = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));
this.navigationLinkWithFullBuilder = new ODataNavigationLink { Name = "NavProp" };
this.navigationLinkWithFullBuilder.MetadataBuilder = metadataBuilder;
this.navigationLinkWithNoOpBuilder = new ODataNavigationLink { Name = "NavProp" };
this.navigationLinkWithNoOpBuilder.MetadataBuilder = new NoOpEntityMetadataBuilder(entry);
this.navigationLinkWithNullBuilder = new ODataNavigationLink { Name = "NavProp" };
this.navigationLinkWithNullBuilder.MetadataBuilder = ODataEntityMetadataBuilder.Null;
}
示例2: CreateLink
/// <summary>
/// Creates the materializer link with a feed.
/// </summary>
/// <param name="link">The link.</param>
/// <param name="feed">The feed.</param>
/// <returns>The materializer link.</returns>
public static MaterializerNavigationLink CreateLink(ODataNavigationLink link, ODataFeed feed)
{
Debug.Assert(link.GetAnnotation<MaterializerNavigationLink>() == null, "there should be no MaterializerNavigationLink annotation on the feed link yet");
MaterializerNavigationLink materializedNavigationLink = new MaterializerNavigationLink(link, feed);
link.SetAnnotation<MaterializerNavigationLink>(materializedNavigationLink);
return materializedNavigationLink;
}
示例3: DefaultValuesTest
public void DefaultValuesTest()
{
ODataNavigationLink navigationLink = new ODataNavigationLink();
this.Assert.IsNull(navigationLink.Name, "Expected null default value for property 'Name'.");
this.Assert.IsNull(navigationLink.Url, "Expected null default value for property 'Url'.");
this.Assert.IsNull(navigationLink.IsCollection, "Expected null default value for property 'IsCollection'.");
}
示例4: MaterializerNavigationLink
/// <summary>
/// Prevents a default instance of the <see cref="MaterializerNavigationLink"/> struct from being created.
/// </summary>
/// <param name="link">The link.</param>
/// <param name="materializedFeedOrEntry">Value of the link.</param>
private MaterializerNavigationLink(ODataNavigationLink link, object materializedFeedOrEntry)
{
Debug.Assert(link != null, "link != null");
Debug.Assert(materializedFeedOrEntry != null, "materializedFeedOrEntry != null");
Debug.Assert(materializedFeedOrEntry is MaterializerEntry || materializedFeedOrEntry is ODataFeed, "must be feed or entry");
this.link = link;
this.feedOrEntry = materializedFeedOrEntry;
}
示例5: DataServiceODataWriterNavigationLinkArgs
/// <summary>
/// Creates a new instance of DataServiceODataWriterNavigationLinkArgs.
/// </summary>
/// <param name="navigationLink">Instance of ODataNavigationLink.</param>
/// <param name="operationContext">Instance of DataServiceOperationContext.</param>
public DataServiceODataWriterNavigationLinkArgs(
ODataNavigationLink navigationLink,
DataServiceOperationContext operationContext)
{
WebUtil.CheckArgumentNull(navigationLink, "navigationLink != null");
Debug.Assert(operationContext != null, "navigationLink != null");
this.NavigationLink = navigationLink;
this.OperationContext = operationContext;
}
示例6: WritingNavigationLinkArgs
/// <summary>
/// Initializes a new instance of the <see cref="WritingNavigationLinkArgs"/> class.
/// </summary>
/// <param name="link">The link.</param>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
public WritingNavigationLinkArgs(ODataNavigationLink link, object source, object target)
{
Util.CheckArgumentNull(link, "link");
Util.CheckArgumentNull(source, "source");
Util.CheckArgumentNull(target, "target");
this.Link = link;
this.Source = source;
this.Target = target;
}
示例7: VisitNavigationLink
protected override void VisitNavigationLink(ODataNavigationLink navigationLink)
{
bool? expectedIsCollectionValue;
if (this.expectedIsCollectionValues != null && this.expectedIsCollectionValues.TryGetValue(navigationLink.Name, out expectedIsCollectionValue))
{
this.assertionHandler.AreEqual(
expectedIsCollectionValue,
navigationLink.IsCollection,
"Value for IsCollection on NavigationLink '{0}' is unexpected",
navigationLink.Name);
}
base.VisitNavigationLink(navigationLink);
}
示例8: ValidateShortIntegrationFeedReading
public void ValidateShortIntegrationFeedReading()
{
var initialFeed = new ODataFeed() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products")};
var productItem = new ODataEntry() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products(0)")};
productItem.Properties = new ODataProperty[] {new ODataProperty() {Name = "Id", Value = 0}};
var categoryNavigationLink = new ODataNavigationLink() {Name = "Category"};
var categoryItem = new ODataEntry() { Id = new Uri("http://services.odata.org/OData/OData.svc/Categories(0)") };
categoryItem.Properties = new ODataProperty[] { new ODataProperty() { Name = "Id", Value = 0 } };
var productsNavigationLink = new ODataNavigationLink() { Name = "Products" };
var supplierNavigationLink = new ODataNavigationLink() { Name = "Supplier" };
var testODataReader = new TestODataReader()
{
new TestODataReaderItem(ODataReaderState.FeedStart, initialFeed),
new TestODataReaderItem(ODataReaderState.EntryStart, productItem),
new TestODataReaderItem(ODataReaderState.NavigationLinkStart, categoryNavigationLink),
new TestODataReaderItem(ODataReaderState.EntryStart, categoryItem),
new TestODataReaderItem(ODataReaderState.NavigationLinkStart, productsNavigationLink),
new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, productsNavigationLink),
new TestODataReaderItem(ODataReaderState.EntryEnd, categoryItem),
new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, categoryNavigationLink),
new TestODataReaderItem(ODataReaderState.NavigationLinkStart, supplierNavigationLink),
new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, supplierNavigationLink),
new TestODataReaderItem(ODataReaderState.EntryEnd, productItem),
new TestODataReaderItem(ODataReaderState.FeedEnd, initialFeed),
};
ClientEdmModel clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);
var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext());
var odataReaderWrapper = ODataReaderWrapper.CreateForTest(testODataReader, responsePipeline);
FeedAndEntryMaterializerAdapter reader = new FeedAndEntryMaterializerAdapter(ODataFormat.Atom, odataReaderWrapper, clientEdmModel, MergeOption.OverwriteChanges);
int readCounter = 0;
while (reader.Read())
{
readCounter++;
}
readCounter.Should().Be(2);
}
示例9: PropertySettersNullTest
public void PropertySettersNullTest()
{
ODataNavigationLink navigationLink = new ODataNavigationLink()
{
Name = "NewLink",
Url = new Uri("http://odata.org"),
IsCollection = true,
};
navigationLink.Name = null;
navigationLink.Url = null;
navigationLink.IsCollection = null;
this.Assert.IsNull(navigationLink.Name, "Expected null value for property 'Name'.");
this.Assert.IsNull(navigationLink.Url, "Expected null value for property 'Url'.");
this.Assert.IsNull(navigationLink.Url, "Expected null value for property 'IsCollection'.");
}
示例10: PropertyGettersAndSettersTest
public void PropertyGettersAndSettersTest()
{
string name = "ODataNavigationLink";
Uri url = new Uri("http://odatatest.org/");
bool isCollection = true;
ODataNavigationLink navigationLink = new ODataNavigationLink()
{
Name = name,
Url = url,
IsCollection = isCollection,
};
this.Assert.AreEqual(name, navigationLink.Name, "Expected equal name values.");
this.Assert.AreSame(url, navigationLink.Url, "Expected reference equal values for property 'Url'.");
this.Assert.AreEqual(isCollection, navigationLink.IsCollection, "Expected equal values for property 'IsCollection'");
}
示例11: CheckForDuplicateNavigationLinkNameAndSetAssociationLink
/// <summary>Checks for duplicate navigation links and if there already is an association link with the same name
/// sets the association link URL on the navigation link.</summary>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker for the current scope.</param>
/// <param name="navigationLink">The navigation link to be checked.</param>
/// <param name="isExpanded">true if the link is expanded, false otherwise.</param>
/// <param name="isCollection">true if the navigation link is a collection, false if it's a singleton or null if we don't know.</param>
internal static void CheckForDuplicateNavigationLinkNameAndSetAssociationLink(
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ODataNavigationLink navigationLink,
bool isExpanded,
bool? isCollection)
{
Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
Debug.Assert(navigationLink != null, "navigationLink != null");
Uri associationLinkUrl = duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(navigationLink, isExpanded, isCollection);
// We must not set the AssociationLinkUrl to null since that would disable templating on it, but we want templating to work if the association link was not in the payload.
if (associationLinkUrl != null && navigationLink.AssociationLinkUrl == null)
{
navigationLink.AssociationLinkUrl = associationLinkUrl;
}
}
示例12: ValidatePropertyMatch
/// <summary>
/// Validates the specified <paramref name="property"/> matches
/// the parsed <paramref name="link"/>.
/// </summary>
/// <param name="property">Property as understood by the type system.</param>
/// <param name="link">Property as parsed.</param>
/// <param name="model">Client Model.</param>
/// <param name="performEntityCheck">whether to do the entity check or not.</param>
/// <returns>The type</returns>
internal static Type ValidatePropertyMatch(ClientPropertyAnnotation property, ODataNavigationLink link, ClientEdmModel model, bool performEntityCheck)
{
Debug.Assert(property != null, "property != null");
Debug.Assert(link != null, "link != null");
Type propertyType = null;
if (link.IsCollection.HasValue)
{
if (link.IsCollection.Value)
{
// We need to fail if the payload states that the property is a navigation collection property
// and in the client, the property is not a collection property.
if (!property.IsEntityCollection)
{
throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_MismatchAtomLinkFeedPropertyNotCollection(property.PropertyName));
}
propertyType = property.EntityCollectionItemType;
}
else
{
if (property.IsEntityCollection)
{
throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_MismatchAtomLinkEntryPropertyIsCollection(property.PropertyName));
}
propertyType = property.PropertyType;
}
}
// If the server type and the client type does not match, we need to throw.
// This is a breaking change from V1/V2 where we allowed materialization of entities into non-entities and vice versa
if (propertyType != null && performEntityCheck)
{
if (!ClientTypeUtil.TypeIsEntity(propertyType, model))
{
throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidNonEntityType(propertyType.ToString()));
}
}
return propertyType;
}
示例13: WriteNavigationLinks
private static void WriteNavigationLinks(ODataWriter writer, object element, Uri parentEntryUri, IEdmEntityType parentEntityType, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties)
{
foreach (var navigationProperty in parentEntityType.NavigationProperties())
{
IEdmTypeReference propertyTypeReference = navigationProperty.Type;
bool isCollection = navigationProperty.Type.IsCollection();
var navigationLink = new ODataNavigationLink
{
Url = new Uri(parentEntryUri, navigationProperty.Name),
IsCollection = isCollection,
Name = navigationProperty.Name,
};
writer.WriteStart(navigationLink);
if (expandedNavigationProperties.Contains(navigationProperty.Name))
{
var propertyValue = DataContext.GetPropertyValue(element, navigationProperty.Name);
if (propertyValue != null)
{
var propertyEntityType = propertyTypeReference.Definition as IEdmEntityType;
IEdmEntitySet targetEntitySet = model.EntityContainer.EntitySets().Single(s => s.EntityType() == propertyEntityType);
if (isCollection)
{
WriteFeed(writer, propertyValue as IEnumerable, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
}
else
{
WriteEntry(writer, propertyValue, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
}
}
}
writer.WriteEnd();
}
}
示例14: WriteStartAsync
/// <summary>
/// Asynchronously start writing a navigation link.
/// </summary>
/// <param name="navigationLink">The navigation link to write.</param>
/// <returns>A task instance that represents the asynchronous write operation.</returns>
public abstract Task WriteStartAsync(ODataNavigationLink navigationLink);
示例15: WriteStart
/// <summary>
/// Start writing a navigation link.
/// </summary>
/// <param name="navigationLink">The navigation link to write.</param>
public abstract void WriteStart(ODataNavigationLink navigationLink);