public void Create_ShouldThrowException_GivenInvalidCourseScheduleID() { // Insert the master data rows in the database. int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Build the CourseGroup data row. CourseGroupDataRow courseGroupDataRow = new CourseGroupDataRow(); courseGroupDataRow.CourseGroupCode = "5s1cgndj6e5x0uvz"; courseGroupDataRow.CourseScheduleID = -1; courseGroupDataRow.PlacesCount = 1; // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); try { // Create the CourseGroup data row. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataAccessComponent.Create(databaseConnection, courseGroupDataRow).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 ReadByCourseGroupCode_ShouldReturnNull() { // Insert the master data rows in the database. int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the CourseGroup data row in the database. int courseGroupID = CourseGroupTestTable.InsertWithValues( "5s1cgndj6e5x0uvz", courseScheduleID, 1); // Build the database connection. CourseGroupDataRow courseGroupDataRow = null; using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Read the CourseGroup data row. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataRow = courseGroupDataAccessComponent.ReadByCourseGroupCode(databaseConnection, "").Result; } // Validate the CourseGroup data row. Assert.IsNull(courseGroupDataRow); }
public void Delete_ShouldSucceed() { // Insert the master data rows in the database. int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the CourseGroup data row in the database. int courseGroupID = CourseGroupTestTable.InsertWithValues( "5s1cgndj6e5x0uvz", courseScheduleID, 1); // Build the CourseGroup data row. CourseGroupDataRow courseGroupDataRow = new CourseGroupDataRow(); courseGroupDataRow.CourseGroupID = courseGroupID; courseGroupDataRow.CourseGroupCode = "5s1cgndj6e5x0uvz"; courseGroupDataRow.CourseScheduleID = courseScheduleID; courseGroupDataRow.PlacesCount = 1; // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Delete the CourseGroup data row. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataAccessComponent.Delete(databaseConnection, courseGroupDataRow).Wait(); } // Validate the CourseGroup data row was deleted in the database. CourseGroupTestTable.AssertAbsence(courseGroupID); }
public void ReadByCourseScheduleID_ShouldReturnMultipleDataRows() { // Insert the master data rows in the database. int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the first CourseGroup data row in the database. int firstCourseGroupID = CourseGroupTestTable.InsertWithValues( "5s1cgndj6e5x0uvz", courseScheduleID, 1); // Insert the second CourseGroup data row in the database. int secondCourseGroupID = CourseGroupTestTable.InsertWithValues( "78zcn25ynkaz50ef", courseScheduleID, 2); // Insert the third CourseGroup data row in the database. int thirdCourseGroupID = CourseGroupTestTable.InsertWithValues( "q5692qwy70qde9uv", courseScheduleID, 3); // Build the database connection. CourseGroupDataRow[] courseGroupDataRows = null; using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Read the CourseGroup data rows. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataRows = courseGroupDataAccessComponent.ReadByCourseScheduleID(databaseConnection, courseScheduleID).Result; } // Validate the CourseGroup data rows. Assert.IsNotNull(courseGroupDataRows); Assert.AreEqual(3, courseGroupDataRows.Length); // Validate the first CourseGroup data row. Assert.AreEqual(firstCourseGroupID, courseGroupDataRows[0].CourseGroupID); Assert.AreEqual("5s1cgndj6e5x0uvz", courseGroupDataRows[0].CourseGroupCode); Assert.AreEqual(courseScheduleID, courseGroupDataRows[0].CourseScheduleID); Assert.AreEqual(1, courseGroupDataRows[0].PlacesCount); // Validate the second CourseGroup data row. Assert.AreEqual(secondCourseGroupID, courseGroupDataRows[1].CourseGroupID); Assert.AreEqual("78zcn25ynkaz50ef", courseGroupDataRows[1].CourseGroupCode); Assert.AreEqual(courseScheduleID, courseGroupDataRows[1].CourseScheduleID); Assert.AreEqual(2, courseGroupDataRows[1].PlacesCount); // Validate the third CourseGroup data row. Assert.AreEqual(thirdCourseGroupID, courseGroupDataRows[2].CourseGroupID); Assert.AreEqual("q5692qwy70qde9uv", courseGroupDataRows[2].CourseGroupCode); Assert.AreEqual(courseScheduleID, courseGroupDataRows[2].CourseScheduleID); Assert.AreEqual(3, courseGroupDataRows[2].PlacesCount); }
public void Update_ShouldThrowException_GivenDuplicateCourseGroupCode() { // Insert the first master data rows in the database. int firstCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the second master data rows in the database. int secondCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the CourseGroup data row in the database. int courseGroupID = CourseGroupTestTable.InsertWithValues( "5s1cgndj6e5x0uvz", firstCourseScheduleID, 1); // Insert the duplicate CourseGroup data row in the database. int duplicateCourseGroupID = CourseGroupTestTable.InsertPlaceholder(courseGroupCode: "78zcn25ynkaz50ef"); // Build the CourseGroup data row. CourseGroupDataRow courseGroupDataRow = new CourseGroupDataRow(); courseGroupDataRow.CourseGroupID = courseGroupID; courseGroupDataRow.CourseGroupCode = "78zcn25ynkaz50ef"; courseGroupDataRow.CourseScheduleID = secondCourseScheduleID; courseGroupDataRow.PlacesCount = 2; // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); try { // Update the CourseGroup data row. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataAccessComponent.Update(databaseConnection, courseGroupDataRow).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_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 Update_ShouldSucceed() { // Insert the first master data rows in the database. int firstCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the second master data rows in the database. int secondCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); // Insert the CourseGroup data row in the database. int courseGroupID = CourseGroupTestTable.InsertWithValues( "5s1cgndj6e5x0uvz", firstCourseScheduleID, 1); // Build the CourseGroup data row. CourseGroupDataRow courseGroupDataRow = new CourseGroupDataRow(); courseGroupDataRow.CourseGroupID = courseGroupID; courseGroupDataRow.CourseGroupCode = "78zcn25ynkaz50ef"; courseGroupDataRow.CourseScheduleID = secondCourseScheduleID; courseGroupDataRow.PlacesCount = 2; // Build the database connection. using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString)) { // Open the database connection. databaseConnection.Open().Wait(); // Update the CourseGroup data row. CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent(); courseGroupDataAccessComponent.Update(databaseConnection, courseGroupDataRow).Wait(); } // Validate the CourseGroup data row was updated in the database. CourseGroupTestTable.AssertPresence( courseGroupID, "78zcn25ynkaz50ef", secondCourseScheduleID, 2); }
/// <summary> /// Inserts a placeholder row. /// </summary> public static int InsertPlaceholder(string courseGroupCode = default(string), int courseScheduleID = default(int), int placesCount = default(int)) { // Provide a value for all the columns. if (courseGroupCode == default(string)) { courseGroupCode = Guid.NewGuid().ToString(); } if (courseScheduleID == default(int)) { courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(); } if (placesCount == default(int)) { placesCount = 0; } // Insert the row. int courseGroupID = InsertWithValues(courseGroupCode, courseScheduleID, placesCount); // Return the generated ID. return(courseGroupID); }