Ejemplo n.º 1
0
        public virtual ParserResult Parse()
        {
            ParserResult res = null;

            using (var connection = NewConnection(command.Connection.ConnectionString))
            {
                var fullSql = $@"SET FMTONLY ON; {command.CommandText} SET FMTONLY OFF;";
                OpenConnection(connection);
                StartWatch();
                using (var cmdIn = connection.CreateCommand())
                {
                    cmdIn.CommandText = fullSql;
                    InitializeCommand(cmdIn, connection);
                    try
                    {
                        cmdIn.ExecuteNonQuery();
                        res = ParserResult.NoParsingError();
                    }
                    catch (Exception ex)
                    {
                        res = new ParserResult(ParseMessage(ex.Message));
                    }
                }
            }
            StopWatch();
            return(res);
        }
Ejemplo n.º 2
0
        public void Matches_NoParsingError_ReturnTrue()
        {
            var mock = new Mock <IQueryParser>();

            mock.Setup(engine => engine.Parse())
            .Returns(ParserResult.NoParsingError());
            IQueryParser qp = mock.Object;

            var syntacticallyCorrectConstraint = new SyntacticallyCorrectConstraint()
            {
                Engine = qp
            };

            //Method under test
            var res = syntacticallyCorrectConstraint.Matches(new SqlCommand());

            //Test conclusion
            Assert.That(res, Is.True);
        }
Ejemplo n.º 3
0
        public void Matches_AnyIDbCommand_EngineParseCalledOnce()
        {
            var mock = new Mock <IQueryParser>();

            mock.Setup(engine => engine.Parse())
            .Returns(ParserResult.NoParsingError());
            IQueryParser qp = mock.Object;

            var syntacticallyCorrectConstraint = new SyntacticallyCorrectConstraint()
            {
                Engine = qp
            };

            //Method under test
            syntacticallyCorrectConstraint.Matches(new SqlCommand());

            //Test conclusion
            mock.Verify(engine => engine.Parse(), Times.Once());
        }
        public void Matches_AnyIDbCommand_EngineParseCalledOnce()
        {
            var mock = new Mock <IValidationEngine>();

            mock.Setup(engine => engine.Parse())
            .Returns(ParserResult.NoParsingError());
            IValidationEngine qp = mock.Object;

            var syntacticallyCorrectConstraint = new SyntacticallyCorrectConstraint()
            {
                Engine = qp
            };

            var queryFoundry = new Mock <IQuery>();
            var query        = queryFoundry.Object;

            syntacticallyCorrectConstraint.Matches(query);

            //Test conclusion
            mock.Verify(engine => engine.Parse(), Times.Once());
        }
        public void Matches_NoParsingError_ReturnTrue()
        {
            var mock = new Mock <IValidationEngine>();

            mock.Setup(engine => engine.Parse())
            .Returns(ParserResult.NoParsingError());
            IValidationEngine qp = mock.Object;

            var syntacticallyCorrectConstraint = new SyntacticallyCorrectConstraint()
            {
                Engine = qp
            };

            var queryFoundry = new Mock <IQuery>();
            var query        = queryFoundry.Object;

            //Method under test
            var res = syntacticallyCorrectConstraint.Matches(query);

            //Test conclusion
            Assert.That(res, Is.True);
        }
Ejemplo n.º 6
0
        public override ParserResult Parse()
        {
            ParserResult res = null;

            using (var connection = NewConnection(command.Connection.ConnectionString))
            {
                OpenConnection(connection);
                StartWatch();
                InitializeCommand(command, connection);
                try
                {
                    command.ExecuteReader(CommandBehavior.SchemaOnly);
                    res = ParserResult.NoParsingError();
                }
                catch (AdomdException ex)
                {
                    res = new ParserResult(ex.Message.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));
                }
            }
            StopWatch();
            return(res);
        }