public void Create_ShouldThrowException_GivenInvalidSessionID() { // Insert the master data rows in the database. int sessionID = SessionTestTable.InsertPlaceholder(); // Build the CourseSchedule data row. CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow(); courseScheduleDataRow.CourseScheduleCode = "zzcj32kpd6huzp1n"; courseScheduleDataRow.SessionID = -1; 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 { // Create the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataAccessComponent.Create(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); }
public void ReadByCourseScheduleCode_ShouldReturnNull() { // 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 database connection. CourseScheduleDataRow courseScheduleDataRow = null; using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Read the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataRow = courseScheduleDataAccessComponent.ReadByCourseScheduleCode(databaseConnection, "").Result; } // Validate the CourseSchedule data row. Assert.IsNull(courseScheduleDataRow); }
/// <summary> /// Inserts a placeholder row. /// </summary> public static int InsertPlaceholder(string courseScheduleCode = default(string), int sessionID = default(int), int dayOfWeek = default(int), TimeSpan time = default(TimeSpan)) { // Provide a value for all the columns. if (courseScheduleCode == default(string)) { courseScheduleCode = Guid.NewGuid().ToString(); } if (sessionID == default(int)) { sessionID = SessionTestTable.InsertPlaceholder(); } if (dayOfWeek == default(int)) { dayOfWeek = 0; } if (time == default(TimeSpan)) { time = new TimeSpan(10, 1, 1); } // Insert the row. int courseScheduleID = InsertWithValues(courseScheduleCode, sessionID, dayOfWeek, time); // Return the generated ID. return(courseScheduleID); }
public void Update_ShouldThrowException_GivenDuplicateCourseScheduleCode() { // Insert the first master data rows in the database. int firstSessionID = SessionTestTable.InsertPlaceholder(); // Insert the second master data rows in the database. int secondSessionID = SessionTestTable.InsertPlaceholder(); // Insert the CourseSchedule data row in the database. int courseScheduleID = CourseScheduleTestTable.InsertWithValues( "zzcj32kpd6huzp1n", firstSessionID, 1, new TimeSpan(9, 15, 0)); // Insert the duplicate CourseSchedule data row in the database. int duplicateCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder(courseScheduleCode: "8zu96quwvk70ng1e"); // Build the CourseSchedule data row. CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow(); courseScheduleDataRow.CourseScheduleID = courseScheduleID; courseScheduleDataRow.CourseScheduleCode = "8zu96quwvk70ng1e"; courseScheduleDataRow.SessionID = secondSessionID; courseScheduleDataRow.DayOfWeek = 2; courseScheduleDataRow.Time = new TimeSpan(10, 30, 0); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); try { // Update the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataAccessComponent.Update(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 Update_ShouldSucceed() { // Insert the first master data rows in the database. int firstSessionID = SessionTestTable.InsertPlaceholder(); // Insert the second master data rows in the database. int secondSessionID = SessionTestTable.InsertPlaceholder(); // Insert the CourseSchedule data row in the database. int courseScheduleID = CourseScheduleTestTable.InsertWithValues( "zzcj32kpd6huzp1n", firstSessionID, 1, new TimeSpan(9, 15, 0)); // Build the CourseSchedule data row. CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow(); courseScheduleDataRow.CourseScheduleID = courseScheduleID; courseScheduleDataRow.CourseScheduleCode = "8zu96quwvk70ng1e"; courseScheduleDataRow.SessionID = secondSessionID; courseScheduleDataRow.DayOfWeek = 2; courseScheduleDataRow.Time = new TimeSpan(10, 30, 0); // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Update the CourseSchedule data row. CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent(); courseScheduleDataAccessComponent.Update(databaseConnection, courseScheduleDataRow).Wait(); } // Validate the CourseSchedule data row was updated in the database. CourseScheduleTestTable.AssertPresence( courseScheduleID, "8zu96quwvk70ng1e", secondSessionID, 2, new TimeSpan(10, 30, 0)); }