Exemple #1
0
        public void DeleteDatabase_DatabaseDoesntExist_ThrowException()
        {
            AbstractParser xmlParser          = CreateXMLParser();
            string         randomDatabaseName = VariousFunctions.GenerateRandomString(6);

            while (xmlParser.ExistDatabase(randomDatabaseName))
            {
                randomDatabaseName = VariousFunctions.GenerateRandomString(10);
            }
            Assert.IsFalse(xmlParser.ExistDatabase(randomDatabaseName));
            xmlParser.DeleteDatabase(randomDatabaseName);
        }
Exemple #2
0
        public void TestHigherOperatorWithString_SecondStringIsHigherThanFirstString_ReturnFalse()
        {
            Operator op  = OperatorFactory.GetOperatorFactory().GetOperator(OperatorKeys.HigherKey);
            string   st2 = "ha";
            string   st1 = VariousFunctions.GenerateRandomString(st2.Length);

            while (!(st2.CompareTo(st1) == 1))
            {
                st1 = VariousFunctions.GenerateRandomString(st2.Length);
            }
            Assert.AreEqual(1, st2.CompareTo(st1));
            Assert.IsFalse(op.evaluate(st1, st2));
        }
Exemple #3
0
        public void TestLessOperatorWithString_FirstStringIsLesserThanSecondString_ReturnTrue()
        {
            Operator op  = OperatorFactory.GetOperatorFactory().GetOperator(OperatorKeys.LessKey);
            string   st1 = "aa";
            string   st2 = VariousFunctions.GenerateRandomString(st1.Length);

            while (!(st1.CompareTo(st2) == -1))
            {
                st2 = VariousFunctions.GenerateRandomString(st1.Length);
            }
            Assert.AreEqual(-1, st1.CompareTo(st2)); //I dont trust nothing
            Assert.IsTrue(op.evaluate(st1, st2));
        }
        public void GrantPrivilege_DatabaseDoenstExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer  = ObjectConstructor.CreateDatabaseContainer();
            string             randomDatabaseName = VariousFunctions.GenerateRandomString(8);

            while (databaseContainer.ExistDatabase(randomDatabaseName))
            {
                randomDatabaseName = VariousFunctions.GenerateRandomString(8);
            }
            GrantPrivilege grantPrivilege = CreateGrantPrivilege(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.PrivilegesOfProfilesOnTablesTableName);

            grantPrivilege.SetData(SystemeConstants.InsertPrivilegeName, SystemeConstants.DefaultProfile, randomDatabaseName, "aaa");
            Assert.IsFalse(grantPrivilege.ValidateParameters());
        }
Exemple #5
0
        public void ExistCells_NoExist_ReturnFalse_StrType()
        {
            List <string> dataToWork = TestColumn.CreateStringCellData();
            Column        column     = ObjectConstructor.CreateColumn(dataToWork, TypesKeyConstants.StringTypeKey, "aaaa");
            string        randomStr  = "uwu";

            while (dataToWork.Contains(randomStr))
            {
                randomStr = VariousFunctions.GenerateRandomString(8);
            }
            Assert.IsFalse(dataToWork.Contains(randomStr));
            Assert.IsTrue(dataToWork.Count > 0);
            Assert.IsFalse(column.ExistCells(randomStr));
        }
Exemple #6
0
        public void RevoqueDatabasePrivilege_DatabaseDoenstExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            string             databaseName      = VariousFunctions.GenerateRandomString(8);

            while (databaseContainer.ExistDatabase(databaseName))
            {
                databaseName = VariousFunctions.GenerateRandomString(8);
            }
            RevokeDatabasePrivilege revoqueDatabasePrivilege = CreateRevoqueDatabasePrivilege(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.PrivilegesOfProfilesOnDatabasesTableName);

            revoqueDatabasePrivilege.SetData(SystemeConstants.DefaultProfile, databaseName, SystemeConstants.CreatePrivilegeName);
            Assert.IsFalse(revoqueDatabasePrivilege.ValidateParameters());
        }
