public void ContainsPredicate_Constructor_SetsCaseSensitivity()
        {
            var fields    = new TestPredicateFields();
            var predicate = new ContainsPredicate <TestPredicateFields>(fields, isCaseSensitive: true);

            Assert.IsTrue(predicate.IsCaseSensitive);
        }
        public void ContainsPredicate_Constructor_SetsFieldObject()
        {
            var expectedFields = new TestPredicateFields();
            var predicate      = new ContainsPredicate <TestPredicateFields>(expectedFields);

            Assert.AreSame(expectedFields, predicate.Fields);
        }
Example #3
0
        public void HttpStub_ReturnsProxy_ReturnsHttpProxyStub()
        {
            var predicateInvokingProxyStub = new ContainsPredicate <HttpPredicateFields>(new HttpPredicateFields
            {
                Path = "/aTestPath"
            });

            var proxyGeneratorPredicate = new MatchesPredicate <HttpPredicateFields>(new HttpPredicateFields
            {
                Path            = "/aTestPath",
                Method          = Method.Get,
                QueryParameters = new Dictionary <string, string> {
                    { "q", "value" }
                }
            });

            var proxyToUrl     = new Uri("http://someTestDestination.com");
            var proxyModeToUse = ProxyMode.ProxyTransparent;

            var stub = new HttpStub();

            stub.On(predicateInvokingProxyStub)
            .ReturnsProxy(proxyToUrl, proxyModeToUse, new [] { proxyGeneratorPredicate });

            var proxyResponse = stub.Responses.First() as ProxyResponse <ProxyResponseFields <HttpPredicateFields> >;

            Assert.AreEqual(proxyToUrl, proxyResponse.Fields.To);
            Assert.AreEqual(proxyModeToUse, proxyResponse.Fields.Mode);
            Assert.AreEqual(proxyGeneratorPredicate, proxyResponse.Fields.PredicateGenerators.First());
        }
Example #4
0
        public void TcpStub_ReturnsProxy_ReturnsTcpBooleanProxyStub()
        {
            var predicateInvokingProxyStub = new ContainsPredicate <TcpPredicateFields>(new TcpPredicateFields
            {
                Data = "123345"
            });

            var proxyGeneratorPredicate = new MatchesPredicate <TcpBooleanPredicateFields>(new TcpBooleanPredicateFields
            {
                Data = true
            });

            var proxyToUrl     = new Uri("tcp://someTestDestination.com");
            var proxyModeToUse = ProxyMode.ProxyTransparent;

            var stub = new TcpStub();

            stub.On(predicateInvokingProxyStub)
            .ReturnsProxy(proxyToUrl, proxyModeToUse, new [] { proxyGeneratorPredicate });

            var proxyResponse = stub.Responses.First() as ProxyResponse <ProxyResponseFields <TcpBooleanPredicateFields> >;

            Assert.AreEqual(proxyToUrl, proxyResponse.Fields.To);
            Assert.AreEqual(proxyModeToUse, proxyResponse.Fields.Mode);
            Assert.AreEqual(proxyGeneratorPredicate, proxyResponse.Fields.PredicateGenerators.First());
        }
Example #5
0
        public async Task AndPredicateExample()
        {
            var imposter = _client.CreateTcpImposter(4554, "AndPredicateExample");

            var startsWithFields = new TcpPredicateFields {
                Data = "start"
            };
            var startsWith = new StartsWithPredicate <TcpPredicateFields>(startsWithFields);

            var endsWithFields = new TcpPredicateFields {
                Data = "end\n"
            };
            var endsWith = new EndsWithPredicate <TcpPredicateFields>(endsWithFields);

            var containsFields = new TcpPredicateFields {
                Data = "middle"
            };
            var contains = new ContainsPredicate <TcpPredicateFields>(containsFields);

            var predicate = new AndPredicate(new List <PredicateBase> {
                startsWith, endsWith, contains
            });

            imposter.AddStub().On(predicate)
            .ReturnsData("matches");

            await _client.SubmitAsync(imposter);
        }
