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 (testEntities context = new testEntities()) { Child c = new Child(); c.Id = 20; c.EmployeeID = 1; c.FirstName = "Bam bam"; c.LastName = "Rubble"; c.BirthWeight = 8.65; c.Modified = DateTime.Now; context.AddToChildren(c); context.SaveChanges(); } } finally { Thread.CurrentThread.CurrentCulture = curCulture; Thread.CurrentThread.CurrentUICulture = curUICulture; } }
public void CanInsertRowWithDefaultTimeStamp() { using (testEntities context = new testEntities()) { // The default timestamp is in the CreatedDate column. Product product = new Product(); product.Name = "Coca Cola"; context.AddToProducts(product); context.SaveChanges(); Assert.AreEqual(DateTime.Today.Day, product.CreatedDate.Day); } }
public void Delete() { using (testEntities context = new testEntities()) { foreach (Book b in context.Books) context.DeleteObject(b); context.SaveChanges(); } MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Books", conn); DataTable dt = new DataTable(); da.Fill(dt); Assert.AreEqual(0, dt.Rows.Count); }
public void UpdateAllRows() { MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM toys", conn); object count = cmd.ExecuteScalar(); using (testEntities context = new testEntities()) { foreach (Toy t in context.Toys) t.Name = "Top"; context.SaveChanges(); } cmd.CommandText = "SELECT COUNT(*) FROM Toys WHERE name='Top'"; object newCount = cmd.ExecuteScalar(); Assert.AreEqual(count, newCount); }
public void SimpleDeleteAllRows() { using (testEntities context = new testEntities()) { foreach (Toy t in context.Toys) context.DeleteObject(t); context.SaveChanges(); EntityConnection ec = context.Connection as EntityConnection; MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys", (MySqlConnection)ec.StoreConnection); DataTable dt = new DataTable(); da.Fill(dt); Assert.AreEqual(0, dt.Rows.Count); } }
public void SimpleDeleteRowByParameter() { using (testEntities context = new testEntities()) { MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys WHERE minage=3", conn); DataTable dt = new DataTable(); da.Fill(dt); Assert.IsTrue(dt.Rows.Count > 0); ObjectQuery<Toy> toys = context.Toys.Where("it.MinAge = @age", new ObjectParameter("age", 3)); foreach (Toy t in toys) context.DeleteObject(t); context.SaveChanges(); dt.Clear(); da.Fill(dt); Assert.AreEqual(0, dt.Rows.Count); } }
public void InsertSingleRow() { MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM companies", conn); DataTable dt = new DataTable(); da.Fill(dt); DataRow lastRow = dt.Rows[dt.Rows.Count - 1]; int lastId = (int)lastRow["id"]; DateTime dateBegan = DateTime.Now; using (testEntities context = new testEntities()) { Company c = new Company(); c.Id = 23; c.Name = "Yoyo"; c.NumEmployees = 486; c.DateBegan = dateBegan; c.Address.Address = "212 My Street."; c.Address.City = "Helena"; c.Address.State = "MT"; c.Address.ZipCode = "44558"; context.AddToCompanies(c); int result = context.SaveChanges(); DataTable afterInsert = new DataTable(); da.Fill(afterInsert); lastRow = afterInsert.Rows[afterInsert.Rows.Count - 1]; Assert.AreEqual(dt.Rows.Count + 1, afterInsert.Rows.Count); Assert.AreEqual(lastId+1, lastRow["id"]); Assert.AreEqual("Yoyo", lastRow["name"]); Assert.AreEqual(486, lastRow["numemployees"]); DateTime insertedDT = (DateTime)lastRow["dateBegan"]; Assert.AreEqual(dateBegan.Date, insertedDT.Date); Assert.AreEqual("212 My Street.", lastRow["address"]); Assert.AreEqual("Helena", lastRow["city"]); Assert.AreEqual("MT", lastRow["state"]); Assert.AreEqual("44558", lastRow["zipcode"]); } }
public void CommandTimeout() { string connectionString = String.Format( "metadata=res://*/TestModel.csdl|res://*/TestModel.ssdl|res://*/TestModel.msl;provider=MariaDB.Data.MySqlClient; provider connection string=\"{0};default command timeout=5\"", GetConnectionString(true)); EntityConnection connection = new EntityConnection(connectionString); using (testEntities context = new testEntities(connection)) { Author a = new Author(); a.Id = 66; // special value to indicate the routine should take 30 seconds a.Name = "Test name"; a.Age = 44; context.AddToAuthors(a); try { context.SaveChanges(); Assert.Fail("This should have timed out"); } catch (Exception ex) { string s = ex.Message; } } }
public void TimestampColumn() { DateTime now = DateTime.Now; using (testEntities context = new testEntities()) { Child c = context.Children.First(); DateTime dt = c.Modified; c.Modified = now; context.SaveChanges(); c = context.Children.First(); dt = c.Modified; Assert.AreEqual(now, dt); } }
public void TimeType() { using (testEntities context = new testEntities()) { TimeSpan birth = new TimeSpan(11,3,2); Child c = new Child(); c.Id = 20; c.EmployeeID = 1; c.FirstName = "first"; c.LastName = "last"; c.BirthTime = birth; c.Modified = DateTime.Now; context.AddToChildren(c); context.SaveChanges(); MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM EmployeeChildren WHERE id=20", conn); DataTable dt = new DataTable(); da.Fill(dt); Assert.AreEqual(birth, dt.Rows[0]["birthtime"]); } }
public void Insert() { MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Authors", conn); DataTable dt = new DataTable(); da.Fill(dt); int count = dt.Rows.Count; using (testEntities context = new testEntities()) { Author a = new Author(); a.Id = 23; a.Name = "Test name"; a.Age = 44; context.AddToAuthors(a); context.SaveChanges(); } dt.Clear(); da.Fill(dt); Assert.AreEqual(count + 1, dt.Rows.Count); Assert.AreEqual(23, dt.Rows[count]["id"]); }
public void Update() { MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Authors", conn); DataTable dt = new DataTable(); da.Fill(dt); int count = dt.Rows.Count; using (testEntities context = new testEntities()) { var q = from a in context.Authors where a.Name == "Don Box" select a; foreach (Author a in q) a.Name = "Dummy"; context.SaveChanges(); } da.SelectCommand.CommandText = "SELECT * FROM Authors WHERE name='Dummy'"; dt.Clear(); da.Fill(dt); Assert.AreEqual(1, dt.Rows.Count); }