[Test] //work +
        //старт інтервал має починатись з 0, як і елементи колекції
        public void GetUsersFromIntervalByRoleId_IsRoleZero_Test()
        {
            //Arrange
            Role admin = new Role();
            admin.Id = 0;

            IQueryable<Role> rol = new List<Role>()
            {
                admin
            }.AsQueryable<Role>();

            IQueryable<User> listOfUsers = new List<User>
                            {
                                new User{Id = 5, Name = "Andrew", Roles = new List<Role>(){admin}}, 
                                new User{Id = 3, Name = "Fred", Roles = new List<Role>(){admin}},
                                new User{Id = 1, Name = "Sasha", Roles = new List<Role>(){admin}}

                            }.AsQueryable<User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(listOfUsers);

            //Act
            var result = usServ.GetUsersFromIntervalByRoleId(0, 3);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Exactly(3));
            userReposit.Verify(t => t.GetAll(), Times.Exactly(3));
            Assert.AreEqual(result, listOfUsers.ToList<User>());

        }
        [Test] //+
        public void GetAmountOfUsersByRoleIdNotZero_Test()
        {
            //Arrange
            Role admin = new Role();
            admin.Id = 1;

            IQueryable<Role> rol = new List<Role>()
            {
                admin
            }.AsQueryable<Role>();

            User user = new User { Id = 5, Name = "Andrew" };
            var user_2 = new User();
            user_2.Id = 3;
            user.Roles = new List<Role>() { admin };
            user_2.Roles = new List<Role>() { admin };

            IQueryable<User> listOfUsers = new List<User>
           {
            user,
            user_2
           }.AsQueryable<User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(listOfUsers);

            //Act
            int result = usServ.GetAmountOfUsersByRoleId(1);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.AtLeastOnce());
            userReposit.Verify(t => t.GetAll(), Times.AtLeastOnce());

            Assert.IsTrue(result == 2);
        }
        [Test] //+
        public void SearchByNameAndRole_RoleIsZero_Test()
        {
            IRepository<WorldOfWords.Domain.Models.Role> RoleReposit = new Mock<IRepository<WorldOfWords.Domain.Models.Role>>().Object;

            #region user and role
            User user = new User();
            user.Name = "Andrew";
            user.Email = "*****@*****.**";
            user.Id = 2;

            Role admin = new Role();
            admin.Id = 0;

            user.Roles = new List<Role>() { admin };

            IQueryable<User> users = new List<User>()
            {
                user
            }.AsQueryable<User>();
            #endregion

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(users);

            //Act
            var userColl = usServ.SearchByNameAndRole("Andrew");

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Once);
            userReposit.Verify(t => t.GetAll(), Times.Once);
            Assert.IsNotNull(userColl);
        }
        [Test] //work - 100% +
        public void ChangeRolesOfUser_Test()
        {
            ///Arrange
            Mock<IRepository<WorldOfWords.Domain.Models.Role>> roleRepository = new Mock<IRepository<Role>>();

            Role admin = new Role();
            admin.Id = 1;

            IQueryable<Role> rol = new List<Role>()
            {
                admin
            }.AsQueryable<Role>();

            User user_2 = new User()
            {
                Email = "*****@*****.**",
                Id = 1,
                Roles = new List<Role> 
                { 
                    new Role
                    {
                        Id = 1
                    }
                }
            };

            IQueryable<User> users = new List<User>()
            {
                new User
                {
                Email = "*****@*****.**",
                Id = 1,
                Roles = new List<Role> 
                { 
                    new Role
                    {
                        Id = 1
                    }
                }}
            }.AsQueryable<User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(users);
            worldOfWordsUow.Setup(t => t.RoleRepository).Returns(roleRepository.Object);
            roleRepository.Setup(t => t.GetAll()).Returns(rol);

            worldOfWordsUow.Setup(t => t.Save()).Verifiable();

            //Act
            var actual = usServ.ChangeRolesOfUser(user_2);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Once);
            userReposit.Verify(t => t.GetAll(), Times.Once);
            worldOfWordsUow.Verify(t => t.RoleRepository, Times.Once);
            roleRepository.Verify(t => t.GetAll(), Times.Once);
            worldOfWordsUow.VerifyAll();
            Assert.IsTrue(actual);
        }
        [Test] //+
        public void GetUsersFromIntervalByRoleId_Exception_Test()
        {
            //Arrange
            Role admin = new Role();
            admin.Id = 0;

            IQueryable<Role> rol = new List<Role>()
            {
                admin
            }.AsQueryable<Role>();

            IQueryable<User> listOfUsers = new List<User>
                            {
                                new User{Id = 5, Name = "Andrew", Roles = new List<Role>(){admin}}, 
                                new User{Id = 3, Name = "Fred", Roles = new List<Role>(){admin}},
                                new User{Id = 1, Name = "Sasha", Roles = new List<Role>(){admin}}

                            }.AsQueryable<User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(listOfUsers);

            //Act
            Assert.Throws<ArgumentException>(() => usServ.GetUsersFromIntervalByRoleId(-5, 0), "Start of interval is bigger than end");
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Once);
            userReposit.Verify(t => t.GetAll(), Times.Once);
        }
        public void GetUsersNotBelongingToGroupTestPositive()
        {
            // Arrange

            // The group, not belonging to it users must be returned by test method
            var group = new Group
            {
                Id = 111,
                Course = new Course { Id = 222 },
                OwnerId = 333,
                CourseId = 222
            };

            var role1 = new Role { Name = "Student" };
            var role2 = new Role { Name = "AnotherRole" };

            // On the exit must be this user with this enrollment 

            // Enrollment to return
            var enrollment = new Enrollment
            {
                GroupId = 100,
                Group = new Group { Course = new Course { Id = 100 } }
            };

            // User to return
            var user = new User
            {
                Id = 100,
                Roles = new List<Role> { role1 },
                Enrollments = new List<Enrollment> { enrollment }
            };

            enrollment.User = user;

            // User to test "u.Id != group.OwnerId" condition in Service
            var user1 = new User
            {
                Id = 333,
                Roles = new List<Role> { role1 },
                Enrollments = new List<Enrollment> { enrollment }
            };

            // User to test "u.Enrollments.Select(e => e.Group.Course).FirstOrDefault(c => c.Id == course.Id) == null"
            // condition in Service
            var enrollment2 = new Enrollment
            {
                GroupId = 100,
                Group = new Group { Course = new Course { Id = 222 } }
            };
            var user2 = new User
            {
                Id = 333,
                Roles = new List<Role> { role1 },
                Enrollments = new List<Enrollment> { enrollment2 }
            };

            // User to test "!usersCurrentlyInGroup.Any(u2 => u2.Id == u.Id)" condition
            var user3 = new User
            {
                Id = 333,
                Roles = new List<Role> { role1 },
                Enrollments = new List<Enrollment> { enrollment2 }
            };

            // User to test "u.Roles.Select(r => r.Name).Contains("Student")" condition
            var user4 = new User
            {
                Id = 333,
                Roles = new List<Role> { role2 },
                Enrollments = new List<Enrollment> { enrollment2 }
            };

            // For enrollmentRepository to return
            var enrollments = new List<Enrollment>(new Enrollment[] {
                enrollment,
                new Enrollment { GroupId = 111, User = user1}
            }).AsQueryable();

            var users = (new List<User> { user, user1, user2, user3, user4 }).AsQueryable();

            var groupRepository = new Mock<IRepository<Group>>();
            unitOfWork.Setup(x => x.GroupRepository).Returns(groupRepository.Object);
            groupRepository.Setup(x => x.GetById(group.Id)).Returns(group);
            enrollmentRepository.Setup(x => x.GetAll()).Returns(enrollments);

            var userRepository = new Mock<IUserRepository>();
            unitOfWork.Setup(x => x.UserRepository).Returns(userRepository.Object);
            userRepository.Setup(x => x.GetAll()).Returns(users);

            // Act
            var result = enrollmentService.GetUsersNotBelongingToGroup(group.Id);

            // Assert
            Assert.IsTrue(result.TrueForAll(u => u.Roles.Select(r => r.Name).Contains("Student")),
                "User should have the Student role");
            Assert.IsTrue(result.TrueForAll(u => !u.Enrollments.Any( e => e.GroupId == group.Id)),
                "User shouldn't be in that group");
            Assert.IsTrue(result.TrueForAll(u => !u.Enrollments.Any(e => e.Group.CourseId == group.CourseId)),
                "User shouldn't be in the course that contains given group");
            Assert.IsTrue(result.TrueForAll(u => u.Id != group.OwnerId));
        }