Beispiel #1
0
        public static LinqTestOutput ExecuteTest(LinqTestInput input)
        {
            string querySqlStr = string.Empty;

            try
            {
                Func <bool, IQueryable> compiledQuery = input.Expression.Compile();

                IQueryable queryResults = compiledQuery(true);
                querySqlStr = JObject.Parse(queryResults.ToString()).GetValue("query", StringComparison.Ordinal).ToString();

                // we skip unordered query because the LinQ results vs actual query results are non-deterministic
                if (!input.skipVerification)
                {
                    IQueryable dataResults = compiledQuery(false);
                    LinqTestsCommon.ValidateResults(queryResults, dataResults);
                }

                return(new LinqTestOutput(querySqlStr));
            }
            catch (Exception e)
            {
                return(new LinqTestOutput(querySqlStr, LinqTestsCommon.BuildExceptionMessageForTest(e)));
            }
        }
        public static LinqTestOutput ExecuteTest(LinqTestInput input)
        {
            var querySqlStr = string.Empty;

            try
            {
                var compiledQuery = input.Expression.Compile();

                var queryResults = compiledQuery(true);
                querySqlStr = JObject.Parse(queryResults.ToString()).GetValue("query", StringComparison.Ordinal).ToString();

                // we skip unordered query because the LinQ results vs actual query results are non-deterministic
                if (!input.skipVerification)
                {
                    var dataResults = compiledQuery(false);
                    LinqTestsCommon.ValidateResults(queryResults, dataResults);
                }

                string errorMsg = null;
                if (input.errorMessage != null)
                {
                    errorMsg = $"Expecting error containing message [[{input.errorMessage}]]. Actual: <No error>";
                }

                return(new LinqTestOutput(querySqlStr, errorMsg, errorMsg != null));
            }
            catch (Exception e)
            {
                while (!(e is DocumentClientException) && e.InnerException != null)
                {
                    e = e.InnerException;
                }

                string message   = null;
                bool   hasFailed = false;
                if (input.errorMessage != null && !e.Message.Contains(input.errorMessage))
                {
                    message   = $"Expecting error containing message [[{input.errorMessage}]]. Actual: [[{e.Message}]]";
                    hasFailed = true;
                }
                else if (input.errorMessage == null)
                {
                    message   = e.Message;
                    hasFailed = true;
                }

                return(new LinqTestOutput(querySqlStr, message, hasFailed));
            }
        }
        public static LinqTestOutput ExecuteTest(LinqTestInput input)
        {
            string querySqlStr = string.Empty;

            try
            {
                Func <bool, IQueryable> compiledQuery = input.Expression.Compile();

                IQueryable queryResults = compiledQuery(true);
                querySqlStr = JObject.Parse(queryResults.ToString()).GetValue("query", StringComparison.Ordinal).ToString();

                // we skip unordered query because the LinQ results vs actual query results are non-deterministic
                if (!input.skipVerification)
                {
                    IQueryable dataResults = compiledQuery(false);
                    LinqTestsCommon.ValidateResults(queryResults, dataResults);
                }

                return(new LinqTestOutput(querySqlStr));
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                string message;
                if (e is CosmosException cosmosException)
                {
                    message = $"Status Code: {cosmosException.StatusCode}";
                }
                else if (e is DocumentClientException documentClientException)
                {
                    message = documentClientException.RawErrorMessage;
                }
                else
                {
                    message = e.Message;
                }

                return(new LinqTestOutput(querySqlStr, message));
            }
        }
        public static LinqTestOutput ExecuteTest(LinqTestInput input)
        {
            var querySqlStr = string.Empty;

            try
            {
                var compiledQuery = input.Expression.Compile();

                var queryResults = compiledQuery(true);
                querySqlStr = JObject.Parse(queryResults.ToString()).GetValue("query", StringComparison.Ordinal).ToString();

                // we skip unordered query because the LinQ results vs actual query results are non-deterministic
                if (!input.skipVerification)
                {
                    var dataResults = compiledQuery(false);
                    LinqTestsCommon.ValidateResults(queryResults, dataResults);
                }

                return(new LinqTestOutput(querySqlStr));
            }
            catch (Exception e)
            {
                while (!(e is DocumentClientException) && e.InnerException != null)
                {
                    e = e.InnerException;
                }

                string message = null;
                DocumentClientException dce = e as DocumentClientException;
                if (dce != null)
                {
                    message = dce.RawErrorMessage;
                }
                else
                {
                    message = e.Message;
                }

                return(new LinqTestOutput(querySqlStr, message));
            }
        }