public void Delete_ShouldThrowException_GivenCourseScheduleDetails() { // Insert the Session data row in the database. int sessionID = SessionTestTable.InsertWithValues( "6dk61ufcuzp3f7vs", "Session Alpha", new DateTime(2001, 1, 1)); // Insert the details CourseSchedule data row in the database. int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(sessionID: sessionID); // Build the Session data row. SessionDataRow sessionDataRow = new SessionDataRow(); sessionDataRow.SessionID = sessionID; sessionDataRow.SessionCode = "6dk61ufcuzp3f7vs"; sessionDataRow.Name = "Session Alpha"; sessionDataRow.StartDate = new DateTime(2001, 1, 1); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); try { // Delete the Session data row. SessionDataAccessComponent sessionDataAccessComponent = new SessionDataAccessComponent(); sessionDataAccessComponent.Delete(databaseConnection, sessionDataRow).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 Session data row in the database. int sessionID = SessionTestTable.InsertWithValues( "6dk61ufcuzp3f7vs", "Session Alpha", new DateTime(2001, 1, 1)); // Build the Session data row. SessionDataRow sessionDataRow = new SessionDataRow(); sessionDataRow.SessionID = sessionID; sessionDataRow.SessionCode = "6dk61ufcuzp3f7vs"; sessionDataRow.Name = "Session Alpha"; sessionDataRow.StartDate = new DateTime(2001, 1, 1); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Delete the Session data row. SessionDataAccessComponent sessionDataAccessComponent = new SessionDataAccessComponent(); sessionDataAccessComponent.Delete(databaseConnection, sessionDataRow).Wait(); } // Validate the Session data row was deleted in the database. SessionTestTable.AssertAbsence(sessionID); }