Esempio n. 1
0
        public static ISetup <IHttpClient, byte[]> SetupOtherDataApiCall(this Mock <IHttpClient> httpClientMock, ComponentBase component, string method, IDictionary <string, object> parameters = null, string apiKey = null)
        {
            if (apiKey != null)
            {
                parameters = parameters ?? new Parameters();
                parameters.Add("apikey", apiKey);
            }
            var url = ZapApi.BuildRequestUrl(DataType.Other, component.ComponentName, CallType.Other, method, parameters);

            return(httpClientMock.Setup(m => m.DownloadData(url)));
        }
Esempio n. 2
0
        public static ISetup <IHttpClient, string> SetupApiCall(this Mock <IHttpClient> httpClientMock, ComponentBase component, CallType callType, string method, IDictionary <string, object> parameters = null, DataType?dataType = null, string apiKey = null)
        {
            dataType = dataType ?? DataType.Json;
            if (apiKey != null)
            {
                parameters = parameters ?? new Parameters();
                parameters.Add("apikey", apiKey);
            }
            var url = ZapApi.BuildRequestUrl(dataType.Value, component.ComponentName, callType, method, parameters);

            return(httpClientMock.Setup(m => m.DownloadString(url)));
        }
Esempio n. 3
0
        private string CallApi(DataType dataType, CallType callType, string method, IDictionary <string, object> parameters)
        {
            parameters = AddApiKey(parameters);
            var url    = ZapApi.BuildRequestUrl(dataType, ComponentName, callType, method, parameters);
            var result = _httpClient.DownloadString(url);

            if (string.IsNullOrEmpty(result))
            {
                throw new ZapException(Resources.EmptyServerResult);
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Calls an "other" API method in ZAP and return it's result as binary data.
        /// </summary>
        /// <param name="method">The name of the API method.</param>
        /// <param name="parameters">Optional parameters to send to the API method.</param>
        /// <returns>The result of the API call as binary data.</returns>
        protected byte[] CallOtherData(string method, IDictionary <string, object> parameters = null)
        {
            parameters = AddApiKey(parameters);

            var url    = ZapApi.BuildRequestUrl(DataType.Other, ComponentName, CallType.Other, method, parameters);
            var result = _httpClient.DownloadData(url);

            if (!result.Any())
            {
                throw new ZapException(Resources.EmptyServerResult);
            }

            return(result);
        }