public void TestExamCoreqFailed()
        {
            var course1 = new Course
            {
                Name = "C# 44",
                Description = "Programming in .NET Framework With C#",
                Credits = 8,
                Cost = 400,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100
            };

            var course2 = new Course
            {
                Name = "C# 18",
                Description = "Programming in .NET Framework With C#",
                Credits = 3,
                Cost = 50,
                Currency = "EUR",
                LowerBound = 10,
                UpperBound = 100
            };

            course1.CourseCoRequisites.Add(course2);

            var courseService = new CourseService();
            courseService.AddCourse(course1);
            courseService.AddCourse(course2);

            var student = new Student
            {
                FirstName = "name",
                LastName = "sdjjkghsjkghsk",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new[] { new Email("*****@*****.**"), }
            };

            var studentService = new StudentService();
            studentService.AddStudent(student);

            var exam = new Exam
            {
                Course = course1,
                Student = student,
                Grade = 6,
                ExaminationDate = DateTime.Now,
            };

            var exam1 = new Exam
            {
                Course = course2,
                Student = student,
                Grade = 6,
                ExaminationDate = DateTime.Now,
            };

            _examService.AddExam(exam1);
            //_examService.AddExam(exam);

            var res = Validation.Validate(exam);
            Assert.AreEqual(false, res.IsValid, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            //_examService.DeleteExam(exam2);
            //_examService.DeleteExam(exam);
        }
        public void TestGetAllEmails2()
        {
            //Arrange
            var student = new Student
            {
                FirstName = "firstname1",
                LastName = "lastname1",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new[] { new Email("*****@*****.**"), }
            };
            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12356",
                Street = "353",
                Student = student
            };

            student.Address = address;

            using (var st = new StudentService())
            {
                st.AddStudent(student);
            }

            var email = new Email("*****@*****.**") { Student = student };
            var res = Validation.Validate(email);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

            if (!res.IsValid)
            {
                var firstOrDefault = res.FirstOrDefault();
                if (firstOrDefault != null) Trace.WriteLine(firstOrDefault.Message);
            }

               // using (var es = new EmailService())
               // {
            //    var lastCount = es.GetAllEmails().Count;
            //    es.AddEmail(email);

                //Assert.AreEqual(lastCount + 1, es.GetAllEmails().Count);
              //  }
        }
        public void TestAddPhoneSuccess()
        {
            var student = new Student
            {
                FirstName = "firstname1",
                LastName = "lastname1",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new[] { new Email("*****@*****.**") }
            };

            var phone = new Phone()
            {
                PhoneNumber = "0123 123456",
                Student = student
            };

            using (var es = new PhoneService())
            using (var st = new StudentService())
            {
                es.AddPhone(phone);
                var res = Validation.Validate(phone);
                Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

                if (!res.IsValid)
                {
                    var firstOrDefault = res.FirstOrDefault();
                    if (firstOrDefault != null) Trace.WriteLine(firstOrDefault.Message);
                }

                var stud = st.GetStudentById(student.StudentId);
                Assert.AreEqual(stud.StudentId, student.StudentId);
                Assert.IsTrue(stud.Phones.Any(e => e.PhoneNumber == phone.PhoneNumber));
            }
        }
        public void TestInsertAddressWithStudent()
        {
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 123456") }
            };

            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12345",
                Street = "Brooklyn 33",
                Student = student
            };

            student.Address = address;

            var res = Validation.Validate(address);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            using (var addressService = new AddressService())
            using (var studentService = new StudentService())
            {
                studentService.AddStudent(student);

                var lastid = student.StudentId;
                Trace.WriteLine(lastid);
                var lastAddress = addressService.GetAddressById(lastid);
                Assert.IsNotNull(lastAddress);
                Assert.AreNotEqual(student, lastAddress);

                Assert.AreEqual(student.StudentId, lastAddress.Student.StudentId);
                Assert.AreEqual(student.FirstName, lastAddress.Student.FirstName);
                Assert.AreEqual(student.LastName, lastAddress.Student.LastName);
                Assert.AreEqual(student.CNP, lastAddress.Student.CNP);
                Assert.AreEqual(student.SID, lastAddress.Student.SID);

                Assert.IsNotNull(student.Address);
                Assert.IsNotNull(lastAddress);
                Assert.AreEqual(student.Address.City, lastAddress.City);
                Assert.AreEqual(student.Address.Country, lastAddress.Country);
                Assert.AreEqual(student.Address.PostalCode, lastAddress.PostalCode);
                Assert.AreEqual(student.Address.State, lastAddress.State);
                Assert.AreEqual(student.Address.Street, lastAddress.Street);
                Assert.AreEqual(student.Address.StudentId, lastAddress.StudentId);

                //studentService.DeleteStudent(student.StudentId);
            }
        }
        public void TestAddEmailToStudent()
        {
            var student = new Student
            {
                FirstName = "firstname1",
                LastName = "lastname1",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new[] { new Email("*****@*****.**") }
            };

            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12356",
                Street = "353",
                Student = student
            };

            student.Address = address;

            using (var es = new EmailService())
            using (var st = new StudentService())
            {
                st.AddStudent(student);
                var email = new Email("*****@*****.**") { StudentId = student.StudentId };
                es.AddEmail(email);
                var res = Validation.Validate(email);
                Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

                if (!res.IsValid)
                {
                    var firstOrDefault = res.FirstOrDefault();
                    if (firstOrDefault != null) Trace.WriteLine(firstOrDefault.Message);
                }

                var stud = st.GetStudentById(student.StudentId);
                Assert.AreEqual(stud.StudentId, student.StudentId);
                Assert.IsTrue(stud.Emails.Any(e => e.EmailAddress == email.EmailAddress));
            }
        }
        public void TestAddStudentWithoutPhoneAndWithEmail()
        {
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new [] { new Email("*****@*****.**") }
            };

            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12345",
                Street = "Brooklyn 33",
                Student = student
            };

            student.Address = address;

            var res = Validation.Validate(address);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            using (var studentService = new StudentService())
            {
                studentService.AddStudent(student);
            }
        }
        public void TestDeleteStudentWithStudentIdZero()
        {
            //create entity instance
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 123456"), }
            };

            //insert entity
            var res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true);
            new StudentService().AddStudent(student);

            //change entity properties;update entity
            int lastInsertedStudentId = student.StudentId;
            Student updatedStudent1 = new StudentService().UpdateStudent(0, "updateFname", "updateLname", "updatedescr", 122, DateTime.Now);
        }
 public void MyTestInitialize()
 {
     _studentService = new StudentService();
     _courseService = new CourseService();
 }
        public void TestUpdateStudentWithStudentNonExistent()
        {
            //create entity instance
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 123456"), }
            };

            var student2 = new Student
            {
                FirstName = "uxqwe",
                LastName = "uyrtret",
                CNP = "9234567891234",
                SID = 321,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 654321"), }
            };

            //insert entity
            var res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true);
            new StudentService().AddStudent(student);

            //change entity properties;update entity
            int lastInsertedStudentId = student.StudentId;
            Student updatedStudent1 = new StudentService().UpdateStudent(999999999, student2);

            //read updated entity
            Student updateStudent2 = new StudentService().GetStudentById(lastInsertedStudentId);
        }
        public void TestUpdateStudentWithStudent()
        {
            //create entity instance
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 123456"), }
            };

            var student2 = new Student
            {
                FirstName = "uxqwe",
                LastName = "uyrtret",
                CNP = "9234567891234",
                SID = 321,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 654321"), }
            };

            //insert entity
            var res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true);
            new StudentService().AddStudent(student);

            //change entity properties;update entity
            int lastInsertedStudentId = student.StudentId;
            Student updatedStudent1 = new StudentService().UpdateStudent(lastInsertedStudentId, student2);

            //read updated entity
            Student updateStudent2 = new StudentService().GetStudentById(lastInsertedStudentId);

            //compare changed entity and read entity
            Assert.AreEqual(updatedStudent1.FirstName, updateStudent2.FirstName);
            Assert.AreEqual(updatedStudent1.LastName, updateStudent2.LastName);
            Assert.AreEqual(updatedStudent1.CNP, updateStudent2.CNP);
            Assert.AreEqual(updatedStudent1.SID, updateStudent2.SID);
            Assert.AreEqual(updatedStudent1.EnrollmentDate.ToString("yyyy-MM-ddTHH:mm:ss"), updateStudent2.EnrollmentDate.ToString("yyyy-MM-ddTHH:mm:ss"));

            Assert.AreEqual(student2.FirstName, updateStudent2.FirstName);
            Assert.AreEqual(student2.LastName, updateStudent2.LastName);
            Assert.AreEqual(student2.CNP, updateStudent2.CNP);
            Assert.AreEqual(student2.SID, updateStudent2.SID);
            Assert.AreEqual(student2.EnrollmentDate.ToString("yyyy-MM-ddTHH:mm:ss"), updateStudent2.EnrollmentDate.ToString("yyyy-MM-ddTHH:mm:ss"));

            //delete entity
            new StudentService().DeleteStudent(lastInsertedStudentId);
        }
        public void TestInsertStudentWithAddress()
        {
            var student = new Student
            {
               FirstName = "firstname1",
               LastName = "lastname1",
               CNP = "1234567891234",
               SID = 123,
               EnrollmentDate = DateTime.Now,
               Emails = new[] { new Email("*****@*****.**") }
            };

            var address = new Address
            {
                City = "Brasov",
                Country = "Romania",
                State = "Brasov",
                PostalCode = "50520",
                Street = "Memorandului 31",
                Student = student
            };

            student.Address = address;

            var res = Validation.Validate(address);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) System.Diagnostics.Trace.WriteLine(singleOrDefault.Message);
            }

            res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) System.Diagnostics.Trace.WriteLine(singleOrDefault.Message);
            }

            new StudentService().AddStudent(student);

            var lastid = student.StudentId;
            var lastStudent = new StudentService().GetStudentById(lastid);
            Assert.IsNotNull(lastStudent);
            Assert.AreNotEqual(student, lastStudent);

            Assert.AreEqual(student.StudentId, lastStudent.StudentId);
            Assert.AreEqual(student.FirstName, lastStudent.FirstName);
            Assert.AreEqual(student.LastName, lastStudent.LastName);
            Assert.AreEqual(student.CNP, lastStudent.CNP);
            Assert.AreEqual(student.SID, lastStudent.SID);

            Assert.IsNotNull(student.Address);
            Assert.IsNotNull(lastStudent.Address);
            Assert.AreEqual(student.Address.City, lastStudent.Address.City);
            Assert.AreEqual(student.Address.Country, lastStudent.Address.Country);
            Assert.AreEqual(student.Address.PostalCode, lastStudent.Address.PostalCode);
            Assert.AreEqual(student.Address.State, lastStudent.Address.State);
            Assert.AreEqual(student.Address.Street, lastStudent.Address.Street);
            Assert.AreEqual(student.Address.StudentId, lastStudent.Address.StudentId);

            _studentService.DeleteStudent(lastid);
        }
        public void TestInsertStudentSuccess()
        {
            var student = new Student
            {
                FirstName = "reqwe",
                LastName = "gfsfgfdfds",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Emails = new[] { new Email("*****@*****.**"),  }
            };

            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12345",
                Street = "Brooklyn 33",
                Student = student
            };

            student.Address = address;

            var res = Validation.Validate(student);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            new StudentService().AddStudent(student);

            var lastid = student.StudentId;
            var lastStudent = new StudentService().GetStudentById(lastid);
            Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message);

            if (!res.IsValid)
            {
                var singleOrDefault = res.SingleOrDefault();
                if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message);
            }

            Assert.IsNotNull(lastStudent);
            Assert.AreNotEqual(student, lastStudent);

            Assert.AreEqual(student.StudentId, lastStudent.StudentId);
            Assert.AreEqual(student.FirstName, lastStudent.FirstName);
            Assert.AreEqual(student.LastName, lastStudent.LastName);
            Assert.AreEqual(student.CNP, lastStudent.CNP);
            Assert.AreEqual(student.SID, lastStudent.SID);
            Assert.IsNotNull(student.Address);
        }