public void Initialize()
        {
            stService = new StudentTrackerService.StudentTrackerService();
            peter = new Student { FirstName = "PeterTest", LastName = "SimonsTest", Sex = Sex.Male, Age = 25 };
            sarah = new Student { FirstName = "SarahTest", LastName = "ClarksTest", Sex = Sex.Female, Age = 20 };
            jessy = new Student { FirstName = "JessyTest", LastName = "AlgienTest", Sex = Sex.Female, Age = 22 };

            math = new Course { CourseName = "MathematicsTest", MaxNumberOfStudents = 15 };
            calculus = new Course { CourseName = "CalculusTest", MaxNumberOfStudents = 10 };
            discrete = new Course { CourseName = "DiscreteTest", MaxNumberOfStudents = 2 };

            using (var ctx = new StudentTrackerDbContext())
            {
                ctx.Students.Add(peter);
                ctx.Students.Add(sarah);
                ctx.Students.Add(jessy);
                ctx.SaveChanges();

                math.Students.Add(peter);
                math.Students.Add(jessy);

                ctx.Courses.Add(math);
                ctx.Courses.Add(calculus);
                ctx.Courses.Add(discrete);

                ctx.SaveChanges();
            }
        }
        public void Initialize()
        {
            stService = new StudentTrackerService.StudentTrackerService();
            peter = new Student { FirstName = "PeterTest", LastName = "SimonsTest", Sex = Sex.Male, Age = 25 };
            sarah = new Student { FirstName = "SarahTest", LastName = "ClarksTest", Sex = Sex.Female, Age = 20 };
            jessy = new Student { FirstName = "JessyTest", LastName = "AlgienTest", Sex = Sex.Female, Age = 22 };

            math = new Course { CourseName = "MathematicsTest", MaxNumberOfStudents = 15 };
            calculus = new Course { CourseName = "CalculusTest", MaxNumberOfStudents = 10 };
            discrete = new Course { CourseName = "DiscreteTest", MaxNumberOfStudents = 2 };

            using (var ctx = new StudentTrackerDbContext())
            {
                ctx.Students.Add(peter);
                ctx.Students.Add(sarah);
                ctx.Students.Add(jessy);
                ctx.SaveChanges();

                discrete.Students.Add(sarah);
                calculus.Students.Add(sarah);

                ctx.Courses.Add(math);
                ctx.Courses.Add(calculus);
                ctx.Courses.Add(discrete);

                ctx.SaveChanges();

                expectedCourses = new List<StudentCourse>();
                foreach (var course in ctx.Courses)
                {
                    expectedCourses.Add(new StudentCourse { CourseName = course.CourseName, AssignedStudents = course.Students.Count, Id = course.Id, IsActive = course.Students.Count < course.MaxNumberOfStudents, MaxStudents = course.MaxNumberOfStudents, IsAppliedFor = course.Students.Any(x => x.Id == sarah.Id) });
                }
            }
        }
 public void Initialize()
 {
     stService = new StudentTrackerService.StudentTrackerService();
     colours = new UiColour { BackgroundColour = "#123321", HeaderColour = "#abccba" };
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Users.Add(user5);
         ctx.Users.Add(user16);
         ctx.Users.Add(user22);
         ctx.SaveChanges();
         ctx.Users.Find(user5.Id).UiColour = colours;
         ctx.SaveChanges();
     }
 }
        public void Initialize()
        {
            stService = new StudentTrackerService.StudentTrackerService();

            using (var ctx = new StudentTrackerDbContext())
            {
                ctx.Students.Add(new Student { FirstName = "DoubleName", LastName = "DoubleName", Age = 20, Sex = Sex.Male });
                ctx.SaveChanges();
            }
        }
 public void CleanUp()
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         foreach (var user in ctx.Users.Where(x=>x.Id==user5.Id || x.Id==user16.Id || x.Id==user22.Id))
         {
             ctx.Users.Remove(user);
         }
         ctx.SaveChanges();
     }
 }
 public void Initialize()
 {
     this.stService = new StudentTrackerService.StudentTrackerService();
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Courses.Add(math);
         ctx.Courses.Add(calculus);
         ctx.Courses.Add(discrete);
         ctx.SaveChanges();
     }
 }
 public void CleanUp()
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         foreach (var cs in ctx.Courses.Where(x => x.CourseName == math.CourseName || x.CourseName == calculus.CourseName || x.CourseName == discrete.CourseName || x.CourseName == entry.CourseName))
         {
             ctx.Courses.Remove(cs);
         }
         ctx.SaveChanges();
     }
 }
 public void CleanUp()
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         foreach (var st in ctx.Students.Where(x => x.LastName == sarah.LastName || x.LastName == peter.LastName || x.LastName == jessy.LastName))
         {
             ctx.Students.Remove(st);
         }
         ctx.SaveChanges();
     }
 }
        public void Initialize()
        {
            stService = new StudentTrackerService.StudentTrackerService();
            using (var ctx = new StudentTrackerDbContext())
            {
                ctx.Students.Add(peter);
                ctx.SaveChanges();

                id = ctx.Students.Single(x => x.FirstName == peter.FirstName && x.LastName == peter.LastName && x.Age == peter.Age).Id;
            }
        }
 public void Initialize()
 {
     stService = new StudentTrackerService.StudentTrackerService();
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Students.Add(peter);
         ctx.Students.Add(sarah);
         ctx.Students.Add(jessy);
         ctx.SaveChanges();
         initCount = ctx.Students.Count();
     }
 }
 public void CleanUp()
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         var s = ctx.Students.Where(x => x.FirstName == "DoubleName" && x.LastName == "DoubleName").ToList();
         foreach (var st in ctx.Students.Where(x => x.FirstName == "DoubleName" && x.LastName == "DoubleName"))
         {
             ctx.Students.Remove(st);
         }
         ctx.SaveChanges();
     }
 }
 public void Initialize()
 {
     stService = new StudentTrackerService.StudentTrackerService();
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Students.Add(peter);
         ctx.Students.Add(sarah);
         ctx.Students.Add(jessy);
         ctx.SaveChanges();
     }
     expectedFullName = string.Format("{0} {1}", peter.FirstName, peter.LastName);
     expectedSex = sarah.Sex.ToString();
 }
 public bool AddStudent(Student entry)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         if (IsDublicateName(entry.FirstName, entry.LastName, ctx.Students))
         {
             return false;
         }
         ctx.Students.Add(entry);
         ctx.SaveChanges();
         var student = ctx.Students.OrderByDescending(x => x.Id).First();
         entry.Id = student != null ? student.Id : 0;
         return true;
     }
 }
 public bool AddCourse(Course entity)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         if (ctx.Courses.Any(x => x.CourseName.Equals(entity.CourseName, StringComparison.OrdinalIgnoreCase)))
         {
             return false;
         }
         ctx.Courses.Add(new Course { CourseName = entity.CourseName, MaxNumberOfStudents = entity.MaxNumberOfStudents });
         ctx.SaveChanges();
         var course = ctx.Courses.OrderByDescending(x => x.Id).First();
         entity.Id = course != null ? course.Id : 0;
         return true;
     }
 }
 public void Initialize()
 {
     stService = new StudentTrackerService.StudentTrackerService();
     expectedStudents = new List<StudentInfo>();
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Students.Add(peter);
         ctx.Students.Add(sarah);
         ctx.Students.Add(jessy);
         ctx.SaveChanges();
         foreach (var student in ctx.Students)
         {
             expectedStudents.Add(new StudentInfo { Id = student.Id, FirstName = student.FirstName, LastName = student.LastName, Age = student.Age, Sex = student.Sex.ToString()});
         }
     }
 }
 public void Initialize()
 {
     this.stService = new StudentTrackerService.StudentTrackerService();
     using (var ctx = new StudentTrackerDbContext())
     {
         ctx.Courses.Add(math);
         ctx.Courses.Add(calculus);
         ctx.Courses.Add(discrete);
         ctx.SaveChanges();
         expectedCourses = new List<CourseInfo>();
         foreach (var course in ctx.Courses)
         {
             expectedCourses.Add(new CourseInfo { CourseName = course.CourseName, Id = course.Id, CurrentlyAssigned = course.Students.Count(), MaxAssigned = course.MaxNumberOfStudents });
         }
     }
 }
        public void CleanUp()
        {
            using (var ctx = new StudentTrackerDbContext())
            {
                foreach(var st in ctx.Students.Where(x=>x.LastName==sarah.LastName || x.LastName==peter.LastName || x.LastName==jessy.LastName))
                {
                    ctx.Students.Remove(st);
                }

                foreach (var cs in ctx.Courses.Where(x => x.CourseName == math.CourseName || x.CourseName == discrete.CourseName || x.CourseName == calculus.CourseName))
                {
                    ctx.Courses.Remove(cs);
                }

                ctx.SaveChanges();
            }
        }
 public void ApplyForCourse(int studentId, int courseId)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         var student = ctx.Students.Find(studentId);
         var course = ctx.Courses.Find(courseId);
         if (student == null)
         {
             throw new InvalidOperationException("No student with specified id found.");
         }
         if (course == null)
         {
             throw new InvalidOperationException("No course with specified id found.");
         }
         if (course.Students.Count==course.MaxNumberOfStudents)
         {
             throw new InvalidOperationException("Course is full.");
         }
         course.Students.Add(student);
         ctx.SaveChanges();
     }
 }
 public bool UpdateCourse(string id, string name, string capacity)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         int courseId = int.Parse(id);
         if (ctx.Courses.Any(x => x.CourseName.Equals(name, StringComparison.OrdinalIgnoreCase) && x.Id != courseId))
         {
             return false;
         }
         else
         {
             var course = ctx.Courses.Find(courseId);
             if (course != null)
             {
                 course.CourseName = name;
                 course.MaxNumberOfStudents = int.Parse(capacity);
                 ctx.SaveChanges();
                 return true;
             }
             return false;
         }
     }
 }
 public void UpdateStudent(int id, string firstName, string lastName, string age, string sex)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         var student = ctx.Students.Find(id);
         if (student == null)
         {
             return;
         }
         student.FirstName = firstName;
         student.LastName = lastName;
         student.Age = int.Parse(age);
         student.Sex = sex.Equals("Female") ? Sex.Female : Sex.Male;
         ctx.SaveChanges();
     }
 }
 public void DeleteCourse(string courseId)
 {
     int id;
     if (int.TryParse(courseId, out id))
     {
         using (var ctx = new StudentTrackerDbContext())
         {
             var course = ctx.Courses.Find(id);
             if (course != null)
             {
                 ctx.Courses.Remove(course);
                 ctx.SaveChanges();
             }
         }
     }
 }
 public void LeaveCourse(int studentId, int courseId)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         Student student = ctx.Students.Find(studentId);
         Course course = ctx.Courses.Find(courseId);
         if (student == null)
         {
             throw new InvalidOperationException("Student with specified id does not exist.");
         }
         if (course == null)
         {
             throw new InvalidOperationException("Course with specified id does not exist.");
         }
         course.Students.Remove(student);
         ctx.SaveChanges();
     }
 }
 public void DeleteStudent(int id)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         var st = ctx.Students.Find(id);
         if (st != null)
         {
             ctx.Students.Remove(st);
             ctx.SaveChanges();
         }
     }
 }
 public void SetUiColours(string id, string backgroundColour, string headerColour)
 {
     using (var ctx = new StudentTrackerDbContext())
     {
         var user = ctx.Users.Find(id);
         if (user == null)
         {
             throw new InvalidOperationException("No user with specified name found.");
         }
         if (ctx.Users.Single(x => x.Id == id).UiColour == null)
         {
             ctx.Users.Single(x => x.Id == id).UiColour = new UiColour { HeaderColour = headerColour, BackgroundColour = backgroundColour };
         }
         else
         {
             ctx.Users.Single(x => x.Id == id).UiColour.BackgroundColour = backgroundColour;
             ctx.Users.Single(x => x.Id == id).UiColour.HeaderColour = headerColour;
         }
         ctx.SaveChanges();
     }
 }