public async Task WhenIEnrollNonExistingUserToACourse_ThenIGetAProperErrorMessage()
        {
            var nonExistingUserId = 100000;
            var newCourse         = new Course {
                Name = "Course 1"
            };
            int newId = await CoursesRequests.AddCourse(newCourse);

            var enrollmentResponse = await CoursesRequests.EnrollUserToACourse(nonExistingUserId, newId);

            Assert.False(enrollmentResponse.Item1);
            Assert.Equal($"User with Id: {nonExistingUserId} does not exist!", enrollmentResponse.Item2);
        }
        public async Task WhenIEnrollAUserToACourseThatDoesntExist_ThenIGetAProperErrorMessage()
        {
            var nonExistingCourseId = 100000;
            var newUser1            = new User {
                Email = "*****@*****.**"
            };
            int newId1 = await UsersRequests.AddUser(newUser1);

            var enrollmentResponse = await CoursesRequests.EnrollUserToACourse(newId1, nonExistingCourseId);

            Assert.False(enrollmentResponse.Item1);
            Assert.Equal($"Course with Id: {nonExistingCourseId} does not exist!", enrollmentResponse.Item2);
        }
        public async Task WhenIEnrollUsersToCourses_ThenICanRetrieveTheListOfCoursesWithEnrollments()
        {
            var newUser1 = new User {
                Email = "*****@*****.**"
            };
            var newUser2 = new User {
                Email = "*****@*****.**"
            };
            var newUser3 = new User {
                Email = "*****@*****.**"
            };
            var course1 = new Course {
                Name = "Course 1"
            };
            var course2 = new Course {
                Name = "Course 2"
            };
            var course3 = new Course {
                Name = "Course 3"
            };

            int newId1 = await UsersRequests.AddUser(newUser1);

            int newId2 = await UsersRequests.AddUser(newUser2);

            int newId3 = await UsersRequests.AddUser(newUser3);

            int course1Id = await CoursesRequests.AddCourse(course1);

            int course2Id = await CoursesRequests.AddCourse(course2);

            int course3Id = await CoursesRequests.AddCourse(course3);

            Assert.True((await CoursesRequests.EnrollUserToACourse(newId1, course1Id)).Item1);
            Assert.True((await CoursesRequests.EnrollUserToACourse(newId1, course2Id)).Item1);
            Assert.True((await CoursesRequests.EnrollUserToACourse(newId2, course2Id)).Item1);
            Assert.True((await CoursesRequests.EnrollUserToACourse(newId2, course3Id)).Item1);
            Assert.True((await CoursesRequests.EnrollUserToACourse(newId3, course1Id)).Item1);
            Assert.True((await CoursesRequests.EnrollUserToACourse(newId3, course2Id)).Item1);

            var coursesWithEnrollments = await CoursesRequests.GetCoursesWithEnrollments();

            Assert.Equal(2, coursesWithEnrollments.Single(x => x.Id.Equals(course1Id)).NumberOfEnrollments);
            Assert.Equal(3, coursesWithEnrollments.Single(x => x.Id.Equals(course2Id)).NumberOfEnrollments);
            Assert.Equal(1, coursesWithEnrollments.Single(x => x.Id.Equals(course3Id)).NumberOfEnrollments);
        }
Exemple #4
0
        public async Task WhenIEnrollUserToThreeCourses_ThenICanRetrieveTheListOfThem()
        {
            var newUser = new User {
                Email = "*****@*****.**"
            };
            var course1 = new Course {
                Name = "Course 1"
            };
            var course2 = new Course {
                Name = "Course 2"
            };
            var course3 = new Course {
                Name = "Course 3"
            };

            int newId = await UsersRequests.AddUser(newUser);

            int course1Id = await CoursesRequests.AddCourse(course1);

            int course2Id = await CoursesRequests.AddCourse(course2);

            int course3Id = await CoursesRequests.AddCourse(course3);

            var enrollmentResult1 = await CoursesRequests.EnrollUserToACourse(newId, course1Id);

            var enrollmentResult2 = await CoursesRequests.EnrollUserToACourse(newId, course2Id);

            var enrollmentResult3 = await CoursesRequests.EnrollUserToACourse(newId, course3Id);

            Assert.True(enrollmentResult1.Item1);
            Assert.True(enrollmentResult2.Item1);
            Assert.True(enrollmentResult3.Item1);

            var coursesForUser = await UsersRequests.GetUserCourses(newId);

            Assert.Collection(coursesForUser,
                              item => Assert.Contains(course1.Name, item.Name),
                              item => Assert.Contains(course2.Name, item.Name),
                              item => Assert.Contains(course3.Name, item.Name));
        }
        public async Task WhenIEnrollAUserToACourseHeIsAlreadyEnrolledTo_ThenIGetAProperErrorMessage()
        {
            var newUser = new User {
                Email = "*****@*****.**"
            };
            var course1 = new Course {
                Name = "Course 1"
            };

            int user1Id = await UsersRequests.AddUser(newUser);

            int course1Id = await CoursesRequests.AddCourse(course1);

            var enrollmentResponse1 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id);

            Assert.True(enrollmentResponse1.Item1);
            Assert.Equal($"User: {user1Id} successfully enrolled to course: {course1Id}!", enrollmentResponse1.Item2);

            var enrollmentResponse2 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id);

            Assert.False(enrollmentResponse2.Item1);
            Assert.Equal("User already enrolled to that course!", enrollmentResponse2.Item2);
        }
        public async Task WhenIWithdrawAUserFromACourse_ThenIGetASuccessMessage()
        {
            var newUser = new User {
                Email = "*****@*****.**"
            };
            var course1 = new Course {
                Name = "Course 1"
            };

            int user1Id = await UsersRequests.AddUser(newUser);

            int course1Id = await CoursesRequests.AddCourse(course1);

            var enrollmentResponse1 = await CoursesRequests.EnrollUserToACourse(user1Id, course1Id);

            Assert.True(enrollmentResponse1.Item1);
            Assert.Equal($"User: {user1Id} successfully enrolled to course: {course1Id}!", enrollmentResponse1.Item2);

            var enrollmentResponse2 = await CoursesRequests.WithdrawUserFromACourse(user1Id, course1Id);

            Assert.True(enrollmentResponse2.Item1);
            Assert.Equal($"User: {user1Id} successfully withdrawed from course: {course1Id}!", enrollmentResponse2.Item2);
        }