public void ServiceDocument() { string[] types = new string[] { MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata, MimeTypes.ApplicationJson + MimeTypes.ODataParameterMinimalMetadata, MimeTypes.ApplicationJson + MimeTypes.ODataParameterNoMetadata, }; ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceBaseUri }; foreach (var mimeType in types) { var requestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri.AbsoluteUri, UriKind.Absolute)); requestMessage.SetHeader("Accept", mimeType); var responseMessage = requestMessage.GetResponse(); Assert.Equal(200, responseMessage.StatusCode); if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) { using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) { ODataServiceDocument workSpace = messageReader.ReadServiceDocument(); Assert.NotNull(workSpace.EntitySets.Single(c => c.Name == "Trucks")); Assert.Equal("GetDefaultOutsideGeoFenceAlarm", workSpace.FunctionImports.First().Name); } } } }
public void QueryServiceDocument() { string[] types = new string[] { "text/html, application/xhtml+xml, */*", MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata, MimeTypes.ApplicationJson + MimeTypes.ODataParameterMinimalMetadata, MimeTypes.ApplicationJson + MimeTypes.ODataParameterNoMetadata, }; ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceBaseUri }; foreach (var mimeType in types) { var requestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri.AbsoluteUri, UriKind.Absolute)); requestMessage.SetHeader("Accept", mimeType); var responseMessage = requestMessage.GetResponse(); Assert.AreEqual(200, responseMessage.StatusCode); if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) { using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) { ODataServiceDocument workSpace = messageReader.ReadServiceDocument(); Assert.IsNotNull(workSpace.EntitySets.Single(c => c.Name == "People")); } } } }
public async Task ServiceDocumentTest() { // Arrange var requestUri = "odata"; HttpClient client = CreateClient(); // Act var response = await client.GetAsync(requestUri); var stream = await response.Content.ReadAsStreamAsync(); //Assert var oDataMessageReaderSettings = new ODataMessageReaderSettings(); IODataResponseMessage message = new ODataMessageWrapper(stream, response.Content.Headers); var reader = new ODataMessageReader(message, oDataMessageReaderSettings, UnboundFunctionEdmModel.GetEdmModel()); var oDataWorkSpace = reader.ReadServiceDocument(); var function1 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetAllConventionCustomers"); Assert.Single(function1); var function2 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionOrderByCustomerIdAndOrderName"); // ODL spec says: // The edm:FunctionImport for a parameterless function MAY include the IncludeInServiceDocument attribute // whose Boolean value indicates whether the function import is advertised in the service document. // So the below 2 FunctionImports are not displayed in ServiceDocument. Assert.Empty(function2); var function3 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionCustomerById"); Assert.Empty(function3); }
public void ValidServiceDocument() { var metadataMessage = new HttpWebRequestMessage(new Uri(ServiceUri + "$metadata")); metadataMessage.SetHeader("Accept", MimeTypes.ApplicationXml); var metadataMessageReader = new ODataMessageReader(metadataMessage.GetResponse()); var model = metadataMessageReader.ReadMetadataDocument(); var message = new HttpWebRequestMessage(ServiceUri); message.SetHeader("Accept", MimeTypes.ApplicationJson); ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceUri }; using (var messageReader = new ODataMessageReader(message.GetResponse(), readerSettings, model)) { var workspace = messageReader.ReadServiceDocument(); Assert.AreEqual(21, workspace.EntitySets.Count(e => e.Name.StartsWith("EF"))); Assert.AreEqual(24, workspace.EntitySets.Count(e => !e.Name.StartsWith("EF"))); } }
public void ParseServiceDocument() { var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(ServiceBaseUri.AbsoluteUri, UriKind.Absolute)); var webResponse = requestMessage.GetResponse(); ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceBaseUri }; using (var messageReader = new ODataMessageReader(webResponse, readerSettings, Model)) { ODataServiceDocument workSpace = messageReader.ReadServiceDocument(); foreach (var entitySetName in entitySetsList.Keys) { Assert.IsNotNull(workSpace.EntitySets.Single(c => c.Name == entitySetName)); } } }
public void ServiceDocumentNoWhitespaceTest() { var testCases = new[] { "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<atom:title>Products</atom:title>" + "</collection>" + "<collection href='http://odata.org/Orders'>" + "<atom:title>Orders</atom:title>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<atom:title>Products</atom:title>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "</collection>" + "<collection href='http://odata.org/Orders'>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'/>" + "<collection href='http://odata.org/Orders'/>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'/>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace/>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<atom:title>Products</atom:title>" + "<accept>image/png</accept>" + "<categories href='http://somecategories.com'/>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<accept>image/png</accept>" + "<categories href='http://somecategories.com'/>" + "<atom:title>Products</atom:title>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<accept>image/png</accept>" + "<categories href='http://somecategories.com'/>" + "<atom:title>Products</atom:title>" + "</collection>" + "<collection href='http://odata.org/Orders'>" + "<accept>image/png</accept>" + "<categories href='http://somecategories.com'/>" + "<atom:title>Orders</atom:title>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<cf:cf xmlns:cf='uri'/>" + "</collection>" + "<collection href='http://odata.org/Orders'>" + "<cf:cf xmlns:cf='uri'/>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<cf:cf xmlns:cf='uri'/>" + "</collection>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<collection href='http://odata.org/Products'>" + "<cf:cf xmlns:cf='uri'/>" + "</collection>" + "<cf:cf xmlns:cf='uri'/>" + "<collection href='http://odata.org/Orders'>" + "<cf:cf xmlns:cf='uri'/>" + "</collection>" + "<cf:cf xmlns:cf='uri'/>" + "</workspace>" + "</service>", "<service xmlns:app='http://www.w3.org/2007/app' " + "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" + "<workspace>" + "<cf:cf xmlns:cf='uri'/>" + "</workspace>" + "</service>", }; this.CombinatorialEngineProvider.RunCombinations( testCases, testCase => { // Just validate that the input strings above don't include any whitespaces. using (XmlReader xmlReader = XmlReader.Create(new StringReader(testCase))) { while (xmlReader.Read()) { this.Assert.AreNotEqual(XmlNodeType.Whitespace, xmlReader.NodeType, "No whitespaces please"); this.Assert.AreNotEqual(XmlNodeType.SignificantWhitespace, xmlReader.NodeType, "No whitespaces please"); } } // Run the payload through the reader and make sure it doesn't fail. TestResponseMessage message = new TestResponseMessage(new MemoryStream(Encoding.UTF8.GetBytes(testCase))); message.SetContentType(ODataFormat.Atom, ODataPayloadKind.ServiceDocument); ODataMessageReaderSettings settings = new ODataMessageReaderSettings { EnableAtom = true }; using (ODataMessageReader messageReader = new ODataMessageReader(message, settings)) { messageReader.ReadServiceDocument(); } }); }
public async Task ServiceDocumentTest(string format) { // Act var requestUri = string.Format("{0}/odata?$format={1}", BaseAddress, format); var response = await Client.GetAsync(requestUri); var stream = await response.Content.ReadAsStreamAsync(); //Assert var oDataMessageReaderSettings = new ODataMessageReaderSettings(); IODataResponseMessage message = new ODataMessageWrapper(stream, response.Content.Headers); var reader = new ODataMessageReader(message, oDataMessageReaderSettings, UnboundFunctionEdmModel.GetEdmModel()); var oDataWorkSpace = reader.ReadServiceDocument(); var function1 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetAllConventionCustomers"); Assert.Equal(1, function1.Count()); var function2 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionOrderByCustomerIdAndOrderName"); // ODL spec says: // The edm:FunctionImport for a parameterless function MAY include the IncludeInServiceDocument attribute // whose Boolean value indicates whether the function import is advertised in the service document. // So the below 2 FunctionImports are not displayed in ServiceDocument. Assert.Equal(0, function2.Count()); var function3 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionCustomerById"); Assert.Equal(0, function3.Count()); }