Beispiel #1
0
        public void UpdateSimple()
        {
            var sb = new MySqlConnectionStringBuilder(st.ConnectionString);

            sb.Logging = true;
            using (DefaultContext ctx = new DefaultContext(sb.ToString()))
            {
                MySqlTrace.Listeners.Clear();
                MySqlTrace.Switch.Level = SourceLevels.All;
                GenericListener listener = new GenericListener();
                MySqlTrace.Listeners.Add(listener);

                Product p = new Product()
                {
                    Name = "Acme"
                };
                ctx.Products.Add(p);
                ctx.SaveChanges();

                p.Name = "Acme 2";
                ctx.SaveChanges();

                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.CheckSqlContains(m.Groups["item"].Value,
                                            @"UPDATE `Products` SET `Name`='Acme 2' WHERE `Id` = 1;
                SELECT `CreatedDate` FROM `Products` WHERE  row_count() > 0 and `Id` = 1");
                    }
                }
            }
        }
Beispiel #2
0
        public void DoubleValuesNonEnglish()
        {
            CultureInfo curCulture   = Thread.CurrentThread.CurrentCulture;
            CultureInfo curUICulture = Thread.CurrentThread.CurrentUICulture;
            CultureInfo newCulture   = new CultureInfo("da-DK");

            Thread.CurrentThread.CurrentCulture   = newCulture;
            Thread.CurrentThread.CurrentUICulture = newCulture;

            try
            {
                using (DefaultContext ctx = st.GetDefaultContext())
                {
                    Product p = new Product();
                    p.Name        = "New Product";
                    p.Weight      = 8.65f;
                    p.CreatedDate = DateTime.Now;
                    ctx.Products.Add(p);
                    ctx.SaveChanges();
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture   = curCulture;
                Thread.CurrentThread.CurrentUICulture = curUICulture;
            }
        }
        public void InsertSingleRow()
        {
            using (DefaultContext ctx = new DefaultContext(st.ConnectionString))
            {
                int beforeCnt = ctx.Companies.Count();

                Company c = new Company();
                c.Name            = "Yoyo";
                c.NumEmployees    = 486;
                c.DateBegan       = DateTime.Now;
                c.Address         = new Address();
                c.Address.Street  = "212 My Street.";
                c.Address.City    = "Helena";
                c.Address.State   = "MT";
                c.Address.ZipCode = "44558";

                ctx.Companies.Add(c);
                int result = ctx.SaveChanges();

                Assert.Equal(beforeCnt + 1, ctx.Companies.Count());

                Company d = ctx.Companies.Find(c.Id);
                d.Id = c.Id;
                Assert.Equal(c, d);
            }
        }
Beispiel #4
0
        public void TimestampColumn()
        {
            DateTime now = DateTime.Now;

            using (DefaultContext ctx = st.GetDefaultContext())
            {
                Product p = new Product()
                {
                    Name = "My Product", MinAge = 7, Weight = 8.0f
                };
                ctx.Products.Add(p);
                ctx.SaveChanges();

                p             = ctx.Products.First();
                p.CreatedDate = now;
                ctx.SaveChanges();

                p = ctx.Products.First();
                Assert.Equal(now, p.CreatedDate);
            }
        }
Beispiel #5
0
        public void SimpleDeleteRowByParameter()
        {
            using (DefaultContext ctx = new DefaultContext(st.ConnectionString))
            {
                int total   = ctx.Products.Count();
                int cntLeft = ctx.Products.Where(b => b.MinAge >= 18).Count();
                // make sure the test is valid
                Assert.True(total > cntLeft);

                foreach (Product p in ctx.Products.Where(b => b.MinAge < 18).ToList())
                {
                    ctx.Products.Remove(p);
                }
                ctx.SaveChanges();
                Assert.Equal(cntLeft, ctx.Products.Count());
                st.NeedSetup = true;
            }
        }
Beispiel #6
0
        public void SimpleDeleteAllRows()
        {
            using (DefaultContext ctx = new DefaultContext(st.ConnectionString))
            {
                Assert.True(ctx.Products.Count() > 0);

                foreach (Product p in ctx.Products)
                {
                    ctx.Products.Remove(p);
                }
                ctx.SaveChanges();

                Assert.Equal(0, ctx.Products.Count());
            }
            // set the flag that will cause the setup to happen again
            // since we just blew away a table
            st.NeedSetup = true;
        }
Beispiel #7
0
        public void TimeType()
        {
            using (DefaultContext ctx = st.GetDefaultContext())
            {
                TimeSpan birth = new TimeSpan(11, 3, 2);

                Child c = new Child();
                c.ChildId   = "ABC";
                c.Name      = "first";
                c.BirthTime = birth;
                c.Label     = Guid.NewGuid();
                ctx.Children.Add(c);
                ctx.SaveChanges();

                Child d = ctx.Children.Where(x => x.ChildId == "ABC").Single();
                Assert.Equal(birth, d.BirthTime);
            }
        }
 void LoadData()
 {
     using (DefaultContext ctx = new DefaultContext(st.ConnectionString))
     {
         ctx.Products.Add(new Product()
         {
             Name = "Garbage Truck", MinAge = 8
         });
         ctx.Products.Add(new Product()
         {
             Name = "Fire Truck", MinAge = 12
         });
         ctx.Products.Add(new Product()
         {
             Name = "Hula Hoop", MinAge = 18
         });
         ctx.SaveChanges();
     }
 }
Beispiel #9
0
 void LoadData()
 {
     using (DefaultContext ctx = new DefaultContext(st.ConnectionString))
     {
         ctx.Products.Add(new Product()
         {
             Id = 1, Name = "Garbage Truck", Weight = 8.865f
         });
         ctx.Products.Add(new Product()
         {
             Id = 2, Name = "Fire Truck", Weight = 12.623f
         });
         ctx.Products.Add(new Product()
         {
             Id = 3, Name = "Hula Hoop", Weight = 2.687f
         });
         ctx.SaveChanges();
     }
 }