public void DefaultValues()
        {
            var sut = new UnknownStatement();

            Assert.AreNotEqual(0, sut.GetHashCode());
            Assert.AreNotEqual(1, sut.GetHashCode());
        }
        public void UnknownStatementConstructorTest()
        {
            Token            invalidToken = new Token();
            UnknownStatement target       = new UnknownStatement(invalidToken);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
        public void Equality()
        {
            var a = new UnknownStatement();
            var b = new UnknownStatement();

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Exemple #4
0
        /// <summary>
        /// Parses the SQL code and loads the SQL statements into the StringCollection <see cref="Results"/>.
        /// </summary>
        /// <returns>The number of statements found.</returns>
        public int Parse()
        {
            _results.Clear();
            foreach (var statement in _parser.Parse())
            {
                string newParserToken;
                if (IsSetTermStatement(statement.CleanText, out newParserToken))
                {
                    _parser.Tokens = new[] { newParserToken };
                    continue;
                }

                if (statement.CleanText != string.Empty)
                {
                    var type = GetStatementType(statement.CleanText);
                    if (type != null)
                    {
                        statement.SetStatementType((SqlStatementType)type);
                        _results.Add(statement);
                        continue;
                    }
                }

                if (statement.Text.Trim() != string.Empty)
                {
                    var unknownStatementEventArgs = new UnknownStatementEventArgs(statement);
                    UnknownStatement?.Invoke(this, unknownStatementEventArgs);
                    if (unknownStatementEventArgs.Handled && !unknownStatementEventArgs.Ignore)
                    {
                        statement.SetStatementType(unknownStatementEventArgs.NewStatementType);
                        _results.Add(statement);
                        continue;
                    }
                    else if (!unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
                    {
                        continue;
                    }
                    else if (unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
                    {
                        throw new InvalidOperationException($"Both {nameof(UnknownStatementEventArgs.Handled)} and {nameof(UnknownStatementEventArgs.Ignore)} should not be set.");
                    }
                    else
                    {
                        throw new ArgumentException($"The type of the SQL statement could not be determined. See also {nameof(UnknownStatement)} event.{Environment.NewLine}Statement: {statement.Text}.");
                    }
                }
            }
            return(_results.Count);
        }
        public void UnknownStatement()
        {
            var sst = new UnknownStatement();

            AssertPrint(sst, "???;");
        }
Exemple #6
0
        private IEnumerable <IStatement> ParseMethodExecutions(IEnumerable <string> lines)
        {
            var result = new List <IStatement>();

            int controlsequenceDepth = 0;

            foreach (string line in lines.Select(entry => entry.Trim()))
            {
                if (this.IsLineIgnored(line))
                {
                    continue;
                }

                if (line == "{")
                {
                    continue;
                }

                if (line == "}")
                {
                    if (controlsequenceDepth > 0)
                    {
                        result.Add(new ControlStatementEnd());
                        controlsequenceDepth--;
                    }

                    continue;
                }


                IStatement statement;
                if (this.Class.Name == "FightCommonInformations")
                {
                }

                if (Regex.IsMatch(line, ControlStatement.Pattern))
                {
                    statement = ControlStatement.Parse(line);
                    controlsequenceDepth++;
                }

                else if (Regex.IsMatch(line, AssignationStatement.Pattern))
                {
                    statement = AssignationStatement.Parse(line);
                }

                else if (Regex.IsMatch(line, InvokeExpression.Pattern))
                {
                    statement = InvokeExpression.Parse(line);
                    if (!string.IsNullOrEmpty((statement as InvokeExpression).ReturnVariableAssignation) &&
                        string.IsNullOrEmpty((statement as InvokeExpression).Preffix) &&
                        this.Fields.Count(entry => entry.Name == ((InvokeExpression)statement).ReturnVariableAssignation) > 0)
                    {
                        (statement as InvokeExpression).Preffix = "("
                                                                  + this.Fields.Where(entry =>
                                                                                      entry.Name == ((InvokeExpression)statement).ReturnVariableAssignation)
                                                                  .First()
                                                                  .Type
                                                                  + ")"; // cast
                    }

                    // cast to generic type
                    if (!string.IsNullOrEmpty((statement as InvokeExpression).Target) &&
                        (statement as InvokeExpression).Name == "Add" &&
                        this.Fields.Count(entry => entry.Name == ((InvokeExpression)statement).Target.Split('.').Last()) > 0)
                    {
                        string generictype = this.Fields.Where(entry => entry.Name == ((InvokeExpression)statement).Target.Split('.').Last()).First().Type.Split('<').Last().Split('>').First();

                        (statement as InvokeExpression).Args[0] = "(" + generictype + ")" + (statement as InvokeExpression).Args[0];
                    }
                }

                else
                {
                    statement = new UnknownStatement {
                        Value = line
                    }
                };

                result.Add(statement);
            }

            return(result);
        }
        public void VisitorWithReturnIsImplemented()
        {
            var sut = new UnknownStatement();

            sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23));
        }