Esempio n. 1
0
        public void ValidationFailed()
        {
            using (var db = new MyContext())
            {
                Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

                Article articleLengthTest = new Article
                {
                    Title = "My Title",
                    Description = "Short text"
                };

                db.Articles.Add(articleLengthTest);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void ValidationDisabled()
        {
            using (var db = new MyContext())
            {
                Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

                Article articleLengthTest = new Article
                {
                    Title = "My Title",
                    Description = "Short text"
                };

                db.Articles.Add(articleLengthTest);
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges(); // uložení projde, protože MinLength() není db constraint
            }
        }
Esempio n. 3
0
        public void EmailValidation()
        {
            using (var db = new MyContext())
            {
                Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

                Author author = new Author
                {
                    FirstName = "Miroslav",
                    LastName = "Holec",
                    Email = "*****@*****.**",
                    SecondEmail = "thisIsNotEmail"
                };

                db.Authors.Add(author);
                db.SaveChanges();
            }
        }