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));
                }
            }
        }
        public void Update_ShouldThrowException_GivenInvalidCourseScheduleID()
        {
            // 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 = -1;
            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 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);
        }
        public void ReadByCourseScheduleID_ShouldReturnZeroDataRows()
        {
            // Insert the first master data rows in the database.
            int firstCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder();

            // Insert the first CourseGroup data row in the database.
            int firstCourseGroupID = CourseGroupTestTable.InsertWithValues(
                "5s1cgndj6e5x0uvz",
                firstCourseScheduleID,
                1);

            // Insert the second master data rows in the database.
            int secondCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder();

            // Insert the second CourseGroup data row in the database.
            int secondCourseGroupID = CourseGroupTestTable.InsertWithValues(
                "78zcn25ynkaz50ef",
                secondCourseScheduleID,
                2);

            // Insert the third master data rows in the database.
            int thirdCourseScheduleID = CourseScheduleTestTable.InsertPlaceholder();

            // Insert the third CourseGroup data row in the database.
            int thirdCourseGroupID = CourseGroupTestTable.InsertWithValues(
                "q5692qwy70qde9uv",
                thirdCourseScheduleID,
                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, -1).Result;
            }

            // Validate the CourseGroup data rows.
            Assert.IsNotNull(courseGroupDataRows);
            Assert.AreEqual(0, courseGroupDataRows.Length);
        }
        public void ReadByCourseGroupID_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.ReadByCourseGroupID(databaseConnection, -1).Result;
            }

            // Validate the CourseGroup data row.
            Assert.IsNull(courseGroupDataRow);
        }