Ejemplo n.º 1
0
        public void ConcurrencyCheck()
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                db.Database.Delete();
                db.Database.CreateIfNotExists();

                db.Database.ExecuteSqlCommand(
                    @"DROP TABLE IF EXISTS `MovieReleases`");

                db.Database.ExecuteSqlCommand(
                    @"CREATE TABLE IF NOT EXISTS `MovieReleases` (
  `Id` int(11) NOT NULL,
  `Name` varbinary(45) NOT NULL,
  `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=binary");
                MySqlTrace.Listeners.Clear();
                MySqlTrace.Switch.Level = SourceLevels.All;
                GenericListener listener = new GenericListener();
                MySqlTrace.Listeners.Add(listener);
                try
                {
                    MovieRelease mr = db.MovieReleases.Create();
                    mr.Id   = 1;
                    mr.Name = "Commercial";
                    db.MovieReleases.Add(mr);
                    db.SaveChanges();
                    mr.Name = "Director's Cut";
                    db.SaveChanges();
                }
                finally
                {
                    db.Database.ExecuteSqlCommand(@"DROP TABLE IF EXISTS `MovieReleases`");
                }
                // Check sql
                Regex rx = new Regex(@"Query Opened: (?<item>UPDATE .*)", RegexOptions.Compiled | RegexOptions.Singleline);
                foreach (string s in listener.Strings)
                {
                    Match m = rx.Match(s);
                    if (m.Success)
                    {
                        st.CheckSql(m.Groups["item"].Value, SQLSyntax.UpdateWithSelect);
                        //Assert.Pass();
                    }
                }
                //Assert.Fail();
            }
        }
Ejemplo n.º 2
0
 public void BadOrderBy()
 {
     ReInitDb();
     using (MovieDBContext db = new MovieDBContext())
     {
         db.Database.Initialize(true);
         Movie m1 = new Movie()
         {
             Title = "Terminator 1", ReleaseDate = new DateTime(1984, 10, 26)
         };
         Movie m2 = new Movie()
         {
             Title = "The Matrix", ReleaseDate = new DateTime(1999, 3, 31)
         };
         Movie m3 = new Movie()
         {
             Title = "Predator", ReleaseDate = new DateTime(1987, 6, 12)
         };
         Movie m4 = new Movie()
         {
             Title = "Star Wars, The Sith Revenge", ReleaseDate = new DateTime(2005, 5, 19)
         };
         db.Movies.Add(m1);
         db.Movies.Add(m2);
         db.Movies.Add(m3);
         db.Movies.Add(m4);
         db.SaveChanges();
         DateTime filterDate = new DateTime(1986, 1, 1);
         var      q          = db.Movies.Where(p => p.ReleaseDate >= filterDate).
                               OrderByDescending(p => p.ReleaseDate).Take(2);
         string sql = q.ToString();
         st.CheckSql(SQLSyntax.NestedOrderBy, sql);
         // Data integrity testing
         Movie[] data = new Movie[] {
             new Movie()
             {
                 ID = 4, Title = "Star Wars, The Sith Revenge", ReleaseDate = new DateTime(2005, 5, 19)
             },
             new Movie()
             {
                 ID = 2, Title = "The Matrix", ReleaseDate = new DateTime(1999, 3, 31)
             }
         };
         int i = 0;
         foreach (Movie m in q)
         {
             Assert.Equal(data[i].ID, m.ID);
             Assert.Equal(data[i].Title, m.Title);
             Assert.Equal(data[i].ReleaseDate, m.ReleaseDate);
             i++;
         }
     }
 }
Ejemplo n.º 3
0
        public void AddingEmptyRow()
        {
            using (MovieDBContext ctx = new MovieDBContext())
            {
                ctx.Database.Initialize(true);
                ctx.EntitySingleColumns.Add(new EntitySingleColumn());
                ctx.SaveChanges();
            }

            using (MovieDBContext ctx2 = new MovieDBContext())
            {
                var q = from esc in ctx2.EntitySingleColumns where esc.Id == 1 select esc;
                Assert.AreEqual(1, q.Count());
            }
        }
Ejemplo n.º 4
0
        public void AlterTableTest()
        {
            ReInitDb();
            MovieDBContext db = new MovieDBContext();

            db.Database.Initialize(true);
            var l = db.MovieFormats.ToList();

            foreach (var i in l)
            {
            }
            MovieFormat m = new MovieFormat();

            m.Format = 8.0f;
            db.MovieFormats.Add(m);
            db.SaveChanges();
        }