public void Delete_ShouldThrowException_GivenCourseGroupDetails() { // Insert the master data rows in the database. int sessionID = SessionTestTable.InsertPlaceholder(); // Insert the CourseSchedule data row in the database. int courseScheduleID = CourseScheduleTestTable.InsertWithValues( "zzcj32kpd6huzp1n", sessionID, 1, new TimeSpan(9, 15, 0)); // Insert the details CourseGroup data row in the database. int courseGroupID = CourseGroupTestTable.InsertPlaceholder(courseScheduleID: courseScheduleID); // Build the CourseSchedule data row. CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow(); courseScheduleDataRow.CourseScheduleID = courseScheduleID; courseScheduleDataRow.CourseScheduleCode = "zzcj32kpd6huzp1n"; courseScheduleDataRow.SessionID = sessionID; courseScheduleDataRow.DayOfWeek = 1; courseScheduleDataRow.Time = new TimeSpan(9, 15, 0); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); try { // Delete the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataAccessComponent.Delete(databaseConnection, courseScheduleDataRow).Wait(); // Validate an exception was thrown. Assert.Fail(); } catch (AggregateException ex) { // Validate an SQL exception was thrown. Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(SqlException)); } } }
public void Delete_ShouldSucceed() { // Insert the master data rows in the database. int sessionID = SessionTestTable.InsertPlaceholder(); // Insert the CourseSchedule data row in the database. int courseScheduleID = CourseScheduleTestTable.InsertWithValues( "zzcj32kpd6huzp1n", sessionID, 1, new TimeSpan(9, 15, 0)); // Build the CourseSchedule data row. CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow(); courseScheduleDataRow.CourseScheduleID = courseScheduleID; courseScheduleDataRow.CourseScheduleCode = "zzcj32kpd6huzp1n"; courseScheduleDataRow.SessionID = sessionID; courseScheduleDataRow.DayOfWeek = 1; courseScheduleDataRow.Time = new TimeSpan(9, 15, 0); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Delete the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataAccessComponent.Delete(databaseConnection, courseScheduleDataRow).Wait(); } // Validate the CourseSchedule data row was deleted in the database. CourseScheduleTestTable.AssertAbsence(courseScheduleID); }