void ResetTable(SqlConnection connection) { ScriptExecutor exe = new ScriptExecutor(); int c = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Classroom')", connection).ExecuteScalar(); if (c > 0) { new SqlCommand("DROP TABLE Classroom", connection).ExecuteScalar(); } int s = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Student')", connection).ExecuteScalar(); if (s > 0) { new SqlCommand("DROP TABLE Student", connection).ExecuteScalar(); } int t = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Teacher')", connection).ExecuteScalar(); if (t > 0) { new SqlCommand("DROP TABLE Teacher", connection).ExecuteScalar(); } exe.ScriptExe(DbInit.CreateTableTeacher(), connection); exe.ScriptExe(DbInsert.InsertTeacherTable(), connection); exe.ScriptExe(DbInit.CreateTableStudent(), connection); exe.ScriptExe(DbInsert.InsertStudentTable(), connection); exe.ScriptExe(DbInit.CreateTableClassroom(), connection); exe.ScriptExe(DbInsert.InsertClassroomTable(), connection); }
public void T4_check_if_Student_table_is_created() { using (SqlConnection connection = new SqlConnection(DbInit.GetConnectionString())) { connection.Open(); ScriptExecutor exe = new ScriptExecutor(); int t = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Student')", connection).ExecuteScalar(); if (t > 0) { new SqlCommand("DROP TABLE Student", connection).ExecuteScalar(); } exe.ScriptExe(DbInit.CreateTableStudent(), connection); string cmdText = @"IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='Student ') SELECT 1 ELSE SELECT 0"; SqlCommand DateCheck = new SqlCommand(cmdText, connection); int x = Convert.ToInt32(DateCheck.ExecuteScalar()); x.Should().Be(1); DataTable datatable = new DataTable(); string query = "select * from Student"; SqlCommand cmd = new SqlCommand(query, connection); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(datatable); datatable.Columns.Contains("Guid").Should().Be(true); datatable.Columns.Contains("Name").Should().Be(true); datatable.Columns.Contains("Semestre").Should().Be(true); datatable.Columns.Contains("Orientation").Should().Be(true); datatable.Columns.Contains("BirthDate").Should().Be(true); datatable.Columns.Contains("MainTeacher").Should().Be(true); connection.Close(); } }