public void OrderFeedTest() { foreach (var mimeType in this.mimeTypes) { var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; string outputWithModel = null; string outputWithoutModel = null; var responseMessageWithModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithModel, settings, WritePayloadHelper.Model)) { var odataWriter = messageWriter.CreateODataFeedWriter(WritePayloadHelper.OrderSet, WritePayloadHelper.OrderType); outputWithModel = this.WriteAndVerifyOrderFeed(responseMessageWithModel, odataWriter, true, mimeType); } var responseMessageWithoutModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithoutModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithoutModel, settings)) { var odataWriter = messageWriter.CreateODataFeedWriter(); outputWithoutModel = this.WriteAndVerifyOrderFeed(responseMessageWithoutModel, odataWriter, false, mimeType); } WritePayloadHelper.VerifyPayloadString(outputWithModel, outputWithoutModel, mimeType); } }
public void CarEntryTest() { foreach (var mimeType in this.mimeTypes) { var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; string outputWithModel = null; string outputWithoutModel = null; var responseMessageWithModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithModel.SetHeader("Content-Type", mimeType); responseMessageWithModel.PreferenceAppliedHeader().AnnotationFilter = "*"; using (var messageWriter = new ODataMessageWriter(responseMessageWithModel, settings, WritePayloadHelper.Model)) { var odataWriter = messageWriter.CreateODataEntryWriter(WritePayloadHelper.CarSet, WritePayloadHelper.CarType); outputWithModel = this.WriteAndVerifyCarEntry(responseMessageWithModel, odataWriter, true, mimeType); } var responseMessageWithoutModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithoutModel.SetHeader("Content-Type", mimeType); responseMessageWithoutModel.PreferenceAppliedHeader().AnnotationFilter = "*"; using (var messageWriter = new ODataMessageWriter(responseMessageWithoutModel, settings)) { var odataWriter = messageWriter.CreateODataEntryWriter(); outputWithoutModel = this.WriteAndVerifyCarEntry(responseMessageWithoutModel, odataWriter, false, mimeType); } WritePayloadHelper.VerifyPayloadString(outputWithModel, outputWithoutModel, mimeType); } }
public void DerivedTypeFeedUrlConventionTest() { foreach (var mimeType in this.mimeTypes) { foreach (var hasModel in this.hasModelFlagBools) { var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; settings.PayloadBaseUri = this.ServiceUri; settings.UseKeyAsSegment = true; settings.AutoComputePayloadMetadataInJson = false; string defaultModeResult = this.WriteAndVerifyEmployeeFeed(settings, mimeType, hasModel); settings.AutoComputePayloadMetadataInJson = true; string autoComputeMetadataModeResult = this.WriteAndVerifyEmployeeFeed(settings, mimeType, hasModel); // For Atom, verify that the result is the same for AutoComputePayloadMetadataInJson=true/false if (mimeType == MimeTypes.ApplicationAtomXml) { WritePayloadHelper.VerifyPayloadString(defaultModeResult, autoComputeMetadataModeResult, mimeType); } } } }
public void ExpandedEntryTest() { foreach (var mimeType in this.mimeTypes) { foreach (var hasModel in this.hasModelFlagBools) { const string selectClause = "CustomerId,Video,Orders"; const string expandClause = "Logins($select=Username;$expand=SentMessages)"; const string expectedClause = "CustomerId,Video,Orders,Logins,Logins(Username,SentMessages)"; var uriParser = new ODataUriParser(WritePayloadHelper.Model, WritePayloadHelper.ServiceUri, new Uri(this.ServiceUri, "Customer?$select=" + selectClause + "&$expand=" + expandClause)); var result = uriParser.ParseSelectAndExpand(); var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri, SelectAndExpand = result }; settings.PayloadBaseUri = this.ServiceUri; settings.AutoComputePayloadMetadataInJson = false; string defaultModeResult = this.WriteAndVerifyExpandedCustomerEntry(settings, mimeType, expectedClause, hasModel); settings.AutoComputePayloadMetadataInJson = true; string autoComputeMetadataModeResult = this.WriteAndVerifyExpandedCustomerEntry(settings, mimeType, expectedClause, hasModel); // For Atom, verify that the result is the same for AutoComputePayloadMetadataInJson=true/false if (mimeType == MimeTypes.ApplicationAtomXml) { WritePayloadHelper.VerifyPayloadString(defaultModeResult, autoComputeMetadataModeResult, mimeType); } } } }
public void PersonFeedTest() { foreach (var mimeType in this.mimeTypes) { var settings = new ODataMessageWriterSettings() { PayloadBaseUri = this.ServiceUri }; settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; string outputWithModel = null; string outputWithoutModel = null; var responseMessageWithModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithModel, settings, WritePayloadHelper.Model)) { var odataWriter = messageWriter.CreateODataFeedWriter(WritePayloadHelper.PersonSet, WritePayloadHelper.PersonType); outputWithModel = this.WriteAndVerifyPersonFeed(responseMessageWithModel, odataWriter, true, mimeType); } var responseMessageWithoutModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithoutModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithoutModel, settings)) { var odataWriter = messageWriter.CreateODataFeedWriter(); outputWithoutModel = this.WriteAndVerifyPersonFeed(responseMessageWithoutModel, odataWriter, false, mimeType); } WritePayloadHelper.VerifyPayloadString(outputWithModel, outputWithoutModel, mimeType); if (mimeType.Contains(MimeTypes.ODataParameterMinimalMetadata) || mimeType.Contains(MimeTypes.ODataParameterFullMetadata)) { Assert.IsTrue(outputWithoutModel.Contains(this.ServiceUri + "$metadata#Person\"")); } if (mimeType.Contains(MimeTypes.ApplicationJsonLight)) { // odata.type is included in json light payload only if entry typename is different than serialization info Assert.IsFalse(outputWithoutModel.Contains("{\"@odata.type\":\"" + "#" + NameSpace + "Person\","), "odata.type Person"); Assert.IsTrue(outputWithoutModel.Contains("{\"@odata.type\":\"" + "#" + NameSpace + "Employee\","), "odata.type Employee"); Assert.IsTrue(outputWithoutModel.Contains("{\"@odata.type\":\"" + "#" + NameSpace + "SpecialEmployee\","), "odata.type SpecialEmployee"); } } }
public void ExpandedCustomerEntryTest() { foreach (var mimeType in this.mimeTypes) { var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; string outputWithModel = null; string outputWithoutModel = null; var responseMessageWithModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithModel, settings, WritePayloadHelper.Model)) { var odataWriter = messageWriter.CreateODataEntryWriter(WritePayloadHelper.CustomerSet, WritePayloadHelper.CustomerType); outputWithModel = this.WriteAndVerifyExpandedCustomerEntry(responseMessageWithModel, odataWriter, true, mimeType); } var responseMessageWithoutModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithoutModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithoutModel, settings)) { var odataWriter = messageWriter.CreateODataEntryWriter(); outputWithoutModel = this.WriteAndVerifyExpandedCustomerEntry(responseMessageWithoutModel, odataWriter, false, mimeType); } if (mimeType != MimeTypes.ApplicationAtomXml) { WritePayloadHelper.VerifyPayloadString(outputWithModel, outputWithoutModel, mimeType); } } }