Esempio n. 1
0
        public override bool Check(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query);
            var tableName = InsertUtils.GetTableNameFromQuery(query);

            var columns = InsertUtils.GetColumnsFromArguments(arguments).ToArray();
            var values  = arguments[2].Split(",").Select(x => x.Trim()).ToArray();

            var columnProperties = _database.GetTable(tableName).GetColumnProperties();

            for (var i = 0; i < columns.Count(); i++)
            {
                if (GeneralUtils.ContainsForbiddenCharacters(values[i]))
                {
                    throw new ForbiddenCharactersException(values[i]);
                }

                var type = columnProperties.First(x => x.Name == columns[i]).Type;
                if (!GeneralUtils.IsTypeValid(type, values[i]))
                {
                    throw new InvalidColumnTypeException(columns[i], type);
                }
            }

            return(this.CheckNext(query));
        }
Esempio n. 2
0
        public void GetValuesKeywordFromArguments_ShouldReturnValidKeyword(string query)
        {
            var actual = InsertUtils.GetValuesKeywordFromArguments(InsertUtils.GetArgumentsFromQuery(query));

            var expected = "VALUES";

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void GetTableNameFromQuery_ShouldReturnValidTableName(string query)
        {
            var actual = InsertUtils.GetTableNameFromQuery(query);

            var expected = "users";

            Assert.Equal(expected, actual);
        }
Esempio n. 4
0
        public void GetArgumentsFromQuery_ShouldReturnValidStringArray(string query)
        {
            var actual = InsertUtils.GetArgumentsFromQuery(query);

            var expected = new string[3] {
                "INSERT INTO users", "email, phoneNumber) VALUES", "\"[email protected]\", 703503);"
            };

            Assert.Equal(expected, actual);
        }
Esempio n. 5
0
        public override bool Check(string query)
        {
            var tableName = InsertUtils.GetTableNameFromQuery(query);

            if (!_database.GetTableNames().Contains(tableName))
            {
                throw new TableNotFoundException(tableName);
            }

            return(this.CheckNext(query));
        }
Esempio n. 6
0
        public void GetValuesFromArguments_ShouldReturnValidValues(string query)
        {
            var actual = InsertUtils.GetValuesFromArguments(InsertUtils.GetArgumentsFromQuery(query)).ToArray();

            var expected = new string[] {
                "\"[email protected]\"",
                "703503",
                "true"
            };

            Assert.Equal(expected, actual);
        }
Esempio n. 7
0
        public void GetColumnsFromArguments_ShouldReturnValidColumns(string query)
        {
            var actual = InsertUtils.GetColumnsFromArguments(InsertUtils.GetArgumentsFromQuery(query)).ToArray();

            var expected = new string[] {
                "email",
                "phoneNumber",
                "isAdult"
            };

            Assert.Equal(expected, actual);
        }
Esempio n. 8
0
        private void InsertRow(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query.Substring(0, query.Length - 2));
            var tableName = InsertUtils.GetTableNameFromQuery(query);

            var columnNames = InsertUtils.GetColumnsFromArguments(arguments).ToList();
            var values      = InsertUtils.GetValuesFromArguments(arguments).Select(x => GeneralUtils.TransformStringValueToRealValue(x)).ToList();

            var record = new Record(columnNames, values);

            this._database.GetTable(tableName).AddRecord(record);
        }
Esempio n. 9
0
        public override bool Check(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query);

            var columns = InsertUtils.GetColumnsFromArguments(arguments);
            var values  = InsertUtils.GetValuesFromArguments(arguments);

            if (columns.Count() != values.Count())
            {
                throw new MalformedColumnsException();
            }

            return(this.CheckNext(query));
        }
Esempio n. 10
0
        public override bool Check(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query);
            var tableName = InsertUtils.GetTableNameFromQuery(query);

            var actualColumnNumber   = InsertUtils.GetColumnsFromArguments(arguments).Count();
            var expectedColumnNumber = _database.GetTable(tableName).GetColumnProperties().Count();

            if (actualColumnNumber != expectedColumnNumber)
            {
                throw new InvalidColumnNumberException(actualColumnNumber, expectedColumnNumber);
            }

            return(this.CheckNext(query));
        }
Esempio n. 11
0
        public override bool Check(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query);

            if (arguments.Length != 3)
            {
                throw new MalformedArgumentsException();
            }

            var valuesKeyword = InsertUtils.GetValuesKeywordFromArguments(arguments);

            if (valuesKeyword != "VALUES")
            {
                throw new MalformedArgumentsException();
            }

            return(this.CheckNext(query));
        }
Esempio n. 12
0
        public override bool Check(string query)
        {
            var arguments = InsertUtils.GetArgumentsFromQuery(query);
            var tableName = InsertUtils.GetTableNameFromQuery(query);

            var queryColumns    = InsertUtils.GetColumnsFromArguments(arguments);
            var databaseColumns = _database.GetTable(tableName).GetColumnProperties().Select(x => x.Name).ToArray();

            foreach (var column in queryColumns)
            {
                if (!databaseColumns.Contains(column))
                {
                    throw new UnknownColumnNameException(column);
                }
            }

            return(this.CheckNext(query));
        }