public static IApiProxy GetApiProxy(IApiProxyConfiguration configuration, IApiProxyRecordProvider apiProxyRecordProvider) { var folderBasedRecorder = new FolderHeirarchyBasedApiProxyRecordProvider(configuration); var apiProxyProviderFactory = new ApiProxyProviderFactory(folderBasedRecorder, configuration); return(new DD.ApiProxy.ApiProxy(configuration, apiProxyProviderFactory, apiProxyRecordProvider)); }
public static XmlAction GetXmlAction(this XmlApiRecord apiRecord, IApiProxyConfiguration proxyConfiguration) { if (!proxyConfiguration.FallbackToDefaultApi) { if (apiRecord.ResponseContent != null || apiRecord.Mock) { return(XmlAction.ReplayFromMock); } return(XmlAction.None); } var xmlConfiguration = apiRecord.Configuration; if ((xmlConfiguration != null && apiRecord.Mock && !string.IsNullOrWhiteSpace(xmlConfiguration.Transform?.RequestContent?.XsltFileName))) { return(XmlAction.ReplayFromTransformedRequestMock); } if (xmlConfiguration?.Transform != null) { return(XmlAction.TransformResponse); } if (apiRecord.ResponseContent != null || apiRecord.Mock) { return(XmlAction.ReplayFromMock); } return(XmlAction.ReplayFromRealApi); }
public FolderHeirarchyBasedApiProxyRecordProvider(IApiProxyConfiguration proxyConfiguration) { if (proxyConfiguration == null) { throw new ArgumentNullException(nameof(proxyConfiguration)); } _proxyConfiguration = proxyConfiguration; }
public ApiProxyClientHandler(IApiProxyConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } _configuration = configuration; _inMemoryApiProxyRecordProvider = new InMemoryApiProxyRecordProvider(_configuration); }
public static HttpClient GetHttpClient(IApiProxyConfiguration configuration, HttpClientHandler httpClientHandler) { var baseUri = configuration.DefaultApiAddress ?? new Uri("https://localhost/"); return(new HttpClient(httpClientHandler) { BaseAddress = baseUri }); }
public ApiProxyProviderFactory(IApiRecorder recorder, IApiProxyConfiguration apiProxyConfiguration) { if (recorder == null) { throw new ArgumentNullException(nameof(recorder)); } _recorder = recorder; if (apiProxyConfiguration == null) { throw new ArgumentNullException(nameof(apiProxyConfiguration)); } _apiProxyConfiguration = apiProxyConfiguration; }
public RealApiApiProxyProvider(IApiProxyConfiguration proxyConfiguration, IApiRecorder recorder) { if (proxyConfiguration == null) { throw new ArgumentNullException(nameof(proxyConfiguration)); } ProxyConfiguration = proxyConfiguration; if (recorder == null) { throw new ArgumentNullException(nameof(recorder)); } ApiRecorder = recorder; }
public static HttpClientHandler GetHttpClientHandler(IApiProxyConfiguration configuration, ICredentials credentials = null, EventHandler <RequestReceivedEventArgs> requestReceivedEventHandler = null) { var clientHandler = new ApiProxyClientHandler(configuration) { Credentials = credentials, PreAuthenticate = true }; if (requestReceivedEventHandler != null) { clientHandler.RequestReceived += requestReceivedEventHandler; } return(clientHandler); }
public static HttpClient GetHttpClient(IApiProxyConfiguration configuration, ICredentials credentials = null, EventHandler <RequestReceivedEventArgs> requestReceivedEventHandler = null) { var baseUri = configuration.DefaultApiAddress ?? new Uri("https://localhost/"); var clientHandler = new ApiProxyClientHandler(configuration) { Credentials = credentials, PreAuthenticate = true }; if (requestReceivedEventHandler != null) { clientHandler.RequestReceived += requestReceivedEventHandler; } return(new HttpClient(clientHandler) { BaseAddress = baseUri }); }
public ApiProxy(IApiProxyConfiguration proxyConfiguration, IApiProxyProviderFactory apiProxyProviderFactory, IApiProxyRecordProvider apiProxyRecordProvider) { if (proxyConfiguration == null) { throw new ArgumentNullException(nameof(proxyConfiguration)); } _proxyConfiguration = proxyConfiguration; if (apiProxyProviderFactory == null) { throw new ArgumentNullException(nameof(apiProxyProviderFactory)); } _apiProxyProviderFactory = apiProxyProviderFactory; if (apiProxyRecordProvider == null) { throw new ArgumentNullException(nameof(apiProxyRecordProvider)); } _apiProxyRecordProvider = apiProxyRecordProvider; }
public XmlContentTypeApiProxyProvider(IApiProxyConfiguration proxyConfiguration, IApiRecorder apiRecorder, XmlApiRecord apiRecord) { if (proxyConfiguration == null) { throw new ArgumentNullException(nameof(proxyConfiguration)); } ProxyConfiguration = proxyConfiguration; if (apiRecorder == null) { throw new ArgumentNullException(nameof(apiRecorder)); } ApiRecorder = apiRecorder; if (apiRecord == null) { throw new ArgumentNullException(nameof(apiRecord)); } _xmlApiRecord = apiRecord; }
public IApiProxyProvider GetApiProxyProvider(ApiRecord record, HttpRequestMessage request, IApiProxyConfiguration configuration) { switch (record.ResponseContentType) { case "text/xml": case "application/xml": var xmlApiRecord = JsonConvert.DeserializeObject <XmlApiRecord>(record.RawContent); return(new XmlContentTypeApiProxyProvider(configuration, _recorder, xmlApiRecord)); } if (!_apiProxyConfiguration.FallbackToDefaultApi) { throw new InvalidOperationException("Content type for mocking not supported"); } return(new RealApiApiProxyProvider(configuration, _recorder)); }
public InMemoryApiProxyRecordProvider(IApiProxyConfiguration proxyConfiguration) : base(proxyConfiguration) { }
public async Task Invoke(HttpContext context, IApiProxyContextService apiProxyContextService, IApiProxyConfiguration apiProxyConfiguration, IApiProxyUriResolver apiProxyUriResolver) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var apiProxyContext = apiProxyContextService.Get(context); apiProxyContext.ExecutionStart = DateTime.Now; await _next.Invoke(context); apiProxyContext.ExecutionEnd = DateTime.Now; if (apiProxyContext.Response.HasResponse) { await CopyApiProxyResponseToHttpResponse(context, apiProxyContext, apiProxyUriResolver, apiProxyConfiguration.DebugMode); } }