Пример #1
0
        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);
        }