Example #6
0
        private static object FindOp(List <string> tokens, int start, int end, out int tokenPos)
        {
            int    nestDepth         = 0;
            object unaryPredicate    = null;
            int    unaryPredicatePos = -1;

            for (tokenPos = start; tokenPos <= end; tokenPos++)
            {
                string token = tokens[tokenPos];
                if (token == "(")
                {
                    nestDepth++;
                }
                else if (token == ")")
                {
                    if (nestDepth == 0)
                    {
                        throw new Exception("Parse error: unexpected ')'");
                    }
                    nestDepth--;
                }
                else if (token == "or" && nestDepth == 0)
                {
                    return(new OrPredicateOfValueListImpl5eNmv5yi());
                }
                else if (token == "and" && nestDepth == 0)
                {
                    return(new AndPredicateOfValueListImpl5eNmv5yi());
                }
                else if (token == "not" && nestDepth == 0 && unaryPredicate == null)
                {
                    return(new NotPredicateOfValueListImpl5eNmv5yi());
                }
                else if (token == "contains" && nestDepth == 0 && unaryPredicate == null)
                {
                    unaryPredicate    = new ContainsPredicate();
                    unaryPredicatePos = tokenPos;
                }
                else if (token == "maxlen" && nestDepth == 0 && unaryPredicate == null)
                {
                    unaryPredicate    = new MaxLengthPredicate();
                    unaryPredicatePos = tokenPos;
                }
                else if (token == "minlen" && nestDepth == 0 && unaryPredicate == null)
                {
                    unaryPredicate    = new MinLengthPredicate();
                    unaryPredicatePos = tokenPos;
                }
                else if (nestDepth == 0 && unaryPredicate == null)
                {
                    throw new Exception(String.Format("Parse error: unexpected token '{0}'", token));
                }
            }
            if (unaryPredicate != null)
            {
                tokenPos = unaryPredicatePos;
            }
            return(unaryPredicate);
        }
        public void Constructor_SetsXpathSelector()
        {
            var expectedXPathSelector = new XPathSelector("!$");

            var fields = new TestPredicateFields();
            var predicate = new ContainsPredicate<TestPredicateFields>(fields, false, null, expectedXPathSelector);
            Assert.AreEqual(expectedXPathSelector, predicate.Selector);
        }
        public void Constructor_SetsExceptExpression()
        {
            const string expectedExceptRegex = "!$";

            var fields = new TestPredicateFields();
            var predicate = new ContainsPredicate<TestPredicateFields>(fields, false, expectedExceptRegex, null);
            Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression);
        }
        public void ContainsPredicate_Constructor_SetsXpathSelector()
        {
            var expectedXPathSelector = new XPathSelector("!$");

            var fields    = new TestPredicateFields();
            var predicate = new ContainsPredicate <TestPredicateFields>(fields, xpath: expectedXPathSelector);

            Assert.AreEqual(expectedXPathSelector, predicate.XPathSelector);
        }
        public void ContainsPredicate_Constructor_SetsJsonPathSelector()
        {
            var expectedJsonPathSelector = new JsonPathSelector("$..title");

            var fields    = new TestPredicateFields();
            var predicate = new ContainsPredicate <TestPredicateFields>(fields, jsonpath: expectedJsonPathSelector);

            Assert.AreEqual(expectedJsonPathSelector, predicate.JsonPathSelector);
        }
        public void ContainsPredicate_Constructor_SetsExceptExpression()
        {
            const string expectedExceptRegex = "!$";

            var fields    = new TestPredicateFields();
            var predicate = new ContainsPredicate <TestPredicateFields>(fields, exceptExpression: expectedExceptRegex);

            Assert.AreEqual(expectedExceptRegex, predicate.ExceptExpression);
        }
Example #12
0
        public void ContainsPredicate(SqlFragment parent, ContainsPredicate containsPredicate)
        {
            // TODO do we keep contains here?
            containsPredicate.LeftOperand.Build(parent, this);
            this.Script.Append("LIKE");

            Expression expression = "%" + containsPredicate.RightOperand + "%";

            expression.Build(parent, this);
        }
        /// <summary>Renders CONTAINS predicate as compatible LIKE predicate.</summary>
        /// <param name="contains">Contains predicate.</param>
        /// <param name="dbms">Target DBMS.</param>
        /// <param name="output">StringBuilder to which SQL is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        public void Render(ContainsPredicate contains, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            output.Append("(");
            contains.PredicateItems[0].Render(dbms, output, parameters);
            if (contains.Negate)
                output.Append(" NOT LIKE ");
            else
                output.Append(" LIKE ");

            IDbColumn field = (IDbColumn)contains.PredicateItems[0].Item;
            string pattern = (string)(contains.PredicateItems[1].Item as DbParameter).Value;
            pattern = "%" + pattern + "%";

            PredicateItem parametrizedPattern = new PredicateItem(pattern, DbType.String, field.MaxLengthIfText, field.GetPrefixedAlias());
            parametrizedPattern.Render(dbms, output, parameters);
            output.Append(")");
        }
        public void Render(ContainsPredicate contains, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            output.Append("(");
            if (contains.Negate)
                output.Append("NOT CONTAINS(");
            else
                output.Append("CONTAINS(");

            contains.PredicateItems[0].Render(dbms, output, parameters);
            output.Append(", ");

            IDbColumn field = (IDbColumn)contains.PredicateItems[0].Item;
            string term = (string)(contains.PredicateItems[1].Item as DbParameter).Value;
            if (contains.TermType == ContainsTermType.PrefixTerm)
                term = '"' + term + '"';
            else
                term = '"' + term + "*\"";

            PredicateItem parametrizedTerm = new PredicateItem(term, DbType.String, field.MaxLengthIfText, field.GetPrefixedAlias());
            parametrizedTerm.Render(dbms, output, parameters);
            output.Append(")");
            output.Append(")");
        }
        public static void AddRecordedCommand(VirtSqlRpcModel model)
        {
            _recordedCommands.AddOrUpdate(model.StoredProcName, s => new List <VirtSqlRpcModel> {
                model
            }, (s, list) =>
            {
                list.Add(model);
                return(list);
            });

            var mountebankClient = new MountebankClient();

            mountebankClient.DeleteImposter(1234);

            var imposter = mountebankClient.CreateHttpImposter(1234, "test");

            foreach (var virtRecordedCommand in _recordedCommands)
            {
                var stub = imposter.AddStub();

                var predicateFields = new HttpPredicateFields
                {
                    Path = virtRecordedCommand.Key,
                };

                var containsPredicate = new ContainsPredicate <HttpPredicateFields>(predicateFields);

                foreach (var response in virtRecordedCommand.Value)
                {
                    stub
                    .On(containsPredicate)
                    .ReturnsJson(HttpStatusCode.OK, response);
                }
            }

            mountebankClient.Submit(imposter);
        }
 public void Constructor_SetsFieldObject()
 {
     var expectedFields = new TestPredicateFields();
     var predicate = new ContainsPredicate<TestPredicateFields>(expectedFields);
     Assert.AreSame(expectedFields, predicate.Fields);
 }
 public void Constructor_SetsCaseSensitivity()
 {
     var fields = new TestPredicateFields();
     var predicate = new ContainsPredicate<TestPredicateFields>(fields, true, null, null);
     Assert.IsTrue(predicate.IsCaseSensitive);
 }