Example #1
0
        public void AddStudent(Student newStudent)
        {
            if (newStudent == null)
            {
                throw new ArgumentNullException("newStudent", "Cannot add null value to the list of students of a course!");
            }

            if (!this.IsStudentAlreadyInCourse(newStudent))
            {
                if (this.Students.Count + 1 <= MaxStudents)
                {
                    this.Students.Add(newStudent);
                }
                else
                {
                    throw new InvalidOperationException(
                        string.Format(
                        "Cannot add student because the limit of {0} students for the course is reached!", MaxStudents));
                }
            }
            else
            {
                throw new InvalidOperationException(
                    string.Format("Student with unique number {0} is already in the course!", newStudent.UniqueNumber));
            }
        }
        public static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Presenting the functionality of the school system***");
            Console.Write(decorationLine);

            Student[] students = new Student[]
            {
                new Student("Ivan", "Ivanov", 12551),
                new Student("Peter", "Petrov", 51512),
                new Student("Georgi", "Georgiev", 51211),
                new Student("Lili", "Konstantinova", 91251),
                new Student("Qvor", "Marinov", 21512),
                new Student("Dimitar", "Dimitrov", 15122)
            };

            List<Course> courses = new List<Course>()
            {
                new Course("Informatics", new List<Student>() { students[0], students[2], students[4] }),
                new Course("Mathematics", new List<Student>() { students[1], students[3], students[5] }),
                new Course("History", new List<Student>() { students[1], students[2], students[4] })
            };

            School school = new School("SOU Vasil Levski", courses);

            PrintSchoolInformation(school);
        }
        public void StudentConstructorTest()
        {
            string firstName = "Ivaylo";
            string lastName = "Petkanov";
            int uniqueNumber = 12522;

            Student student = new Student(firstName, lastName, uniqueNumber);

            Assert.AreEqual(firstName, student.FirstName);
            Assert.AreEqual(lastName, student.LastName);
            Assert.AreEqual(uniqueNumber, student.UniqueNumber);
        }
        public void SetWhitespaceNameTest()
        {
            Student[] students = new Student[]
            {
                new Student("Ivan", "Ivanov", 12551),
                new Student("Peter", "Petrov", 51512),
                new Student("Georgi", "Georgiev", 51211),
                new Student("Lili", "Konstantinova", 91251),
                new Student("Qvor", "Marinov", 21512),
                new Student("Dimitar", "Dimitrov", 15122)
            };
            List<Course> courses = new List<Course>()
            {
                new Course("Informatics", new List<Student>() { students[0], students[2], students[4] }),
                new Course("Mathematics", new List<Student>() { students[1], students[3], students[5] }),
                new Course("History", new List<Student>() { students[1], students[2], students[4] })
            };

            School school = new School("   ", courses);
        }
        public void SchoolConstructorTest()
        {
            Student[] students = new Student[]
            {
                new Student("Ivan", "Ivanov", 12551),
                new Student("Peter", "Petrov", 51512),
                new Student("Georgi", "Georgiev", 51211),
                new Student("Lili", "Konstantinova", 91251),
                new Student("Qvor", "Marinov", 21512),
                new Student("Dimitar", "Dimitrov", 15122)
            };
            List<Course> courses = new List<Course>()
            {
                new Course("Informatics", new List<Student>() { students[0], students[2], students[4] }),
                new Course("Mathematics", new List<Student>() { students[1], students[3], students[5] }),
                new Course("History", new List<Student>() { students[1], students[2], students[4] })
            };
            string schoolName = "SOU Vasil Levski";

            School school = new School(schoolName, courses);

            Assert.AreEqual(schoolName, school.Name);
            Assert.AreSame(courses, school.Courses);
        }
Example #6
0
        private bool IsStudentAlreadyInCourse(Student newStudent)
        {
            foreach (Student student in this.Students)
            {
                if (newStudent.UniqueNumber == student.UniqueNumber)
                {
                    return true;
                }
            }

            return false;
        }
Example #7
0
 public bool RemoveStudent(Student student)
 {
     return this.Students.Remove(student);
 }
 public void SetNullNameTest()
 {
     Student student = new Student("Ivan", "Ivanov", 12414);
     Course course = new Course(null, new List<Student>() { student });
 }
        public void RemoveNonExistingStudentFromCourseTest()
        {
            Student peshoStudent = new Student("Pesho", "Peshov", 15122);
            IList<Student> students = new List<Student>()
            {
                new Student("Ivan", "Ivanov", 12512),
                new Student("Milena", "Georgieva", 61222)
            };
            string courseName = "Unit testing course";

            Course course = new Course(courseName, students);
            bool removed = course.RemoveStudent(peshoStudent);

            Assert.IsFalse(removed);
        }
 public void SetWhitespaceFirstNameTest()
 {
     Student student = new Student("   ", "Petkov", 22112);
 }
 public void SetSmallerThanMinUniqueNumberTest()
 {
     Student student = new Student("Ivan", "Petrov", 9999);
 }
 public void SetShorterThanAllowedFirstNameTest()
 {
     Student student = new Student("A", "Petkov", 22112);
 }
 public void SetNullLastNameTest()
 {
     Student student = new Student("Petko", null, 22112);
 }
 public void SetLongerThanAllowedLastNameTest()
 {
     Student student = new Student("Niko", "Wolllfeschllegelsteinhaussennbergerdorffvoroffovich", 22112);
 }
 public void SetInvalidLastNameTest()
 {
     Student student = new Student("Special", "Some.one", 22112);
 }
 public void SetBiggerThanMaxUniqueNumberTest()
 {
     Student student = new Student("Ivan", "Petrov", 119999);
 }