Exemplo n.º 1
0
        public void ReCreateIndex(IConnectionManager connection)
        {
            //Arrange
            string indexName = "ix_IndexTest2";

            CreateTableTask.Create(connection, "IndexCreationTable2", new List <TableColumn>()
            {
                new TableColumn("Key1", "INT", allowNulls: false),
                new TableColumn("Key2", "INT", allowNulls: true),
            });
            CreateIndexTask.CreateOrRecreate(connection, indexName, "IndexCreationTable2",
                                             new List <string>()
            {
                "Key1", "Key2"
            });

            //Act
            CreateIndexTask.CreateOrRecreate(connection, indexName, "IndexCreationTable2",
                                             new List <string>()
            {
                "Key1", "Key2"
            });

            //Assert
            Assert.True(IfIndexExistsTask.IsExisting(connection, "ix_IndexTest2", "IndexCreationTable2"));
        }
Exemplo n.º 2
0
        public void CreateIndexWithInclude()
        {
            //Arrange
            string indexName = "ix_IndexTest3";

            CreateTableTask.Create(SqlConnection, "dbo.IndexCreation3", new List <TableColumn>()
            {
                new TableColumn("Key1", "INT", allowNulls: false),
                new TableColumn("Key2", "CHAR(2)", allowNulls: true),
                new TableColumn("Value1", "NVARCHAR(10)", allowNulls: true),
                new TableColumn("Value2", "DECIMAL(10,2)", allowNulls: false),
            });
            //Act
            CreateIndexTask.CreateOrRecreate(SqlConnection, indexName, "dbo.IndexCreation3",
                                             new List <string>()
            {
                "Key1", "Key2"
            },
                                             new List <string>()
            {
                "Value1", "Value2"
            });
            //Assert
            Assert.True(IfIndexExistsTask.IsExisting(SqlConnection, "ix_IndexTest3", "dbo.IndexCreation3"));
        }
Exemplo n.º 3
0
        public void IfIndexExists(IConnectionManager connection)
        {
            //Arrange
            SqlTask.ExecuteNonQuery(connection, "Create index test table"
                                    , $@"CREATE TABLE indextable (col1 INT NULL)");

            //Act
            var existsBefore = IfIndexExistsTask.IsExisting(connection, "index_test", "indextable");

            SqlTask.ExecuteNonQuery(connection, "Create test index"
                                    , $@"CREATE INDEX index_test ON indextable (col1)");
            var existsAfter = IfIndexExistsTask.IsExisting(connection, "index_test", "indextable");

            //Assert
            Assert.False(existsBefore);
            Assert.True(existsAfter);
        }
Exemplo n.º 4
0
        public void Drop(IConnectionManager connection)
        {
            //Arrange
            CreateTableTask.Create(connection, "DropIndexTable", new List <TableColumn>()
            {
                new TableColumn("Test1", "INT")
            });
            CreateIndexTask.CreateOrRecreate(connection, "IndexToDrop", "DropIndexTable",
                                             new List <string>()
            {
                "Test1"
            });
            Assert.True(IfIndexExistsTask.IsExisting(connection, "IndexToDrop", "DropIndexTable"));

            //Act
            DropIndexTask.Drop(connection, "IndexToDrop", "DropIndexTable");

            //Assert
            Assert.False(IfIndexExistsTask.IsExisting(connection, "IndexToDrop", "DropIndexTable"));
        }
Exemplo n.º 5
0
        public void CreateTableWithPrimaryKeyAndIndex(IConnectionManager connection)
        {
            //Arrange
            List <TableColumn> columns = new List <TableColumn>()
            {
                new TableColumn("Id", "INT", allowNulls: false, isPrimaryKey: true),
                new TableColumn("value2", "DATE", allowNulls: true)
            };

            //Act
            CreateTableTask.Create(connection, "CreateTablePKWithIDX", columns);
            CreateIndexTask.CreateOrRecreate(connection, "testidx", "CreateTablePKWithIDX", new List <string>()
            {
                "value2"
            });

            //Assert
            Assert.True(IfTableOrViewExistsTask.IsExisting(connection, "CreateTablePKWithIDX"));
            Assert.True(IfIndexExistsTask.IsExisting(connection, "testidx", "CreateTablePKWithIDX"));
            var td = TableDefinition.GetDefinitionFromTableName("CreateTablePKWithIDX", connection);

            Assert.True(td.Columns.Where(col => col.IsPrimaryKey).Count() == 1);
        }