Beispiel #1
0
        public void GetArgumentsFromQuery_ShouldReturnValidStringArray(string query)
        {
            var actual = CreateUtils.GetArgumentsFromQuery(query);

            var expected = new string[] { "CREATE TABLE users", "email text, phoneNumber int);" };

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public override bool Check(string query)
        {
            string[] arguments = CreateUtils.GetArgumentsFromQuery(query);
            if (arguments.Length != 2)
            {
                throw new MalformedArgumentsException();
            }

            return(this.CheckNext(query));
        }
Beispiel #3
0
        public void GetColumnsFromArguments_ShouldReturnValidColumns()
        {
            var query = "CREATE TABLE users (  email   text,   phoneNumber   int  ";

            var arguments = CreateUtils.GetArgumentsFromQuery(query);

            var actual = CreateUtils.GetColumnsFromArguments(arguments);

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

            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public override bool Check(string query)
        {
            var arguments = CreateUtils.GetArgumentsFromQuery(query);
            var columns   = CreateUtils.GetColumnsFromArguments(arguments);

            foreach (var column in columns)
            {
                if (!GeneralUtils.GetSupportedTypes().Contains(column[1].ToLower()))
                {
                    throw new UnsupportedTypeException(column[1]);
                }
            }

            return(this.CheckNext(query));
        }
Beispiel #5
0
        private void CreateTable(string query)
        {
            var arguments = CreateUtils.GetArgumentsFromQuery(query.Remove(query.Length - 2));
            var tableName = CreateUtils.GetTableNameFromQuery(query);
            var columns   = CreateUtils.GetColumnsFromArguments(arguments);

            var table = new Table(tableName);

            foreach (var element in columns)
            {
                var column = new Column(new Properties(element[0], element[1]));
                table.AddColumn(column);
            }

            this._database.AddTable(table);
        }
Beispiel #6
0
        public override bool Check(string query)
        {
            var arguments = CreateUtils.GetArgumentsFromQuery(query);
            var columns   = CreateUtils.GetColumnsFromArguments(arguments);

            if (!columns.All(x => x.Length == 2))
            {
                throw new MalformedColumnsException();
            }

            foreach (var column in columns)
            {
                if (!GeneralUtils.ContainsOnlyAlphaNumericCharacters(column[0]))
                {
                    throw new ForbiddenCharactersException(column[0]);
                }
                if (column[0].ToLower() == "id")
                {
                    throw new ForbiddenColumnNameException(column[0]);
                }
            }

            return(this.CheckNext(query));
        }