本文整理汇总了C#中ODataEntry类的典型用法代码示例。如果您正苦于以下问题:C# ODataEntry类的具体用法?C# ODataEntry怎么用?C# ODataEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataEntry类属于命名空间,在下文中一共展示了ODataEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InjectMetadataBuilderShouldNotSetBuilderOnEntry
public void InjectMetadataBuilderShouldNotSetBuilderOnEntry()
{
var entry = new ODataEntry();
var builder = new TestEntityMetadataBuilder(entry);
testSubject.InjectMetadataBuilder(entry, builder);
entry.MetadataBuilder.Should().BeOfType<NoOpEntityMetadataBuilder>();
}
示例2: ReadLinkShouldNotBeOmittedWhenNotIdenticalToEditLink
public void ReadLinkShouldNotBeOmittedWhenNotIdenticalToEditLink()
{
DateTimeOffset updatedTime = DateTimeOffset.UtcNow;
var entry = new ODataEntry
{
Id = new Uri("http://test.org/EntitySet('1')"),
EditLink = new Uri("http://test.org/EntitySet('1')/edit"),
ReadLink = new Uri("http://test.org/EntitySet('1')/read")
};
entry.SetAnnotation(new AtomEntryMetadata() { Updated = updatedTime });
string actual = this.WriteAtomEntry(entry);
string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://temp.org/$metadata#EntitySet/$entity\">" +
"<id>http://test.org/EntitySet('1')</id>" +
"<link rel=\"edit\" href=\"http://test.org/EntitySet('1')/edit\" />" +
"<link rel=\"self\" href=\"http://test.org/EntitySet('1')/read\" />" +
"<title />" +
"<updated>" + ODataAtomConvert.ToAtomString(updatedTime) + "</updated>" +
"<author>" +
"<name />" +
"</author>" +
"<content type=\"application/xml\" />" +
"</entry>";
Assert.Equal(expected, actual);
}
示例3: WriteCompletedAsyncResponse
public void WriteCompletedAsyncResponse()
{
var asyncWriter = this.TestInit();
var innerMessage = asyncWriter.CreateResponseMessage();
innerMessage.StatusCode = 200;
innerMessage.SetHeader("Content-Type", "application/json");
var settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri(ServiceDocumentUri));
settings.DisableMessageStreamDisposal = true;
using (var innerMessageWriter = new ODataMessageWriter(innerMessage, settings, this.userModel))
{
var entryWriter = innerMessageWriter.CreateODataEntryWriter(singleton, testType);
var entry = new ODataEntry() {TypeName = "NS.Test", Properties = new[] {new ODataProperty() {Name = "Id", Value = 1}}};
entryWriter.WriteStart(entry);
entryWriter.WriteEnd();
}
asyncWriter.Flush();
var payload = this.TestFinish();
Assert.Equal("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nOData-Version: 4.0\r\n\r\n{\"@odata.context\":\"http://host/service/$metadata#MySingleton\",\"Id\":1}", payload);
}
示例4: ODataEntryMetadataContextTest
public ODataEntryMetadataContextTest()
{
this.entry = new ODataEntry {TypeName = ActualEntityType.FullName()};
this.typeContext = new TestFeedAndEntryTypeContext();
this.entryMetadataContextWithoutModel = ODataEntryMetadataContext.Create(this.entry, this.typeContext, new ODataFeedAndEntrySerializationInfo(), /*actualEntityType*/null, new TestMetadataContext(), SelectedPropertiesNode.EntireSubtree);
this.entryMetadataContextWithModel = ODataEntryMetadataContext.Create(this.entry, this.typeContext, /*serializationInfo*/null, ActualEntityType, new TestMetadataContext(), SelectedPropertiesNode.EntireSubtree);
}
示例5: EntryMetadataUrlRoundTrip
public void EntryMetadataUrlRoundTrip()
{
var stream = new MemoryStream();
var writerRequestMemoryMessage = new InMemoryMessage();
writerRequestMemoryMessage.Stream = stream;
writerRequestMemoryMessage.SetHeader("Content-Type", "application/json");
var writerSettings = new ODataMessageWriterSettings() {Version = ODataVersion.V4, DisableMessageStreamDisposal = true};
writerSettings.ODataUri = new ODataUri() {ServiceRoot = new Uri("http://christro.svc/")};
var messageWriter = new ODataMessageWriter((IODataResponseMessage)writerRequestMemoryMessage, writerSettings, this.model);
var organizationSetWriter = messageWriter.CreateODataEntryWriter(this.organizationsSet);
var odataEntry = new ODataEntry(){ TypeName = ModelNamespace + ".Corporation" };
odataEntry.Property("Id", 1);
odataEntry.Property("Name", "");
odataEntry.Property("TickerSymbol", "MSFT");
organizationSetWriter.WriteStart(odataEntry);
organizationSetWriter.WriteEnd();
var readerPayloadInput = Encoding.UTF8.GetString(stream.GetBuffer());
Console.WriteLine(readerPayloadInput);
var readerResponseMemoryMessage = new InMemoryMessage();
readerResponseMemoryMessage.Stream = new MemoryStream(stream.GetBuffer());
readerResponseMemoryMessage.SetHeader("Content-Type", "application/json");
var messageReader = new ODataMessageReader((IODataResponseMessage)readerResponseMemoryMessage, new ODataMessageReaderSettings() {MaxProtocolVersion = ODataVersion.V4, DisableMessageStreamDisposal = true}, this.model);
var organizationReader = messageReader.CreateODataEntryReader(this.organizationsSet, this.organizationsSet.EntityType());
organizationReader.Read().Should().Be(true);
organizationReader.Item.As<ODataEntry>();
}
示例6: InjectMetadataBuilderShouldSetBuilderOnEntry
public void InjectMetadataBuilderShouldSetBuilderOnEntry()
{
var entry = new ODataEntry();
var builder = new TestEntityMetadataBuilder(entry);
testSubject.InjectMetadataBuilder(entry, builder);
entry.MetadataBuilder.Should().BeSameAs(builder);
}
示例7: CreateEntryWithKeyAsSegmentConvention
private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment)
{
var model = new EdmModel();
var container = new EdmEntityContainer("Fake", "Container");
model.AddElement(container);
if (addAnnotation)
{
model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
}
EdmEntityType entityType = new EdmEntityType("Fake", "FakeType");
entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
model.AddElement(entityType);
var entitySet = new EdmEntitySet(container, "FakeSet", entityType);
container.AddElement(entitySet);
var metadataContext = new ODataMetadataContext(
true,
ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified,
new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior),
model,
new Uri("http://temp.org/$metadata"),
null /*requestUri*/);
var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}};
thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType));
thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment);
return thing;
}
示例8: ODataNavigationLinkTests
public ODataNavigationLinkTests()
{
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;
}
示例9: ShouldBeAbleToSetTheEntrySerializationInfo
public void ShouldBeAbleToSetTheEntrySerializationInfo()
{
ODataEntry entry = new ODataEntry();
ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.base", ExpectedTypeName = "ns.expected" };
entry.SetSerializationInfo(serializationInfo);
entry.SerializationInfo.Should().BeSameAs(serializationInfo);
}
示例10: GetOperationsInEntry
/// <summary>
/// Returns a hash set of operation imports (actions and functions) in the given entry.
/// </summary>
/// <param name="entry">The entry in question.</param>
/// <param name="model">The edm model to resolve operation imports.</param>
/// <param name="metadataDocumentUri">The metadata document uri.</param>
/// <returns>The hash set of operation imports (actions and functions) in the given entry.</returns>
private static HashSet<IEdmOperation> GetOperationsInEntry(ODataEntry entry, IEdmModel model, Uri metadataDocumentUri)
{
Debug.Assert(entry != null, "entry != null");
Debug.Assert(model != null, "model != null");
Debug.Assert(metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri, "metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri");
HashSet<IEdmOperation> edmOperationImportsInEntry = new HashSet<IEdmOperation>(EqualityComparer<IEdmOperation>.Default);
IEnumerable<ODataOperation> operations = ODataUtilsInternal.ConcatEnumerables((IEnumerable<ODataOperation>)entry.NonComputedActions, (IEnumerable<ODataOperation>)entry.NonComputedFunctions);
if (operations != null)
{
foreach (ODataOperation operation in operations)
{
Debug.Assert(operation.Metadata != null, "operation.Metadata != null");
string operationMetadataString = UriUtils.UriToString(operation.Metadata);
Debug.Assert(
ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString),
"ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString)");
Debug.Assert(
operationMetadataString[0] == ODataConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata),
"operationMetadataString[0] == JsonLightConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata)");
string fullyQualifiedOperationName = ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(metadataDocumentUri, operationMetadataString);
IEnumerable<IEdmOperation> edmOperations = model.ResolveOperations(fullyQualifiedOperationName);
if (edmOperations != null)
{
foreach (IEdmOperation edmOperation in edmOperations)
{
edmOperationImportsInEntry.Add(edmOperation);
}
}
}
}
return edmOperationImportsInEntry;
}
示例11: InjectMetadataBuilderShouldNotSetBuilderOnEntryMediaResource
public void InjectMetadataBuilderShouldNotSetBuilderOnEntryMediaResource()
{
var entry = new ODataEntry();
var builder = new TestEntityMetadataBuilder(entry);
entry.MediaResource = new ODataStreamReferenceValue();
testSubject.InjectMetadataBuilder(entry, builder);
entry.MediaResource.GetMetadataBuilder().Should().BeNull();
}
示例12: ShouldBeAbleToWriteTransientEntry
public void ShouldBeAbleToWriteTransientEntry()
{
IEdmEntityType entityType = GetEntityType();
IEdmEntitySet entitySet = GetEntitySet(entityType);
ODataEntry transientEntry = new ODataEntry() { IsTransient = true };
var actual = WriteJsonLightEntry(true, null, false, transientEntry, entitySet, entityType);
actual.Should().Contain("\"@odata.id\":null");
}
示例13: ODataEdmStructuredValue
/// <summary>
/// Creates a new Edm structured value from an OData entry.
/// </summary>
/// <param name="entry">The <see cref="ODataEntry"/> to create the structured value for.</param>
internal ODataEdmStructuredValue(ODataEntry entry)
: base(entry.GetEdmType())
{
Debug.Assert(entry != null, "entry != null");
this.properties = entry.NonComputedProperties;
this.structuredType = this.Type == null ? null : this.Type.AsStructured();
}
示例14: ODataEntryMetadataContext
/// <summary>
/// Constructs an instance of <see cref="ODataEntryMetadataContext"/>.
/// </summary>
/// <param name="entry">The entry instance.</param>
/// <param name="typeContext">The context object to answer basic questions regarding the type of the entry.</param>
protected ODataEntryMetadataContext(ODataEntry entry, IODataFeedAndEntryTypeContext typeContext)
{
Debug.Assert(entry != null, "entry != null");
Debug.Assert(typeContext != null, "typeContext != null");
this.entry = entry;
this.typeContext = typeContext;
}
示例15: GetIdShouldBeNullWhenEntryIsTransient
public void GetIdShouldBeNullWhenEntryIsTransient()
{
Uri id = new Uri("http://example.com");
ODataEntry odataEntry = new ODataEntry()
{
IsTransient = true,
Id = id
};
new NoOpEntityMetadataBuilder(odataEntry).GetId().Should().BeNull();
}