예제 #1
0
 /// <summary>
 /// Checks whether ZAP is the minimum version an sets <see cref="Started"/> accordingly.
 /// </summary>
 public void Start()
 {
     if (ZapApi.CheckIfMinimumZapVersion(this))
     {
         Started = true;
     }
 }
예제 #2
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)));
        }
예제 #3
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)));
        }
예제 #4
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);
        }
예제 #5
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);
        }