Exemple #7
0
        public void ExistTable_TableNoExist_ReturnFalse()
        {
            AbstractParser xmlParser    = CreateXMLParser();
            Database       testDatabase = ObjectConstructor.CreateDatabaseFull("test3");

            xmlParser.SaveDatabase(testDatabase);
            string randomTableName = VariousFunctions.GenerateRandomString(6);

            while (testDatabase.ExistTable(randomTableName))
            {
                randomTableName = VariousFunctions.GenerateRandomString(6);
            }
            Assert.IsFalse(xmlParser.ExistTable(testDatabase.databaseName, randomTableName));
        }
        public void CreateDatabase_DatabaseDoenstExist_CreateDatabase()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            string             databaseName      = VariousFunctions.GenerateRandomString(8);

            while (databaseContainer.ExistDatabase(databaseName))
            {
                databaseName = VariousFunctions.GenerateRandomString(8);
            }
            CreateDatabase createDatabase = CreateCreateDatabase(databaseContainer, databaseName);

            Assert.IsTrue(createDatabase.ValidateParameters());
            createDatabase.Execute();
            Assert.IsTrue(databaseContainer.ExistDatabase(databaseName));
        }
        public void GrantDatabasePrivilege_ProfileDoenstExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            string             randomProfileName = VariousFunctions.GenerateRandomString(8);
            Column             column            = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.ProfilesTableName).GetColumn(SystemeConstants.ProfileNameColumn);

            while (column.ExistCells(randomProfileName))
            {
                randomProfileName = VariousFunctions.GenerateRandomString(8);
            }
            GrantDatabasePrivilege grantDatabasePrivilege = CreateGrantDatabasePrivilege(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.PrivilegesOfProfilesOnDatabasesTableName);

            grantDatabasePrivilege.SetData(SystemeConstants.CreatePrivilegeName, randomProfileName, SystemeConstants.DefaultDatabaseName);
            Assert.IsFalse(grantDatabasePrivilege.ValidateParameters());
        }
Exemple #10
0
        public void DropSecurityProfile_TheProfileDoesntExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            Column             column            = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.ProfilesTableName).GetColumn(SystemeConstants.ProfileNameColumn);
            string             profileName       = VariousFunctions.GenerateRandomString(8);

            while (column.ExistCells(profileName))
            {
                profileName = VariousFunctions.GenerateRandomString(8);
            }
            DropSecurityProfile dropSecurityProfile = CreateDropSecurityProfile(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.ProfilesTableName);

            dropSecurityProfile.SetTargetSecurityProfile(profileName);
            Assert.IsFalse(dropSecurityProfile.ValidateParameters());
        }
Exemple #11
0
        public void AddCell_NoExistsCellsWithSameData_StrType()
        {
            List <string> dataToWork = TestColumn.CreateStringCellData();
            Column        column     = ObjectConstructor.CreateColumn(dataToWork, TypesKeyConstants.StringTypeKey, "aaaa");
            string        randomStr  = "uwu";

            while (dataToWork.Contains(randomStr))
            {
                randomStr = VariousFunctions.GenerateRandomString(8);
            }
            Assert.IsFalse(dataToWork.Contains(randomStr));
            Assert.IsFalse(column.ExistCells(randomStr));
            column.AddCell(ObjectConstructor.CreateCell(column, randomStr, null));
            Assert.IsTrue(column.ExistCells(randomStr));
        }
Exemple #12
0
        public void DeleteUser_TheUserDoenstExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            ITable             table             = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.UsersTableName);
            Column             column            = table.GetColumn(SystemeConstants.UsersNameColumnName);
            string             username          = VariousFunctions.GenerateRandomString(8);

            while (column.ExistCells(username))
            {
                username = VariousFunctions.GenerateRandomString(8);
            }
            DeleteUser deleteUser = CreateDeleteUser(databaseContainer);

            deleteUser.SetTargetUserName(username);
            Assert.IsFalse(deleteUser.ValidateParameters());
        }
        public void CreateDatabase_DatabaseExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            string             databaseName      = VariousFunctions.GenerateRandomString(8);

            while (databaseContainer.ExistDatabase(databaseName))
            {
                databaseName = VariousFunctions.GenerateRandomString(8);
            }
            IDatabase database = new Database(databaseName);

            databaseContainer.AddDatabase(database);
            CreateDatabase createDatabase = CreateCreateDatabase(databaseContainer, database.databaseName);

            Assert.IsFalse(createDatabase.ValidateParameters());
        }
