Ejemplo n.º 1
0
 public void StudentWithOutOfRangeId()
 {
     int id = 100000;
     string name = "Gosho Goshov";
     Student student = new Student(id, name);
     Assert.Fail();
 }
Ejemplo n.º 2
0
 public void StudentWithNoName()
 {
     int id = 10000;
     string name = string.Empty;
     Student student = new Student(id, name);
     Assert.Fail();
 }
Ejemplo n.º 3
0
 public void RemoveFromEmptyCourse()
 {
     Student ivan = new Student(10000, "Ivan Ivanov");
     Course emptyCourse = new Course("Empty course");
     emptyCourse.RemoveStudent(ivan);
     Assert.Fail();
 }
Ejemplo n.º 4
0
 public void CreateValidStudentTest()
 {
     Student student = new Student(10000, "Pesho Goshov");
     Assert.IsTrue(student.Id == 10000);
     Assert.IsTrue(student.Name == "Pesho Goshov");
     Assert.IsTrue(student.ToString() == "ID: 10000, Name: Pesho Goshov");
 }
        static void Main()
        {
            Student stOne = new Student("Ivan", "Stoqnov", "Georgiev", 133713371)
            {
                Phone = 887843423,
                Univerity = University.Sofiiski,
                Speciality = Speciality.Psihologiq,
                Faculty = Faculty.Filosofski,
                Course = "Filosofiq",
                Address = "Mladost 3",
                Email = "*****@*****.**",
            };
            Student stTwo = new Student("Ivan", "Petrov", "Georgiev", 420);
            Student stThree = new Student("Pesho", "Peshev", "Goshev", 30);
            Student stFour = (Student)stOne.Clone();

            stOne.Email = "*****@*****.**";

            Console.WriteLine("Student one equal to student two: {0}",stOne.Equals(stTwo));
            Console.WriteLine("Student one equal to student two: {0}", stOne == stTwo);
            Console.WriteLine("Student one not equal to student three: {0}", stOne != stThree);
            Console.WriteLine("Student one equal to student three: {0}", stOne.Equals(stThree));

            Console.WriteLine(Environment.NewLine + "GetHashCode:");
            Console.WriteLine(stOne.GetHashCode());
            Console.WriteLine(Environment.NewLine + "Student.ToString():" + Environment.NewLine);
            Console.WriteLine(stOne.ToString());
            Console.WriteLine(Environment.NewLine + "Cloned student:" + Environment.NewLine);
            Console.WriteLine(stFour);

            Console.Write(Environment.NewLine + "Student one compared to student two: ");
            Console.WriteLine(stOne.CompareTo(stTwo));
        }
Ejemplo n.º 6
0
 public void AddStudentToCourseTwiceTest()
 {
     Course sampleCourse = new Course("Javascript");
     Student ivan = new Student(10000, "Ivan Ivanov");
     sampleCourse.AddStudent(ivan);
     sampleCourse.AddStudent(ivan);
     Assert.Fail();
 }
Ejemplo n.º 7
0
 public void RemoveStudentThatIsNotEnrolledTest()
 {
     Student ivan = new Student(10000, "Ivan Ivanov");
     Student pesho = new Student(10001, "Pesho Peshov");
     Course sampleCourse = new Course("Javascript");
     sampleCourse.AddStudent(ivan);
     sampleCourse.RemoveStudent(pesho);
     Assert.Fail();
 }
Ejemplo n.º 8
0
 public void CourseWithOneStudentTest()
 {
     Student ivan = new Student(10000, "Ivan Ivanov");
     Course sampleCourse = new Course("Javascript");
     sampleCourse.AddStudent(ivan);
     Student[] enrolledStudents = sampleCourse.GetStudents();
     Assert.IsTrue(sampleCourse.CourseName == "Javascript");
     Assert.IsTrue(enrolledStudents.Length == 1);
     Assert.IsTrue(enrolledStudents[0] == ivan);
 }
Ejemplo n.º 9
0
 public void RemoveStudentFromCourseTest()
 {
     Student ivan = new Student(10000, "Ivan Ivanov");
     Course sampleCourse = new Course("Javascript");
     sampleCourse.AddStudent(ivan);
     Student[] enrolledStudents = sampleCourse.GetStudents();
     Assert.IsTrue(enrolledStudents.Length == 1);
     sampleCourse.RemoveStudent(ivan);
     Student[] enrolledStudentsWithoutStudent = sampleCourse.GetStudents();
     Assert.IsTrue(enrolledStudentsWithoutStudent.Length == 0);
 }
Ejemplo n.º 10
0
        private static void CreateNewStudent(StudentSystemContext db, string newStudentName, string newStudentNumber)
        {
            var newStudent = new Student()
            {
                Name = newStudentName,
                Number = newStudentNumber
            };

            db.Students.Add(newStudent);
            db.SaveChanges();
        }
