Beispiel #1
0
        public async Task <string[]> GetDistinctMethods(string requestUrl)
        {
            var sqlParams = new Dictionary <string, object>();

            var sql = "SELECT DISTINCT Method FROM HttpStatusResult";

            if (!string.IsNullOrEmpty(requestUrl))
            {
                sql += " WHERE " + _service.CreateRequestUrlWhereClause(requestUrl, out sqlParams);
            }

            var methods = await _dbConnection.QueryAsync <string>(sql, sqlParams);

            return(methods.ToArray());
        }
        private string CreateWhereClause(Filters filters, out IDictionary <string, object> sqlParams)
        {
            sqlParams = new Dictionary <string, object>();

            if (filters.CollationType == CollationType.Tests)
            {
                var filterByTest = !string.IsNullOrWhiteSpace(filters.Test);
                var whereClause  = filterByTest ? "WHERE TestName = @testName" : "";
                if (filterByTest)
                {
                    sqlParams.Add("testName", filters.Test);
                }

                return(whereClause);
            }

            var whereCriteria = new List <string>();

            if (!string.IsNullOrEmpty(filters.Method))
            {
                whereCriteria.Add("Method = @method");
                sqlParams.Add("method", filters.Method);
            }

            if (!string.IsNullOrEmpty(filters.RequestUrl))
            {
                var requestUrlWhereCriteria = _service.CreateRequestUrlWhereClause(filters.RequestUrl, out var requestUrlSqlParams);
                whereCriteria.Add(requestUrlWhereCriteria);

                foreach (var kvp in requestUrlSqlParams)
                {
                    if (sqlParams.ContainsKey(kvp.Key))
                    {
                        throw new ArgumentException($"The sql parameter '{kvp.Key}' provided by the CreateRequestUrlWhereClause method of the IHttpStatusResultService implementation already exists");
                    }

                    sqlParams.Add(kvp.Key, kvp.Value);
                }
            }

            if (filters.StatusCode.HasValue)
            {
                whereCriteria.Add("StatusCode = @statusCode");
                sqlParams.Add("statusCode", filters.StatusCode.Value);
            }

            if (whereCriteria.Count == 0)
            {
                return("");
            }

            return(" WHERE " + string.Join(" AND ", whereCriteria));
        }