Exemple #14
0
        public void Insert_BadArguments_ConcretelyDatabaseDoesntExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer        = ObjectConstructor.CreateDatabaseContainer();
            string             doenstExistDatabaseNames = VariousFunctions.GenerateRandomString(6);

            while (databaseContainer.ExistDatabase(doenstExistDatabaseNames))
            {
                doenstExistDatabaseNames = VariousFunctions.GenerateRandomString(6);
            }
            Assert.IsFalse(databaseContainer.ExistDatabase(doenstExistDatabaseNames));
            Insert insert = CreateInsert(databaseContainer, doenstExistDatabaseNames, "aa");

            insert.AddValue("zz");
            Assert.IsFalse(insert.ValidateParameters());
            insert.Execute();
        }
Exemple #15
0
        public void DeleteCell_CellNoExist_DoNothing()
        {
            List <string> dataToWork       = TestColumn.CreateStringCellData();
            Column        column           = ObjectConstructor.CreateColumn(dataToWork, TypesKeyConstants.StringTypeKey, "aaaa");
            string        noRegisteredData = VariousFunctions.GenerateRandomString(19);

            while (column.ExistCells(noRegisteredData))
            {
                noRegisteredData = VariousFunctions.GenerateRandomString(19);
            }
            Row  row = new Row();
            Cell noRegisteredCell = new Cell(column, noRegisteredData, row);

            row.AddCell(noRegisteredCell);
            Assert.IsFalse(column.DestroyCell(noRegisteredCell));
        }
        public void CreateSecurityProfile_ProfileDoenstExits_CreateProfile()
        {
            IDatabaseContainer    databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            CreateSecurityProfile query             = CreateCreateSecurityProfile(databaseContainer);
            ITable table       = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.ProfilesTableName);
            Column column      = table.GetColumn(SystemeConstants.ProfileNameColumn);
            string profileName = VariousFunctions.GenerateRandomString(8);

            while (column.ExistCells(profileName))
            {
                profileName = VariousFunctions.GenerateRandomString(8);
            }
            query.SetProfileName(profileName);
            Assert.IsTrue(query.ValidateParameters());
            query.Execute();
            Assert.IsTrue(column.ExistCells(profileName));
        }
Exemple #17
0
        public void GetColumnCount_ReturnCoherentValue()
        {
            Table  table       = new Table("testRowCount");
            int    columnCount = table.GetColumnCount();
            string columnName  = VariousFunctions.GenerateRandomString(7);

            for (int i = 0; i < 100; i++)
            {
                while (table.ExistColumn(columnName))
                {
                    columnName = VariousFunctions.GenerateRandomString(7);
                }
                Assert.IsFalse(table.ExistColumn(columnName));
                table.AddColumn(new Column(columnName, DataTypesFactory.GetDataTypesFactory().GetDataType(TypesKeyConstants.StringTypeKey)));
                Assert.AreEqual(columnCount + i + 1, table.GetColumnCount());
            }
        }
Exemple #18
0
        public void Insert_BadArguments_ConcretelyTableDoesntExist_NoticeInValidate()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            Database           database          = new Database("TestInsert1");

            databaseContainer.AddDatabase(database);
            string doenstExistTableNames = VariousFunctions.GenerateRandomString(6);

            while (database.ExistTable(doenstExistTableNames))
            {
                doenstExistTableNames = VariousFunctions.GenerateRandomString(6);
            }
            Assert.IsFalse(database.ExistTable(doenstExistTableNames));
            Insert insert = CreateInsert(databaseContainer, database.databaseName, doenstExistTableNames);

            Assert.IsFalse(insert.ValidateParameters());
            insert.Execute();
        }
