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