public void Create_ShouldSucceed()
        {
            // 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 = courseScheduleID;
            courseGroupDataRow.PlacesCount = 1;

            // Build the database connection.
            using (DatabaseConnection databaseConnection = new DatabaseConnection(TestDatabase.ConnectionString))
            {
                // Open the database connection.
                databaseConnection.Open().Wait();

                // Create the CourseGroup data row.
                CourseGroupDataAccessComponent courseGroupDataAccessComponent = new CourseGroupDataAccessComponent();
                courseGroupDataAccessComponent.Create(databaseConnection, courseGroupDataRow).Wait();
            }

            // Validate the CourseGroupID was generated.
            Assert.AreNotEqual(0, courseGroupDataRow.CourseGroupID);

            // Validate the CourseGroup data row was inserted in the database.
            CourseGroupTestTable.AssertPresence(
                courseGroupDataRow.CourseGroupID,
                "5s1cgndj6e5x0uvz",
                courseScheduleID,
                1);
        }
        public void Create_ShouldThrowException_GivenDuplicateCourseGroupCode()
        {
            // Insert the master data rows in the database.
            int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder();

            // Insert the duplicate CourseGroup data row in the database.
            int courseGroupID = CourseGroupTestTable.InsertPlaceholder(courseGroupCode: "5s1cgndj6e5x0uvz");

            // Build the CourseGroup data row.
            CourseGroupDataRow courseGroupDataRow = new CourseGroupDataRow();
            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();

                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));
                }
            }
        }