本文整理汇总了C#中Microsoft.OData.Core.ODataMessageWriterSettings.SetServiceDocumentUri方法的典型用法代码示例。如果您正苦于以下问题:C# ODataMessageWriterSettings.SetServiceDocumentUri方法的具体用法?C# ODataMessageWriterSettings.SetServiceDocumentUri怎么用?C# ODataMessageWriterSettings.SetServiceDocumentUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.ODataMessageWriterSettings
的用法示例。
在下文中一共展示了ODataMessageWriterSettings.SetServiceDocumentUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriterSettingsIntegrationTest
public void WriterSettingsIntegrationTest()
{
var settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(ServiceDocumentUri);
settings.MetadataDocumentUri.Should().Equals(ServiceDocumentUri + "/$metadata");
settings.SetServiceDocumentUri(null);
settings.MetadataDocumentUri.Should().BeNull();
}
示例2: WriteObject_Calls_CreateODataComplexValue
public void WriteObject_Calls_CreateODataComplexValue()
{
// Arrange
MemoryStream stream = new MemoryStream();
IODataResponseMessage message = new ODataMessageWrapper(stream);
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri("http://any/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter messageWriter = new ODataMessageWriter(message, settings);
Mock<ODataComplexTypeSerializer> serializer = new Mock<ODataComplexTypeSerializer>(new DefaultODataSerializerProvider());
ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "ComplexPropertyName", Model = _model };
object graph = new object();
ODataComplexValue complexValue = new ODataComplexValue
{
TypeName = "NS.Name",
Properties = new[] { new ODataProperty { Name = "Property1", Value = 42 } }
};
serializer.CallBase = true;
serializer.Setup(s => s.CreateODataComplexValue(graph, It.Is<IEdmComplexTypeReference>(e => e.Definition == _addressType), writeContext))
.Returns(complexValue).Verifiable();
// Act
serializer.Object.WriteObject(graph, typeof(Address), messageWriter, writeContext);
// Assert
serializer.Verify();
stream.Seek(0, SeekOrigin.Begin);
XElement element = XElement.Load(stream);
Assert.Equal("value", element.Name.LocalName);
Assert.Equal("#NS.Name", element.Attributes().Single(a => a.Name.LocalName == "type").Value);
Assert.Equal(1, element.Descendants().Count());
Assert.Equal("42", element.Descendants().Single().Value);
Assert.Equal("Property1", element.Descendants().Single().Name.LocalName);
}
示例3: Init
public void Init()
{
model = new EdmModel();
stream = new MemoryStream();
settings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true, Version = ODataVersion.V4 };
settings.SetServiceDocumentUri(new Uri("http://example.com"));
}
示例4: WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue
public void WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue()
{
// Arrange
MemoryStream stream = new MemoryStream();
IODataResponseMessage message = new ODataMessageWrapper(stream);
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri("http://any/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter messageWriter = new ODataMessageWriter(message, settings);
Mock<ODataCollectionSerializer> serializer = new Mock<ODataCollectionSerializer>(new DefaultODataSerializerProvider());
ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "CollectionName", Model = _model };
IEnumerable enumerable = new object[0];
ODataCollectionValue collectionValue = new ODataCollectionValue { TypeName = "NS.Name", Items = new[] { 0, 1, 2 } };
serializer.CallBase = true;
serializer
.Setup(s => s.CreateODataCollectionValue(enumerable, It.Is<IEdmTypeReference>(e => e.Definition == _edmIntType.Definition), writeContext))
.Returns(collectionValue).Verifiable();
// Act
serializer.Object.WriteObject(enumerable, typeof(int[]), messageWriter, writeContext);
// Assert
serializer.Verify();
stream.Seek(0, SeekOrigin.Begin);
XElement element = XElement.Load(stream);
Assert.Equal("value", element.Name.LocalName);
Assert.Equal(3, element.Descendants().Count());
Assert.Equal(new[] { "0", "1", "2" }, element.Descendants().Select(e => e.Value));
}
示例5: 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.AreEqual("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);
}
示例6: ODataWorkspaceSerializer_Works
public void ODataWorkspaceSerializer_Works()
{
// Arrange
ODataServiceDocumentSerializer serializer = new ODataServiceDocumentSerializer();
MemoryStream stream = new MemoryStream();
IODataResponseMessage message = new ODataMessageWrapper(stream);
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri("http://any/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter writer = new ODataMessageWriter(message, settings);
// Act
serializer.WriteObject(new ODataServiceDocument(), _workspaceType, writer, new ODataSerializerContext());
// Assert
stream.Seek(0, SeekOrigin.Begin);
XElement element = XElement.Load(stream);
Assert.Equal("service", element.Name.LocalName);
}
示例7: JsonPaddingEnabledWithUserSpecifiedContentType
public void JsonPaddingEnabledWithUserSpecifiedContentType()
{
var settings = new ODataMessageWriterSettings {JsonPCallback = "functionName", DisableMessageStreamDisposal = true};
settings.SetServiceDocumentUri(new Uri("http://stuff"));
IODataResponseMessage message = new InMemoryMessage {StatusCode = 200, Stream = new MemoryStream()};
message.SetHeader("Content-Type", "application/json");
var property = new ODataProperty {Name = "PropertyName", Value = "value"};
using (var writer = new ODataMessageWriter(message, settings))
{
writer.WriteProperty(property);
}
var responseStream = message.GetStream();
responseStream.Position = 0;
var responseString = new StreamReader(responseStream).ReadToEnd();
responseString.Should().Be("functionName({\"@odata.context\":\"http://stuff/$metadata#Edm.String\",\"value\":\"value\"})");
message.GetHeader("Content-Type").Should().StartWith("text/javascript");
}
示例8: WriteAnnotationsAndValidatePayload
protected void WriteAnnotationsAndValidatePayload(Action<ODataWriter> action, ODataFormat format, string expectedPayload, bool request, bool createFeedWriter)
{
var writerSettings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true, EnableAtom = true };
writerSettings.SetContentType(format);
writerSettings.SetServiceDocumentUri(new Uri("http://www.example.com/"));
MemoryStream stream = new MemoryStream();
if (request)
{
IODataRequestMessage requestMessageToWrite = new InMemoryMessage { Method = "GET", Stream = stream };
using (var messageWriter = new ODataMessageWriter(requestMessageToWrite, writerSettings, Model))
{
ODataWriter odataWriter = createFeedWriter ? messageWriter.CreateODataFeedWriter(EntitySet, EntityType) : messageWriter.CreateODataEntryWriter(EntitySet, EntityType);
action(odataWriter);
}
}
else
{
IODataResponseMessage responseMessageToWrite = new InMemoryMessage { StatusCode = 200, Stream = stream };
using (var messageWriter = new ODataMessageWriter(responseMessageToWrite, writerSettings, Model))
{
ODataWriter odataWriter = createFeedWriter ? messageWriter.CreateODataFeedWriter(EntitySet, EntityType) : messageWriter.CreateODataEntryWriter(EntitySet, EntityType);
action(odataWriter);
}
}
stream.Position = 0;
string payload = (new StreamReader(stream)).ReadToEnd();
if (format == ODataFormat.Atom)
{
// The <updated> element is computed dynamically, so we remove it from the both the baseline and the actual payload.
payload = Regex.Replace(payload, "<updated>[^<]*</updated>", "");
expectedPayload = Regex.Replace(expectedPayload, "<updated>[^<]*</updated>", "");
}
Assert.AreEqual(expectedPayload, payload);
}
示例9: Read_RoundTrips
public void Read_RoundTrips()
{
// Arrange
var deserializer = new ODataEntityReferenceLinkDeserializer();
MockODataRequestMessage requestMessage = new MockODataRequestMessage();
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri("http://any/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter messageWriter = new ODataMessageWriter(requestMessage, settings);
messageWriter.WriteEntityReferenceLink(new ODataEntityReferenceLink { Url = new Uri("http://localhost/samplelink") });
ODataMessageReader messageReader = new ODataMessageReader(new MockODataRequestMessage(requestMessage));
ODataDeserializerContext context = new ODataDeserializerContext
{
Request = new HttpRequestMessage(),
Path = new ODataPath(new NavigationPathSegment(GetNavigationProperty(CreateModel())))
};
// Act
Uri uri = deserializer.Read(messageReader, typeof(Uri), context) as Uri;
// Assert
Assert.NotNull(uri);
Assert.Equal("http://localhost/samplelink", uri.AbsoluteUri);
}
示例10: WriterEntry
private string WriterEntry(IEdmModel userModel, ODataEntry entry, EdmEntitySet entitySet, IEdmEntityType entityType, bool fullMetadata = false)
{
var message = new InMemoryMessage() { Stream = new MemoryStream() };
var writerSettings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true, AutoComputePayloadMetadataInJson = true };
writerSettings.SetContentType(ODataFormat.Json);
writerSettings.SetServiceDocumentUri(new Uri("http://www.example.com"));
writerSettings.SetContentType(fullMetadata ?
"application/json;odata.metadata=full;odata.streaming=false" :
"application/json;odata.metadata=minimal;odata.streaming=false", "utf-8");
using (var msgReader = new ODataMessageWriter((IODataResponseMessage)message, writerSettings, userModel))
{
var writer = msgReader.CreateODataEntryWriter(entitySet, entityType);
writer.WriteStart(entry);
writer.WriteEnd();
}
message.Stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(message.Stream))
{
return reader.ReadToEnd();
}
}
示例11: WriteJsonLightEntry
private static string WriteJsonLightEntry(bool isRequest, Uri serviceDocumentUri, bool specifySet,
ODataEntry odataEntry, IEdmNavigationSource entitySet, IEdmEntityType entityType, ODataUri odataUri)
{
var model = new EdmModel();
model.AddElement(new EdmEntityContainer("Fake", "Container_sub"));
var stream = new MemoryStream();
var message = new InMemoryMessage { Stream = stream };
var settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, AutoComputePayloadMetadataInJson = true };
settings.ODataUri = odataUri;
settings.SetServiceDocumentUri(serviceDocumentUri);
settings.SetContentType(ODataFormat.Json);
settings.SetContentType("application/json;odata.metadata=full", null);
ODataMessageWriter messageWriter;
if (isRequest)
{
messageWriter = new ODataMessageWriter((IODataRequestMessage)message, settings, TestUtils.WrapReferencedModelsToMainModel("Fake", "Container", model));
}
else
{
messageWriter = new ODataMessageWriter((IODataResponseMessage)message, settings, TestUtils.WrapReferencedModelsToMainModel("Fake", "Container", model));
}
var entryWriter = messageWriter.CreateODataEntryWriter(specifySet ? entitySet : null, entityType);
entryWriter.WriteStart(odataEntry);
entryWriter.WriteEnd();
entryWriter.Flush();
var actual = Encoding.UTF8.GetString(stream.ToArray());
return actual;
}
示例12: WriteODataEntry
private string WriteODataEntry(ODataEntry entryToWrite)
{
var writerSettings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true };
writerSettings.SetContentType(ODataFormat.Json);
writerSettings.SetServiceDocumentUri(new Uri("http://www.example.com/"));
MemoryStream stream = new MemoryStream();
IODataRequestMessage requestMessageToWrite = new InMemoryMessage { Method = "GET", Stream = stream };
using (var messageWriter = new ODataMessageWriter(requestMessageToWrite, writerSettings, this.model))
{
ODataWriter odataWriter = messageWriter.CreateODataEntryWriter(this.entitySet, this.entityType);
odataWriter.WriteStart(entryToWrite);
odataWriter.WriteEnd();
}
stream.Position = 0;
string payload = (new StreamReader(stream)).ReadToEnd();
return payload;
}
示例13: CreateJsonLightOutputContext
private ODataJsonLightOutputContext CreateJsonLightOutputContext(MemoryStream stream)
{
ODataMessageWriterSettings settings = new ODataMessageWriterSettings { Version = ODataVersion.V4 };
settings.SetServiceDocumentUri(new Uri("http://example.com/"));
return new ODataJsonLightOutputContext(
ODataFormat.Json,
new NonDisposingStream(stream),
new ODataMediaType("application", "json"),
Encoding.UTF8,
settings,
/*writingResponse*/ true,
/*synchronous*/ true,
this.model,
/*urlResolver*/ null);
}
示例14: WriteAndValidateContextUri
private void WriteAndValidateContextUri(ODataFormat odataFormat, EdmModel edmModel, Action<ODataMessageWriter> test, string expectedUri, out string payload, out string contentType)
{
var message = new InMemoryMessage() { Stream = new MemoryStream() };
var writerSettings = new ODataMessageWriterSettings
{
DisableMessageStreamDisposal = true,
PayloadBaseUri = new Uri(TestBaseUri),
AutoComputePayloadMetadataInJson = true,
EnableAtom = true
};
writerSettings.SetServiceDocumentUri(new Uri(TestBaseUri));
writerSettings.SetContentType(odataFormat);
using (var msgWriter = new ODataMessageWriter((IODataResponseMessage)message, writerSettings, edmModel))
{
test(msgWriter);
}
message.Stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(message.Stream))
{
contentType = message.GetHeader("Content-Type");
payload = reader.ReadToEnd();
payload.Should().Contain(expectedUri);
}
}
示例15: WriteAtomEntry
private string WriteAtomEntry(ODataEntry entry)
{
MemoryStream stream = new MemoryStream();
InMemoryMessage message = new InMemoryMessage { Stream = stream };
var settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, AutoComputePayloadMetadataInJson = true, EnableAtom = true};
settings.SetServiceDocumentUri(new Uri("http://temp.org/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter messageWriter = new ODataMessageWriter((IODataResponseMessage)message, settings, Model);
var entryWriter = messageWriter.CreateODataEntryWriter(EntitySet, EntityType);
entryWriter.WriteStart(entry);
entryWriter.WriteEnd();
entryWriter.Flush();
var actual = Encoding.UTF8.GetString(stream.ToArray());
return actual;
}