public void MyTestInitialize()
 {
     _emailService = new EmailService();
 }
        public void TestGetAllEmails1()
        {
            var categoriesList = new EmailService().GetAllEmails();

            foreach (var email in categoriesList)
            {
                var emailId = email.EmailId;

                var email2 = new EmailService().GetEmailById(emailId);

                Assert.AreEqual(email.EmailAddress, email2.EmailAddress);
                Assert.AreEqual(email.StudentId, email2.StudentId);
            }
        }
        public void TestEmailStudentIsNull()
        {
            var student = new Student
            {
                FirstName = "firstname1",
                LastName = "lastname1",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
            };

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

                if (!res.IsValid)
                {
                    var firstOrDefault = res.FirstOrDefault();
                    if (firstOrDefault != null) Trace.WriteLine(firstOrDefault.Message);
                }
            }
        }
        public void TestEmailIsIsOfProperMaximumLength()
        {
            var student = new Student
            {
                FirstName = "firstname1",
                LastName = "lastname1",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
            };

            using (var es = new EmailService())
            {
                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);
                }
            }
        }
        public void TestAddEmailWithStudentId()
        {
            //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("*****@*****.**") { StudentId = student.StudentId };

            //Act
            using (var es = new EmailService())
            {
                es.AddEmail(email);
            }

            //Assert
            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);
            }

            Assert.AreEqual(student.StudentId, email.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));
            }
        }