Пример #1
0
        public IHttpActionResult EnrollUsersToGroup(UsersForEnrollmentModel data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("Parameter could not be null", "data");
            }
            var users = _userMapper.Map(data.UserModels);

            _enrollmentService.EnrollUsersToGroup(users, data.GroupId);
            _wordSuiteService.CopyWordsuitesForUsersByGroup(users, data.GroupId);
            _wordProgressService.CopyProgressesForUsersInGroup(users, data.GroupId);
            return(Ok());
        }
Пример #2
0
        public IHttpActionResult EnrollUsersToGroup(UsersForEnrollmentModel data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("Parameter could not be null", "data");
            }
            var users = _userMapper.MapCollection(data.UserModels);

            if (_enrollmentService.EnrollUsersToGroup(users, data.GroupId) &&
                _wordSuiteService.CopyWordsuitesForUsersByGroup(users, data.GroupId) &&
                _wordProgressService.CopyProgressesForUsersInGroup(users, data.GroupId))
            {
                return(Ok());
            }
            return(BadRequest("Some problem occurred!"));
        }
        public void Post_EnrollUsersToGroup_ThrowsArgumentException_Negative()
        {
            var initialUsers = GetUserModels();
            var mappedUsers  = GetUsers();

            int groupId = 1;
            UsersForEnrollmentModel data = new UsersForEnrollmentModel
            {
                GroupId    = groupId,
                UserModels = initialUsers
            };

            _userMapper.Setup(x => x.Map(initialUsers)).Returns(mappedUsers);
            _enrollmentService.Setup(x => x.EnrollUsersToGroup(mappedUsers, groupId));
            _wordSuiteService.Setup(x => x.CopyWordsuitesForUsersByGroup(mappedUsers, groupId));
            _wordProgressService.Setup(x => x.CopyProgressesForUsersInGroup(mappedUsers, groupId)).Throws <ArgumentException>();

            Assert.Throws <ArgumentException>(() => _controller.EnrollUsersToGroup(data));
        }
        public void Post_EnrollUsersToGroup_ReturnsOkResult_Positive()
        {
            var initialUsers = GetUserModels();
            var mappedUsers  = GetUsers();

            int groupId = 1;
            UsersForEnrollmentModel data = new UsersForEnrollmentModel
            {
                GroupId    = groupId,
                UserModels = initialUsers
            };

            _userMapper.Setup(x => x.Map(initialUsers)).Returns(mappedUsers);
            _enrollmentService.Setup(x => x.EnrollUsersToGroup(mappedUsers, groupId));
            _wordSuiteService.Setup(x => x.CopyWordsuitesForUsersByGroup(mappedUsers, groupId));
            _wordProgressService.Setup(x => x.CopyProgressesForUsersInGroup(mappedUsers, groupId));

            var actual = _controller.EnrollUsersToGroup(data);

            Assert.IsInstanceOf(typeof(OkResult), actual);
        }
        public void Post_EnrollUsersToGroup_ThrowsArgumentNullException_Negative()
        {
            UsersForEnrollmentModel model = null;

            Assert.Throws <ArgumentNullException>(() => _controller.EnrollUsersToGroup(model));
        }
Пример #6
0
        public void Post_EnrollUsersToGroup_ReturnsBadRequestResult_Negative()
        {
            var initialUsers = new List <UserForListingModel>
            {
                new UserForListingModel
                {
                    Id   = 4,
                    Name = "Sasha"
                },
                new UserForListingModel
                {
                    Id   = 5,
                    Name = "Slava"
                },
                new UserForListingModel
                {
                    Id   = 6,
                    Name = "Yaryna"
                },
                new UserForListingModel
                {
                    Id   = 7,
                    Name = "Yura"
                }
            };

            var mappedUsers = new List <User>
            {
                new User
                {
                    Id   = 4,
                    Name = "Sasha"
                },
                new User
                {
                    Id   = 5,
                    Name = "Slava"
                },
                new User
                {
                    Id   = 6,
                    Name = "Yaryna"
                },
                new User
                {
                    Id   = 7,
                    Name = "Yura"
                }
            };

            int groupId = 1;
            UsersForEnrollmentModel data = new UsersForEnrollmentModel
            {
                GroupId    = groupId,
                UserModels = initialUsers
            };

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

            userMapper.Setup(x => x.MapCollection(initialUsers)).Returns(mappedUsers);
            enrollmentService.Setup(x => x.EnrollUsersToGroup(mappedUsers, groupId)).Returns(true);
            wordSuiteService.Setup(x => x.CopyWordsuitesForUsersByGroup(mappedUsers, groupId)).Returns(true);
            wordProgressService.Setup(x => x.CopyProgressesForUsersInGroup(mappedUsers, groupId)).Returns(false);

            var actual = controller.EnrollUsersToGroup(data);

            Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), actual);
        }
 public async void Post_EnrollUsersToGroup_ThrowsArgumentNullException_Negative()
 {
     UsersForEnrollmentModel model = null;
     await _controller.EnrollUsersToGroup(model);
 }