Exemple #19
0
        public void Select_BadArguments_TableDoesntExist_NoticedInValidateParameters()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            Database           database          = ObjectConstructor.CreateDatabaseFull("test1");

            databaseContainer.AddDatabase(database);
            string noInDatabaseTableName = VariousFunctions.GenerateRandomString(10); //Do while instead of while is okkkkk

            while (database.ExistTable(noInDatabaseTableName))
            {
                noInDatabaseTableName = VariousFunctions.GenerateRandomString(10);
            }
            Select select = CreateSelect(databaseContainer, database.databaseName, noInDatabaseTableName, true);

            Assert.IsFalse(select.ValidateParameters());
            select.Execute();
            Assert.AreEqual(0, select.GetAfectedRowCount());
            Console.WriteLine(select.GetResult()); //It is only to see the message not to trace execution
        }
        public void RevokePrivilege_AllParamsExistsButTheCombinationIsNotValid_NoticeInValidate()
        {
            //Prefase
            IDatabaseContainer    databaseContainer     = ObjectConstructor.CreateDatabaseContainer();
            CreateSecurityProfile createSecurityProfile = TestCreateSecurityProfile.CreateCreateSecurityProfile(databaseContainer);
            Column profileNamesColumn = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.ProfilesTableName).GetColumn(SystemeConstants.ProfileNameColumn);
            string profileName        = VariousFunctions.GenerateRandomString(8);

            while (profileNamesColumn.ExistCells(profileName))
            {
                profileName = VariousFunctions.GenerateRandomString(8);
            }
            createSecurityProfile.SetProfileName(profileName);
            createSecurityProfile.ValidateParameters();
            createSecurityProfile.Execute();
            //TEST
            RevoquePrivilege revoquePrivilege = CreateRevokePrivilege(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.PrivilegesOfProfilesOnTablesTableName);

            revoquePrivilege.SetData(profileName, SystemeConstants.SystemDatabaseName, SystemeConstants.ProfilesTableName, SystemeConstants.InsertPrivilegeName);
            Assert.IsFalse(revoquePrivilege.ValidateParameters());
        }
Exemple #21
0
        public void DeleteUser_TheUserExist_DeleteUser()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            ITable             table             = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.UsersTableName);
            Column             column            = table.GetColumn(SystemeConstants.UsersNameColumnName);
            string             username          = VariousFunctions.GenerateRandomString(8);

            while (column.ExistCells(username))
            {
                username = VariousFunctions.GenerateRandomString(8);
            }
            Row row = table.CreateRowDefinition();

            row.GetCell(SystemeConstants.UsersNameColumnName).data = username;
            table.AddRow(row);
            DeleteUser deleteUser = CreateDeleteUser(databaseContainer);

            deleteUser.SetTargetUserName(username);
            Assert.IsTrue(deleteUser.ValidateParameters());
            deleteUser.Execute();
            Assert.IsFalse(column.ExistCells(username));
        }
Exemple #22
0
        public void DropSecurity_TheProfileCanDrop_DropTheProfile()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            ITable             table             = databaseContainer.GetDatabase(SystemeConstants.SystemDatabaseName).GetTable(SystemeConstants.ProfilesTableName);
            Column             column            = table.GetColumn(SystemeConstants.ProfileNameColumn);
            string             profileName       = VariousFunctions.GenerateRandomString(8);

            while (column.ExistCells(profileName))
            {
                profileName = VariousFunctions.GenerateRandomString(8);
            }
            Row row = table.CreateRowDefinition();

            row.GetCell(SystemeConstants.ProfileNameColumn).data = profileName;
            table.AddRow(row);
            int numberOfRow = table.GetRowCount();
            DropSecurityProfile dropSecurityProfile = CreateDropSecurityProfile(databaseContainer, SystemeConstants.SystemDatabaseName, SystemeConstants.ProfilesTableName);

            dropSecurityProfile.SetTargetSecurityProfile(profileName);
            Assert.IsTrue(dropSecurityProfile.ValidateParameters());
            dropSecurityProfile.Execute();
            Assert.AreEqual(numberOfRow - 1, table.GetRowCount());
        }
Exemple #23
0
        public void Select_BadArguments_WhereClauseColumnsDontExist_NoticedInValidateParameters()
        {
            IDatabaseContainer databaseContainer = ObjectConstructor.CreateDatabaseContainer();
            Database           database          = new Database("aa");
            ITable             table             = new Table("table1");
            Column             column            = new Column("c1", DataTypesFactory.GetDataTypesFactory().GetDataType(TypesKeyConstants.StringTypeKey));

            table.AddColumn(column);
            database.AddTable(table);
            databaseContainer.AddDatabase(database);
            string noInTableColumnName = VariousFunctions.GenerateRandomString(10);

            while (table.ExistColumn(noInTableColumnName))
            {
                noInTableColumnName = VariousFunctions.GenerateRandomString(10);
            }
            Select select = CreateSelect(databaseContainer, database.databaseName, table.tableName, true);

            select.whereClause.AddCritery(noInTableColumnName, "a", Operator.equal);
            Assert.IsFalse(select.ValidateParameters());
            select.Execute();
            Assert.AreEqual(0, select.GetAfectedRowCount());
            Console.WriteLine(select.GetResult());
        }