Ejemplo n.º 1
0
        public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Ejemplo n.º 2
0
        public void MailTest()
        {
            MailerDbEntities _db = new MailerDbEntities();

            _db.Contacts.RemoveRange(_db.Contacts.Where(x => x.Email != null).AsEnumerable());
            var email1    = "*****@*****.**";
            var email2    = "*****@*****.**";
            var emailList = new List <string>
            {
                email1, email2
            };

            _db.Contacts.Add(new Contact()
            {
                Email = email1
            });
            _db.Contacts.Add(new Contact()
            {
                Email = email2
            });
            _db.SaveChanges();

            var homeController = new HomeController();

            homeController.SendAllEmail();
            Assert.AreEqual(2, _simpleSmtpServer.ReceivedEmailCount);
            Assert.IsTrue(emailList.Contains(_simpleSmtpServer.ReceivedEmail[0].ToAddresses[0].ToString()));
            Assert.IsTrue(emailList.Contains(_simpleSmtpServer.ReceivedEmail[1].ToAddresses[0].ToString()));
        }
Ejemplo n.º 3
0
 public void Init()
 {
     _controller = new ContactsController();
     _db = new MailerDbEntities();
     _db.Contacts.RemoveRange(_db.Contacts.Where(x => x.Email != null).AsEnumerable());
     _db.SaveChanges();
 }
Ejemplo n.º 4
0
        public void ContactDelete()
        {
            List <Contact> result;

            using (var db = new MailerDbEntities())
            {
                var ctObj = new Contact()
                {
                    ID    = 1,
                    Email = "*****@*****.**"
                };

                db.Entry(ctObj).State = EntityState.Added;
                db.SaveChanges();
                db.Entry(ctObj).State = EntityState.Deleted;
                db.SaveChanges();
                result = db.Contacts.Where(x => x.Email == "*****@*****.**").ToList();
            }
            Assert.IsTrue(result.Count == 0);
        }
Ejemplo n.º 5
0
        public void GivenUpcomingCourseNumberIs(int number)
        {
            List <Course> courses = new List <Course>();

            for (int i = 0; i < number; i++)
            {
                courses.Add(new Course
                {
                    CourseName = i.ToString(),
                    StartDate  = DateTime.Now,
                    EndDate    = DateTime.Now
                });
            }
            _db.Courses.AddRange(courses);
            _db.SaveChanges();
        }