public static async Task <MetaDataInfo> LoadMetaDataHttpAsync(OdataConnectionString odataConnString) { // to avoid the Error Message://An error occurred while sending the request.--> ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var client = new CustomeHttpClient(odataConnString); var content = await client.ReadMetaDataAsync(); var metaData = new MetaDataInfo { MetaDataAsString = content, MetaDataVersion = Helper.GetMetadataVersion(content), ServiceUrl = client.ServiceUri.OriginalString, SchemaNamespace = Helper.GetNameSpace(content), MediaType = Media.Http, }; if (client.Response != null) { foreach (var entry in client.Response.Headers) { string value = entry.Value.FirstOrDefault(); string key = entry.Key; metaData.ServiceHeader.Add(key, value); } } metaData.ServiceVersion = Helper.GetServiceVersion(metaData.ServiceHeader); return(metaData); }
public async Task No_auth_ReadMetaDataTest(string url) { var connection = new OdataConnectionString { ServiceUrl = url, }; var cc = new CustomeHttpClient(connection); var metadata = await cc.ReadMetaDataAsync(); Assert.That(metadata.Length, Is.GreaterThan(0)); }
public async Task Token_Auth_CheckHttpRequestMessage_HttpGet() { var connection = new OdataConnectionString { ServiceUrl = "http://localhost/odata2/api/northwind", Password = "******", Authenticate = AuthenticationType.Token }; var client = new CustomeHttpClient(connection, new CustomeHandler(r => { Assert.AreEqual(r.RequestUri.ToString(), "http://localhost/odata2/api/northwind/$metadata"); Assert.IsNotNull(r.Headers.UserAgent); Assert.AreEqual(r.Headers.UserAgent.ToString(), "OData2Poco"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); })); var metadata = await client.ReadMetaDataAsync(); }