public void Create_ShouldSucceed()
        {
            // 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 = 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();

                // Create the CourseSchedule data row.
                CourseScheduleDataAccessComponent courseScheduleDataAccessComponent = new CourseScheduleDataAccessComponent();
                courseScheduleDataAccessComponent.Create(databaseConnection, courseScheduleDataRow).Wait();
            }

            // Validate the CourseScheduleID was generated.
            Assert.AreNotEqual(0, courseScheduleDataRow.CourseScheduleID);

            // Validate the CourseSchedule data row was inserted in the database.
            CourseScheduleTestTable.AssertPresence(
                courseScheduleDataRow.CourseScheduleID,
                "zzcj32kpd6huzp1n",
                sessionID,
                1,
                new TimeSpan(9, 15, 0));
        }
        public void Create_ShouldThrowException_GivenDuplicateCourseScheduleCode()
        {
            // Insert the master data rows in the database.
            int sessionID = SessionTestTable.InsertPlaceholder();

            // Insert the duplicate CourseSchedule data row in the database.
            int courseScheduleID = CourseScheduleTestTable.InsertPlaceholder(courseScheduleCode: "zzcj32kpd6huzp1n");

            // Build the CourseSchedule data row.
            CourseScheduleDataRow courseScheduleDataRow = new CourseScheduleDataRow();
            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();

                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 Update_ShouldThrowException_GivenInvalidSessionID()
        {
            // 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 = -1;
            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));
        }
        public void ReadByCourseScheduleID_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.ReadByCourseScheduleID(databaseConnection, -1).Result;
            }

            // Validate the CourseSchedule data row.
            Assert.IsNull(courseScheduleDataRow);
        }