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); }
public override bool Check(string query) { string[] arguments = CreateUtils.GetArgumentsFromQuery(query); if (arguments.Length != 2) { throw new MalformedArgumentsException(); } return(this.CheckNext(query)); }
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); }
public override bool Check(string query) { var tableName = CreateUtils.GetTableNameFromQuery(query); if (!Regex.IsMatch(tableName, @"^[a-zA-Z]+$")) { throw new ForbiddenTableNameException(tableName); } if (_database.GetTableNames().Contains(tableName)) { throw new TableAlreadyExistsException(tableName); } return(this.CheckNext(query)); }
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)); }
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); }
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)); }
public void GetTableNameFromQuery_ShouldReturnValidTableName(string query, string expectedTableName) { var actual = CreateUtils.GetTableNameFromQuery(query); Assert.Equal(actual, expectedTableName); }