public NSIService20Test(string endpoint) { this._wsInvoker = new SdmxServiceTestInvoker(); var baseUrl = new Uri(Properties.Settings.Default.baseURL); var endpointUri = new Uri(baseUrl, endpoint); this.wsClient = new SdmxWsClient(endpointUri, SchemaVersion); }
/// <summary> /// Invokes the service. /// </summary> /// <param name="wsClient"> /// The ws client. /// </param> /// <param name="operation"> /// The operation. /// </param> /// <param name="request"> /// The request. /// </param> /// <param name="response"> /// The response. /// </param> /// <param name="schemaVersion"> /// The schema version. /// </param> /// <param name="compress"> /// if set to <c>true</c> [compress]. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool InvokeService(SdmxWsClient wsClient, SoapOperation operation, FileInfo request, FileInfo response, SdmxSchemaEnumType schemaVersion, bool compress = false) { var sdmxMessage = new FileInfo(Path.Combine(response.DirectoryName ?? string.Empty, response.Name + ".sdmx.xml")); try { wsClient.InvokeService(operation, request, response, compress); using (var reader = XmlReader.Create(response.FullName, new XmlReaderSettings() {IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true})) using (var writer = XmlWriter.Create(sdmxMessage.FullName, new XmlWriterSettings() {Encoding = Encoding.UTF8, Indent = true })) { SdmxMessageUtil.FindSdmx(reader); writer.WriteNode(reader, true); writer.Flush(); } } catch (WebException e) { _log.Error(e.Message, e); var webResponse = e.Response; if (webResponse != null) { var tempFileName = Path.GetTempFileName(); _log.ErrorFormat("Logging error at {0}", tempFileName); WriteResponse(webResponse, tempFileName); var errorCode = GetErrorCode(tempFileName); _log.ErrorFormat("Error code : {0} ", errorCode); _log.Error(File.ReadAllText(tempFileName)); File.Delete(tempFileName); } throw; } using (IReadableDataLocation location = new FileReadableDataLocation(sdmxMessage)) { var actualVersion = SdmxMessageUtil.GetSchemaVersion(location); if (actualVersion != schemaVersion) { return false; } var actualMessageType = SdmxMessageUtil.GetMessageType(location); var expectedMessageType = operation.GetMessageType(); if (actualMessageType != expectedMessageType) { return false; } } return true; }
/// <summary> /// Invokes the service error assert. /// </summary> /// <param name="wsClient"> /// The WS client. /// </param> /// <param name="operation"> /// The operation. /// </param> /// <param name="request"> /// The request. /// </param> /// <param name="expectedError"> /// The expected error. /// </param> /// <param name="compress"> /// if set to <c>true</c> [compress]. /// </param> /// <returns> /// True if the returned error matches the <paramref name="expectedError"/> ; otherwise false. /// </returns> public bool InvokeServiceErrorAssert(SdmxWsClient wsClient, SoapOperation operation, FileInfo request, int expectedError, bool compress = false) { var response = new FileInfo(Path.GetTempFileName()); try { wsClient.InvokeService(operation, request, response, compress); } catch (WebException e) { if (CheckErrorResponse(expectedError, e)) { return true; } } response.Refresh(); response.Delete(); return false; }
public void Init() { try { var baseUrl = new Uri(Properties.Settings.Default.baseURL); this._wsClient = new SdmxWsClient(new Uri(baseUrl, Endpoint), SchemaVersion); } catch (Exception e) { _log.Error("Error at Test Init", e); Assert.Fail(e.Message); } }