public void SendToRestService(string url, WebServiceMethod method, string service, Table parameters) { this.serviceContext.Services.SingleOrDefault(key => key.Key == service).Value.Should() .BeNull($"Сервис с названием '{service}' уже существует"); url.Should().NotBeEmpty("Ссылка на сервис не задана"); parameters.Should().NotBeNull("Параметры не заданы"); NameValueCollection headersCollection; List <KeyValuePair <string, string> > queryCollection; (url, headersCollection, queryCollection) = this.InitializationRestService(url, parameters); this.consoleOutputHelper.WriteLine($"url (сериализован): {url}"); using (var rest = new Rest(url, webServiceMethod: method)) { rest.Headers = headersCollection; var(statusCode, errors) = rest.CallWebService(); this.serviceContext.Services.Add(service, new WebService() { Url = url, Service = (Core.Data.Services.Service)rest.Clone(), Body = string.Empty, HeadersCollection = headersCollection, ParametersCollection = queryCollection, StatusCode = statusCode, Errors = errors, }); } }
public void SendToRestServiceWithBodyAndAuth(string url, WebServiceMethod method, string body, string service, string varCredentials, Table parameters) { this.serviceContext.Services.SingleOrDefault(key => key.Key == service).Value.Should() .BeNull($"Сервис с названием '{service}' уже существует"); url.Should().NotBeEmpty("Ссылка на сервис не задана"); parameters.Should().NotBeNull("Параметры не заданы"); this.variableContext.Variables.ContainsKey(body).Should().BeTrue($"Переменной '{body}' не существует"); var credentials = this.variableContext.GetVariableValue(varCredentials); credentials.Should().NotBeNull("Полномочия для входа были не созданы"); NameValueCollection headersCollection; List <KeyValuePair <string, string> > queryCollection; (url, headersCollection, queryCollection) = this.InitializationRestService(url, parameters); var serviceBody = this.variableContext.GetVariableValueText(body); serviceBody = this.TransformBody(headersCollection, serviceBody); this.consoleOutputHelper.WriteLine($"url (сериализован): {url}"); this.consoleOutputHelper.WriteLine($"Запрос (сериализован): {Environment.NewLine}{serviceBody}"); using (var rest = new Rest(url, webServiceMethod: method)) { rest.Headers = headersCollection; rest.Credentials = credentials as ICredentials; var(statusCode, errors) = rest.CallWebService(serviceBody); this.serviceContext.Services.Add(service, new WebService() { Url = url, Service = (Core.Data.Services.Service)rest.Clone(), Body = serviceBody, HeadersCollection = headersCollection, ParametersCollection = queryCollection, StatusCode = statusCode, Errors = errors, }); } }