public void created_course_is_assigned_to_correct_instructor()
        {
            //using (var Uow = new MOOCollab2UOW())
            using (var Uow = new TestDb())
            {
                //Arrange
                var courseRepo = new CourseRepository(Uow);
                var instructorRepo = new InstructorRepository(Uow);
                var testInstructor = instructorRepo.Find(1);

                courseRepo.Create(new Course
                {
                    OwnerId = 1,//course to instructor with Id of one
                    Title = "Test",
                    Resume = "Argh",//test text
                    Status = true
                });
                courseRepo.SaveChanges();
            }

            //using (var Uow = new MOOCollab2UOW())
            using (var Uow = new TestDb())
            {
                //Arrange
                var instructorRepo = new InstructorRepository(Uow);

                //Act
                var instructor = instructorRepo.FindAll()
                                .Include(i => i.Courses)
                                .FirstOrDefault(i => i.Id == 1);
                //assert  //Check if instructor has the new course
                Assert.IsNotNull(instructor.Courses.FirstOrDefault(c => c.Resume == "Argh"));
            }
        }
        public void GetStudentsForCourse_Returns_correctnumber()
        {
            //  Arrange
            //  -------
            TestDb testContext = new TestDb();

            //  instantiate the repository class
            UserRepository repository = new UserRepository(testContext);
            string username = "******";

            //  Action
            //  ------
            IQueryable<User> course1students = repository.GetUsersForCourse(1, username);
            var course2students = repository.GetUsersForCourse(2, username);
            var course3students = repository.GetUsersForCourse(3, username);
            var course4students = repository.GetUsersForCourse(4, username);
            var course5students = repository.GetUsersForCourse(5, username);

            //  Assert
            //  ------
            Assert.AreEqual(5 - 1, course1students.Count());  // 1 less as the method exclued the named user (logged on)
            Assert.AreEqual(5 - 1, course2students.Count());
            Assert.AreEqual(14 - 1, course3students.Count());
            Assert.AreEqual(8 - 1, course4students.Count());
            Assert.AreEqual(14 - 1, course5students.Count());
        }
        public void Course_And_Instructor_By_Id_data_verified()
        {
            Course testcourse;
            //using (var Uow = new MOOCollab2UOW())
            using (var Uow = new TestDb())
            {
                //Arrange
                var courseRepo = new CourseRepository(Uow);
                testcourse = courseRepo.CourseAndInstructorByCourseId(1);

            }
            Assert.IsNotNull(testcourse.OwnerId);
        }
        public void robert_stalks_narelle()
        {
            //have robert follow narelle
            using (var db = new TestDb())
            {
                var rob = db.Students.Include(s => s.Following).FirstOrDefault(s => s.UserName == "Robert");

                var narelle = db.Students.Include(s=>s.Following).FirstOrDefault(s => s.UserName == "Narelle");

                rob.Following.Add(narelle);

                db.SaveChanges();
            }

            //Get Narelle plus followers
               var narelle2 = _db.Students.Include(s=>s.Followers).FirstOrDefault(s => s.UserName == "Narelle");

               Assert.IsNotNull(narelle2.Followers.FirstOrDefault(f=>f.UserName=="Robert"));
        }
        public void GetStudentsForCourse1_Returns_Student_Names()
        {
            //  Arrange
            //  -------
            TestDb testContext = new TestDb();

            //  instantiate the repository class
            UserRepository repository = new UserRepository(testContext);
            string username = "******";

            //  Action
            //  ------
            List<User> course1students = repository.GetUsersForCourse(1, username).ToList<User>();

            //  Assert
            //  ------
            Assert.AreEqual("Robert", course1students[0].UserName);
            Assert.AreEqual("Andrew", course1students[1].UserName);
            Assert.AreEqual("Narelle", course1students[2].UserName);
            Assert.AreEqual("Bartoz", course1students[3].UserName);
            Assert.AreEqual(4, course1students.Count());    // Tim is not there, excluded from method as logged on user.
        }
        public void GetStudentsForGroups_Returns_CorrectNumber()
        {
            //  Arrange
            //  -------
            TestDb testContext = new TestDb();

            //  instantiate the repository class
            UserRepository repository = new UserRepository(testContext);
            string username = "******";

            //  Action
            //  ------
            List<User> group1students = repository.GetUsersForGroup(1, username).ToList<User>();
            List<User> group2students = repository.GetUsersForGroup(2, username).ToList<User>();
            List<User> group3students = repository.GetUsersForGroup(3, username).ToList<User>();
            List<User> group4students = repository.GetUsersForGroup(4, username).ToList<User>();
            List<User> group5students = repository.GetUsersForGroup(5, username).ToList<User>();
            List<User> group6students = repository.GetUsersForGroup(6, username).ToList<User>();
            List<User> group7students = repository.GetUsersForGroup(7, username).ToList<User>();
            List<User> group8students = repository.GetUsersForGroup(8, username).ToList<User>();
            List<User> group9students = repository.GetUsersForGroup(9, username).ToList<User>();
            List<User> group10students = repository.GetUsersForGroup(10, username).ToList<User>();
            List<User> group11students = repository.GetUsersForGroup(11, username).ToList<User>();

            //  Assert
            //  ------
            Assert.AreEqual(5 - 1, group1students.Count()); //  minus 1 as the method excludes Tim: the logged on user.
            Assert.AreEqual(8, group2students.Count());     //  Tim NOT member
            Assert.AreEqual(4, group3students.Count());     //  Tim NOT member
            Assert.AreEqual(9, group4students.Count());     //  Tim NOT member
            Assert.AreEqual(7, group5students.Count());     //  Tim NOT member
            Assert.AreEqual(5 - 1, group6students.Count()); //  Tim IS member
            Assert.AreEqual(3, group7students.Count());     //  Tim NOT member
            Assert.AreEqual(7, group8students.Count());     //  Tim NOT member
            Assert.AreEqual(6 - 1, group9students.Count()); //  Tim IS member
            Assert.AreEqual(4 - 1, group10students.Count());//  Tim IS member
            Assert.AreEqual(9 - 1, group11students.Count());//  Tim IS member
        }
        public void Student1_UnFollows_Student2()
        {
            //  Arrange
            //  -------
            TestDb testContext = new TestDb();

            //  instantiate the repository class
            UserRepository repository = new UserRepository(testContext);

            //  Bartosz is Student no 6, Andrew is Student no 4.  Is already followin Jim, Brian and Bartosz
            //  Get Andrew
            User Andrew = new User();
            Andrew = testContext.Users.FirstOrDefault(s => s.Id == 4) as User;
            User Bartosz = new User();
            Bartosz = testContext.Users.FirstOrDefault(s => s.Id == 6) as User;
            //int BartoszsId = 7;
            string BartoszsName = "Bartoz";

            List<User> BartoszFollowingBefore = Bartosz.Following.ToList<User>();
            List<User> AndrewFollowersBefore = Andrew.Followers.ToList<User>();

            //  Action
            //  ------
            //  Set Bartosz to Follow Andrew, only setting the one side
            repository.FollowUser(BartoszsName, Andrew);

            //  Retrieve who Bartosz is Following, and who is following Andrew
            //  Get Bartosz
            Bartosz = testContext.Users.FirstOrDefault(s => s.Id == 6);
            //  Refresh Andrew
            Andrew = testContext.Users.FirstOrDefault(s => s.Id == 4);

            List<User> BartoszFollowingAndrew = Bartosz.Following.ToList<User>();
            List<User> AndrewFollowedByBartosz = Andrew.Followers.ToList<User>();

            //  Set Bartosz to unfollow Andrew
            repository.UnFollowUser(BartoszsName, Andrew);

            Bartosz = testContext.Users.FirstOrDefault(s => s.Id == 6);
            Andrew = testContext.Users.FirstOrDefault(s => s.Id == 4);

            List<User> BartoszStoppedFollowingAndrew = Bartosz.Following.ToList<User>();
            List<User> AndrewNoLongerFollowedByBartosz = Andrew.Followers.ToList<User>();

            //  Assert: before
            //  ------
            // Bartosz follows Jim, Brian and Bartosz and now Andrew should be added
            Assert.AreEqual(2, BartoszFollowingBefore.Count());
            //  Andrew should be in Bartosz's collection of students he's following.
            Assert.IsFalse(BartoszFollowingBefore.Contains(Andrew));
            //  Only Bartosz should be following Andrew
            Assert.AreEqual(0, AndrewFollowersBefore.Count());
            //  Bartosz should be in Andrews collection of students following him.
            Assert.IsFalse(AndrewFollowersBefore.Contains(Bartosz));

            //  Assert: following
            //  -------
            // Bartosz follows Jim, Brian and Bartosz and now Andrew should be added
            Assert.AreEqual(3, BartoszFollowingAndrew.Count());
            //  Andrew should be in Bartosz's collection of students he's following.
            Assert.IsTrue(BartoszFollowingAndrew.Contains(Andrew));
            //  Only Bartosz should be following Andrew
            Assert.AreEqual(1, AndrewFollowedByBartosz.Count());
            //  Bartosz should be in Andrews collection of students following him.
            Assert.IsTrue(AndrewFollowedByBartosz.Contains(Bartosz));

            //  Assert: unfollowing
            //  ------
            // Bartosz follows Jim, Brian and Bartosz and now Andrew should be added
            Assert.AreEqual(2, BartoszStoppedFollowingAndrew.Count());
            //  Andrew should be in Bartosz's collection of students he's following.
            Assert.IsFalse(BartoszStoppedFollowingAndrew.Contains(Andrew));
            //  Only Bartosz should be following Andrew
            Assert.AreEqual(0, AndrewNoLongerFollowedByBartosz.Count());
            //  Bartosz should be in Andrews collection of students following him.
            Assert.IsFalse(AndrewNoLongerFollowedByBartosz.Contains(Bartosz));
        }
 public static void Setup(TestContext testContext)
 {
     _db = new TestDb();
 }
        public void Student1_Follows_Student_2_OK()
        {
            //  Arrange
            //  -------
            TestDb testContext = new TestDb();

            //  instantiate the repository class
            UserRepository repository = new UserRepository(testContext);

            //  Tim is Student no 7, Robert is Student no 3.  Is already followin Jim, Brian and Bartosz
            //  Get Robert
            User robert = testContext.Users.FirstOrDefault(s => s.Id == 3);
            int timsId = 7;

            //  Action
            //  ------
            //  Set Tim to Follow Robert, only setting the one side
            repository.FollowUser(timsId, robert);

            //  Retrieve who Tim is Following, and who is following Robert
            //  Get Tim
            User tim = testContext.Users.FirstOrDefault(s => s.Id == 7);
            //  Refresh Robert
            robert = testContext.Users.FirstOrDefault(s => s.Id == 3);

            //  Assert
            //  ------
            // Tim follows Jim, Brian and Bartosz and now Robert should be added
            Assert.AreEqual(4, tim.Following.Count());
            //  Robert should be in Tim's collection of students he's following.
            Assert.IsTrue(tim.Following.Contains(robert));
            //  Only Tim should be following Robert
            Assert.AreEqual(1, robert.Followers.Count());
            //  Tim should be in Roberts collection of students following him.
            Assert.IsTrue(robert.Followers.Contains(tim));
        }