Ejemplo n.º 1
0
        public void ParseStatement_WhenNonMatchingType_ExpectThrows()
        {
            // Arrange
            var equalsParser = new EqualsParser();

            // Act
            var stopwatch = Stopwatch.StartNew();

            Assert.Throws <ParseException>(() => equalsParser.ParseStatement("Name", Types.DateTime));
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="parserOptions">The parser options.</param>
        /// <returns>The IEntityParser.</returns>
        private static object Initialize <TEntity>(ParserOptions parserOptions)
        {
            var tokenSplitter = new TokenSplitter();

            var rangeParser  = new RangeParser();
            var equalsParser = new EqualsParser();

            var entityParser = new EntityParser <TEntity>();
            var typeSplitter = new TypeSplitter();

            var whereStatementParser = new WhereStatementParser <TEntity>(rangeParser, equalsParser, entityParser, typeSplitter);
            var whereParser          = new WhereParser(whereStatementParser, parserOptions);
            var orderByParser        = new OrderByParser <TEntity>(entityParser);
            var pageParser           = new PageParser();
            var selectParser         = new SelectParser <TEntity>(entityParser);

            return(new StatementParser(tokenSplitter, whereParser, pageParser, orderByParser, selectParser));
        }
Ejemplo n.º 3
0
        public void ParseWhere_WhenTwoParts_ExpectBinaryNode()
        {
            // Arrange
            var rangeParser          = new RangeParser();
            var equalsParser         = new EqualsParser();
            var entityParser         = new EntityParser <CustomEntity>();
            var typeSplitter         = new TypeSplitter();
            var whereStatementParser = new WhereStatementParser <CustomEntity>(rangeParser, equalsParser, entityParser, typeSplitter);
            var whereParser          = new WhereParser(whereStatementParser, new ParserOptions());

            // Act
            var stopwatch = Stopwatch.StartNew();
            var whereNode = whereParser.ParseWhere("testKey:testValue and testKey2:[23,2]");

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            var next1 = new WhereNode
            {
                Conjunctive = Conjunctives.None,
                Next        = null,
                Statement   = new WhereStatement {
                    As = null, Value = new RangeOperator {
                        Statement = "testKey2:[23,2]", Name = "testKey2", Lower = 23, LowerInclusive = false, Upper = 2, UpperInclusive = false
                    }
                }
            };

            var expected = new WhereNode
            {
                Conjunctive = Conjunctives.And,
                Next        = next1,
                Statement   = new WhereStatement {
                    As = null, Value = new EqualsOperator {
                        Statement = "testKey:testValue", Name = "testKey", CaseInsensitive = false, Value = "testValue", IsNot = false
                    }
                }
            };

            whereNode.ShouldDeepEqual(expected);
        }
Ejemplo n.º 4
0
        public void ParseStatement_WhenDecimalWithDecimalTypeSpecified_ExpectQueryIsDecimal()
        {
            // Arrange
            var equalsParser = new EqualsParser();

            // Act
            var stopwatch = Stopwatch.StartNew();
            var unaryNode = equalsParser.ParseStatement("123.125", Types.Decimal);

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(unaryNode, Is.Not.Null);
            Assert.That(unaryNode, Is.TypeOf <EqualsOperator>());

            var equalsNode = (EqualsOperator)unaryNode;

            Assert.That(equalsNode.Name, Is.Null);
            Assert.That(equalsNode.Value, Is.EqualTo(123.125m));
            Assert.That(equalsNode.IsNot, Is.False);
        }
Ejemplo n.º 5
0
        public void ParseStatement_WhenStringWithStringTypeSpecified_ExpectQueryIsString()
        {
            // Arrange
            var equalsParser = new EqualsParser();

            // Act
            var stopwatch = Stopwatch.StartNew();
            var unaryNode = equalsParser.ParseStatement("2018-1-1", Types.String);

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(unaryNode, Is.Not.Null);
            Assert.That(unaryNode, Is.TypeOf <EqualsOperator>());

            var equalsNode = (EqualsOperator)unaryNode;

            Assert.That(equalsNode.Name, Is.Null);
            Assert.That(equalsNode.Value, Is.EqualTo("2018-1-1"));
            Assert.That(equalsNode.IsNot, Is.False);
        }
Ejemplo n.º 6
0
        public void ParseStatement_WhenStringInWithNot_ExpectEqualsNode()
        {
            // Arrange
            var equalsParser = new EqualsParser();

            // Act
            var stopwatch = Stopwatch.StartNew();
            var unaryNode = equalsParser.ParseStatement("!TestString");

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(unaryNode, Is.Not.Null);
            Assert.That(unaryNode, Is.TypeOf <EqualsOperator>());

            var equalsNode = (EqualsOperator)unaryNode;

            Assert.That(equalsNode.Name, Is.Null);
            Assert.That(equalsNode.Value, Is.EqualTo("TestString"));
            Assert.That(equalsNode.IsNot, Is.True);
        }
Ejemplo n.º 7
0
        public void ParseStatement_WhenNumber_ExpectQueryIsNumber()
        {
            // Arrange
            var equalsParser = new EqualsParser();

            // Act
            var stopwatch = Stopwatch.StartNew();
            var unaryNode = equalsParser.ParseStatement("56");

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(unaryNode, Is.Not.Null);
            Assert.That(unaryNode, Is.TypeOf <EqualsOperator>());

            var equalsNode = (EqualsOperator)unaryNode;

            Assert.That(equalsNode.Name, Is.Null);
            Assert.That(equalsNode.Value, Is.EqualTo(56));
            Assert.That(equalsNode.IsNot, Is.False);
        }
Ejemplo n.º 8
0
        public void ParseWhere_WhenSimpleQuery_ExpectNodeBack()
        {
            // Arrange
            var rangeParser          = new RangeParser();
            var equalsParser         = new EqualsParser();
            var entityParser         = new EntityParser <CustomEntity>();
            var typeSplitter         = new TypeSplitter();
            var whereStatementParser = new WhereStatementParser <CustomEntity>(rangeParser, equalsParser, entityParser, typeSplitter);
            var whereParser          = new WhereParser(whereStatementParser, new ParserOptions());

            // Act
            var stopwatch = Stopwatch.StartNew();
            var whereNode = whereParser.ParseWhere("testKey:testValue");

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            var equalsOperator = whereNode;

            Assert.That(equalsOperator, Is.Not.Null);

            var expected = new WhereNode
            {
                Conjunctive = Conjunctives.None,
                Next        = null,
                Statement   = new WhereStatement {
                    As = null, Value = new EqualsOperator {
                        Statement = "testKey:testValue", Name = "testKey", CaseInsensitive = false, Value = "testValue", IsNot = false
                    }
                }
            };

            whereNode.ShouldDeepEqual(expected);
        }