public void Get_GetEnrollmentsByGroupId_ReturnsEnrollments_Positive()
        {
            int groupId  = 1;
            int userId   = 1;
            int courseId = 1;

            var initialEnrollments  = GetEnrollments(groupId);
            var initialGroup        = GetGroup(groupId, userId, courseId);
            var userProgressMapping = GetUserProgressMapping();
            var expected            = GetExpectedEnrollments(initialEnrollments, userProgressMapping);

            initialEnrollments.Reverse();

            _enrollmentService.Setup(x => x.GetByGroupId(groupId)).Returns(initialEnrollments);
            _enrollmentMapper.Setup(x => x.Map(initialEnrollments)).Returns(
                initialEnrollments.Select(e => new EnrollmentModel
            {
                Id      = e.Id,
                GroupId = e.GroupId,
                User    = new UserForListingModel {
                    Id = e.User.Id, Name = e.User.Name
                },
                Date = string.Format("{0:dd.MM.yyyy}", e.Date)
            }).ToList());
            _groupService.Setup(x => x.GetById(groupId, userId)).Returns(initialGroup);
            _courseService.Setup(x => x.GetProgress(courseId,
                                                    It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.User.Id == id) != null)))
            .Returns <int, int>((cId, uId) => userProgressMapping[uId]);

            var actual = _controller.GetByGroupId(groupId);

            Assert.That(actual, Is.EquivalentTo(expected).Using(new EnrollmentWithProgressModelComparer()));
        }
Esempio n. 2
0
        public void Get_GetEnrollmentsByGroupId_ReturnsEnrollments_Positive()
        {
            int groupId  = 1;
            int userId   = 1;
            int courseId = 1;

            var initialEnrollments = new List <Enrollment>
            {
                new Enrollment
                {
                    Id   = 1,
                    User = new User
                    {
                        Id   = 1,
                        Name = "Roman"
                    },
                    GroupId = groupId,
                    Date    = DateTime.Now
                },
                new Enrollment
                {
                    Id   = 2,
                    User = new User
                    {
                        Id   = 2,
                        Name = "Andriy"
                    },
                    GroupId = groupId,
                    Date    = DateTime.Now
                },
                new Enrollment
                {
                    Id   = 3,
                    User = new User
                    {
                        Id   = 3,
                        Name = "Nazar"
                    },
                    GroupId = groupId,
                    Date    = DateTime.Now
                }
            };

            var initialGroup = new Group
            {
                Id       = groupId,
                OwnerId  = userId,
                Name     = "Basic English",
                CourseId = courseId
            };

            var userProgressMapping = new Dictionary <int, double>();

            userProgressMapping.Add(1, 68.53);
            userProgressMapping.Add(2, 76.56);
            userProgressMapping.Add(3, 28.43);

            var expected = new List <EnrollmentWithProgressModel>();

            foreach (var enrollment in initialEnrollments)
            {
                expected.Add(new EnrollmentWithProgressModel()
                {
                    Enrollment = new EnrollmentModel
                    {
                        Id   = enrollment.Id,
                        User = new UserForListingModel
                        {
                            Id   = enrollment.User.Id,
                            Name = enrollment.User.Name
                        },
                        GroupId = enrollment.GroupId,
                        Date    = string.Format("{0:dd.MM.yyyy}", enrollment.Date)
                    },
                    Progress = userProgressMapping[enrollment.User.Id]
                });
            }
            initialEnrollments.Reverse();

            GenerateData("1", new[] { "NoRoles" });
            Mock <IEnrollmentMapper>     enrollmentMapper    = new Mock <IEnrollmentMapper>();
            Mock <ICourseService>        courseService       = new Mock <ICourseService>();
            Mock <IEnrollmentService>    enrollmentService   = new Mock <IEnrollmentService>();
            Mock <IWordSuiteService>     wordSuiteService    = new Mock <IWordSuiteService>();
            Mock <IWordProgressService>  wordProgressService = new Mock <IWordProgressService>();
            Mock <IGroupService>         groupService        = new Mock <IGroupService>();
            Mock <IUserForListingMapper> userMapper          = new Mock <IUserForListingMapper>();

            EnrollmentController controller = new EnrollmentController(enrollmentService.Object, enrollmentMapper.Object,
                                                                       wordSuiteService.Object, wordProgressService.Object, userMapper.Object, courseService.Object, groupService.Object);

            enrollmentService.Setup(x => x.GetByGroupId(groupId)).Returns(initialEnrollments);
            enrollmentMapper.Setup(x => x.MapToEnrollmentModelCollection(initialEnrollments)).Returns(
                initialEnrollments.Select(e => new EnrollmentModel
            {
                Id      = e.Id,
                GroupId = e.GroupId,
                User    = new UserForListingModel {
                    Id = e.User.Id, Name = e.User.Name
                },
                Date = string.Format("{0:dd.MM.yyyy}", e.Date)
            }).ToList());
            groupService.Setup(x => x.GetById(groupId, userId)).Returns(initialGroup);
            courseService.Setup(x => x.GetProgress(courseId,
                                                   It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.User.Id == id) != null)))
            .Returns <int, int>((cId, uId) => userProgressMapping[uId]);

            var actual = controller.GetByGroupId(groupId);

            Assert.That(actual, Is.EquivalentTo(expected).Using(new EnrollmentWithProgressModelComparer()));
        }