Ejemplo n.º 11
0
        public void DisplayEnrolledStudents()
        {
            Student ivan = new Student(10000, "Ivan Ivanov");
            Course sampleCourse = new Course("Javascript");
            sampleCourse.AddStudent(ivan);
            string courseString = sampleCourse.ToString();
            
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Course name: Javascript");
            sb.AppendLine("ID: 10000, Name: Ivan Ivanov");
            string expectedString = sb.ToString();

            Assert.AreEqual(expectedString, courseString);
        }
 public static bool AddStudent(Student studentToAdd)
 {
     try
     {
         using (var writer = new StreamWriter(Opeations.FilePath, true))
         {
             writer.WriteLine(studentToAdd);
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }
Ejemplo n.º 13
0
        public void RemoveStudent(Student studentToRemove)
        {
            if (this.enrolledStudents.Count == 0)
            {
                throw new CourseException("Cannot remove student from the course, because the course is empty!");
            }

            bool studentIsRegisteredInCourse = this.IsStudentInCourse(studentToRemove);

            if (studentIsRegisteredInCourse == false)
            {
                throw new ArgumentException("The student is not registered for this course!");
            }

            this.enrolledStudents.Remove(studentToRemove);
        }
Ejemplo n.º 14
0
        public void AddStudent(Student newEnrolledStudent)
        {
            if (this.enrolledStudents.Count == MaxStudentsPerCourse)
            {
                throw new CourseException("The course cannot have more than " + MaxStudentsPerCourse + " students");
            }

            bool studentIsAlreadyRegistered = this.IsStudentInCourse(newEnrolledStudent);

            if (studentIsAlreadyRegistered)
            {
                throw new ArgumentException("This student is already registered for the course!");
            }

            this.enrolledStudents.Add(newEnrolledStudent);
        }
Ejemplo n.º 15
0
        static void Main()
        {
            var substr = Utils.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

            var subarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);
            Console.WriteLine(String.Join(" ", subarr));

            var allarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);
            Console.WriteLine(String.Join(" ", allarr));

            var emptyarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);
            Console.WriteLine(String.Join(" ", emptyarr));

            Console.WriteLine(Utils.ExtractEnding("I love C#", 2));
            Console.WriteLine(Utils.ExtractEnding("Nakov", 4));
            Console.WriteLine(Utils.ExtractEnding("beer", 4));
            Console.WriteLine(Utils.ExtractEnding("Hi", 100));

            var validPrime = 23;
            var isPrime = Utils.CheckPrime(validPrime);
            Console.WriteLine(validPrime + " is prime: " + isPrime);

            var invalidNumber = -23;
            try
            {
                Utils.CheckPrime(invalidNumber);
                Console.WriteLine(invalidNumber + " is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(invalidNumber + " is not prime. ");
            }

            var peterExams = new List<Exam>()
            {
                new SimpleMathExam(2),
                new CSharpExam(55),
                new CSharpExam(100),
                new SimpleMathExam(1),
                new CSharpExam(0),
            };
            Student peter = new Student("Peter", "Petrov", peterExams);
            var peterAverageResult = peter.CalcAverageExamResultInPercents();
            Console.WriteLine("Average results = {0:p0}", peterAverageResult);
        }
 public static List<Student> ReadFromDataBase()
 {
     var listOfStudents = new List<Student>();
     using (var reader = new StreamReader(Opeations.FilePath))
     {
         var line = reader.ReadLine();
         while (line != null)
         {
             var currentStudent = line.Split('|');
             var student = new Student(
                 currentStudent[0].Trim(),
                 currentStudent[1].Trim(),
                 int.Parse(currentStudent[2].Trim()),
                 double.Parse(currentStudent[3].Trim()));
             listOfStudents.Add(student);
             line = reader.ReadLine();
         }
     }
     return listOfStudents;
 }
        private static void CreateSampleData(StudentSystemContext db)
        {
            var student = new Student()
            {
                StudentId = 1,
                Name = "Georgi Ivanov",
                Number = 2000,
                DateOfBirth = new DateTime(1994, 01, 16)
            };

            var course = new Course()
            {
                Name = "HQC",
                Description = string.Empty,
                Materials = "SOLID, Design Patterns"
            };

            var homework = new Homework()
            {
                HomeworkId = 1,
                CourseId = "HQC",
                StudentId = 1,
                Course = course,
                Student = student,
                DateSent = new DateTime(2015, 10, 10)
            };

            student.Courses.Add(course);
            student.Homeworks.Add(homework);
            course.Students.Add(student);
            course.Homeworks.Add(homework);

            db.Courses.Add(course);
            db.Homeworks.Add(homework);
            db.Students.Add(student);
            db.SaveChanges();
        }
Ejemplo n.º 18
0
 private bool IsStudentInCourse(Student studentToFind)
 {
     Debug.Assert(studentToFind != null, "The student to find cannot be null!");
     return this.enrolledStudents.Contains(studentToFind);
 }