Пример #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);
        }
Пример #3
0
        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);
        }
Пример #6
0
        private bool IsStudentAlreadyInCourse(Student newStudent)
        {
            foreach (Student student in this.Students)
            {
                if (newStudent.UniqueNumber == student.UniqueNumber)
                {
                    return true;
                }
            }

            return false;
        }
Пример #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);
        }
Пример #10
0
 public void SetWhitespaceFirstNameTest()
 {
     Student student = new Student("   ", "Petkov", 22112);
 }
Пример #11
0
 public void SetSmallerThanMinUniqueNumberTest()
 {
     Student student = new Student("Ivan", "Petrov", 9999);
 }
Пример #12
0
 public void SetShorterThanAllowedFirstNameTest()
 {
     Student student = new Student("A", "Petkov", 22112);
 }
Пример #13
0
 public void SetNullLastNameTest()
 {
     Student student = new Student("Petko", null, 22112);
 }
Пример #14
0
 public void SetLongerThanAllowedLastNameTest()
 {
     Student student = new Student("Niko", "Wolllfeschllegelsteinhaussennbergerdorffvoroffovich", 22112);
 }
Пример #15
0
 public void SetInvalidLastNameTest()
 {
     Student student = new Student("Special", "Some.one", 22112);
 }
Пример #16
0
 public void SetBiggerThanMaxUniqueNumberTest()
 {
     Student student = new Student("Ivan", "Petrov", 119999);
 }