示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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));
                }
            }
        }
示例#5
0
        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);
        }