5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Collections.Generic;
\r
31 using System.Linq.Expressions;
\r
33 using NUnit.Framework;
\r
35 using System.ComponentModel;
\r
36 using System.Data.Linq.Mapping;
\r
41 using System.Data.Linq;
\r
46 using DbLinq.Data.Linq;
\r
51 using Id = System.Decimal;
\r
53 using Id = System.Int32;
\r
58 namespace Test_NUnit_MySql
\r
60 namespace Test_NUnit_OracleODP
\r
62 namespace Test_NUnit_Oracle
\r
64 namespace Test_NUnit_PostgreSql
\r
66 namespace Test_NUnit_Sqlite
\r
68 namespace Test_NUnit_Ingres
\r
69 #elif MSSQL && L2SQL
\r
70 namespace Test_NUnit_MsSql_Strict
\r
72 namespace Test_NUnit_MsSql
\r
74 namespace Test_NUnit_Firebird
\r
78 public class WriteTest : TestBase
\r
81 public void TestSetup()
\r
85 Profiler.At("START: WriteTest.TestSetup()");
\r
87 Northwind db = CreateDB();
\r
88 // "[Products]" gets converted to "Products".
\r
89 //This is a DbLinq-defined escape sequence, by Pascal.
\r
90 //db.ExecuteCommand("DELETE FROM [Products] WHERE [ProductName] like 'temp%'");
\r
92 var deleteProducts = db.Products.Where(p => p.ProductName.StartsWith("temp")).ToList();
\r
93 db.Products.DeleteAllOnSubmit(deleteProducts);
\r
95 var deleteCategories = db.Categories.Where(c => c.CategoryName.StartsWith("temp")).ToList();
\r
96 db.Categories.DeleteAllOnSubmit(deleteCategories);
\r
100 Profiler.At("END: WriteTest.TestSetup()");
\r
103 #region Tests 'E' test live object cache
\r
105 public void E1_LiveObjectsAreUnique()
\r
107 //grab an object twice, make sure we get the same object each time
\r
108 Northwind db = CreateDB();
\r
109 var q = from p in db.Products select p;
\r
110 Product product1 = q.First();
\r
111 Product product2 = q.First();
\r
112 Assert.AreSame(product1, product2);
\r
114 string uniqueStr = "Unique" + Environment.TickCount;
\r
115 product1.QuantityPerUnit = uniqueStr;
\r
116 bool isSameObject1 = product2.QuantityPerUnit == uniqueStr;
\r
117 Assert.IsTrue(isSameObject1, "Expected product1 and product2 to be the same live object, but their fields are different");
\r
118 object oProduct1 = product1;
\r
119 object oProduct2 = product2;
\r
120 bool isSameObject2 = oProduct1 == oProduct2;
\r
121 Assert.IsTrue(isSameObject2, "Expected product1 and product2 to be the same live object, but their fields are different");
\r
125 public void E2_LiveObjectsAreUnique_Scalar()
\r
127 //grab an object twice, make sure we get the same object each time
\r
128 Northwind db = CreateDB();
\r
129 var q = from p in db.Products select p;
\r
130 Product product1 = q.First(p => p.ProductName == "Chai");
\r
131 Product product2 = q.Single(p => p.ProductName == "Chai");
\r
132 bool isSame = object.ReferenceEquals(product1, product2);
\r
133 Assert.IsTrue(isSame, "Expected product2 and product2 to be the same live object");
\r
136 #if MYSQL && USE_ALLTYPES
\r
138 public void E3_UpdateEnum()
\r
140 Northwind db = CreateDB();
\r
142 var q = from at in db.Alltypes where at.int_ == 1 select at;
\r
144 Alltype row = q.First();
\r
145 DbLinq_EnumTest newValue = row.DbLinq_EnumTest == DbLinq_EnumTest.BB
\r
146 ? DbLinq_EnumTest.CC
\r
147 : DbLinq_EnumTest.BB;
\r
149 row.DbLinq_EnumTest = newValue;
\r
151 db.SubmitChanges();
\r
157 #region Tests 'G' do insertion
\r
158 private int insertProduct_priv()
\r
160 Northwind db = CreateDB();
\r
162 Product newProd = new Product();
\r
163 newProd.CategoryID = db.Categories.First().CategoryID;
\r
164 newProd.ProductName = "Temp." + Environment.TickCount;
\r
165 newProd.QuantityPerUnit = "33 1/2";
\r
166 db.Products.InsertOnSubmit(newProd);
\r
167 db.SubmitChanges();
\r
168 AssertHelper.Greater(newProd.ProductID, 0, "After insertion, ProductID should be non-zero");
\r
169 //Assert.IsFalse(newProd.IsModified, "After insertion, Product.IsModified should be false");
\r
170 return (int)newProd.ProductID; //this test cab be used from delete tests
\r
174 public void G1_InsertProduct()
\r
176 insertProduct_priv();
\r
180 public void G2_DeleteTest()
\r
182 int insertedID = insertProduct_priv();
\r
183 AssertHelper.Greater(insertedID, 0, "DeleteTest cannot operate if row was not inserted");
\r
185 Northwind db = CreateDB();
\r
187 var q = from p in db.Products where p.ProductID == insertedID select p;
\r
188 List<Product> insertedProducts = q.ToList();
\r
189 foreach (Product insertedProd in insertedProducts)
\r
191 db.Products.DeleteOnSubmit(insertedProd);
\r
193 db.SubmitChanges();
\r
195 int numLeft = (from p in db.Products where p.ProductID == insertedID select p).Count();
\r
196 Assert.AreEqual(numLeft, 0, "After deletion, expected count of Products with ID=" + insertedID + " to be zero, instead got " + numLeft);
\r
200 public void G3_DeleteTest()
\r
202 int insertedID = insertProduct_priv();
\r
203 AssertHelper.Greater(insertedID, 0, "DeleteTest cannot operate if row was not inserted");
\r
205 Northwind db = CreateDB();
\r
207 var q = from p in db.Products where p.ProductID == insertedID select p;
\r
208 List<Product> insertedProducts = q.ToList();
\r
209 foreach (Product insertedProd in insertedProducts)
\r
211 db.Products.DeleteOnSubmit(insertedProd);
\r
213 db.SubmitChanges();
\r
215 int numLeft = (from p in db.Products where p.ProductID == insertedID select p).Count();
\r
216 Assert.AreEqual(numLeft, 0, "After deletion, expected count of Products with ID=" + insertedID + " to be zero, instead got " + numLeft);
\r
220 public void G4_DuplicateSubmitTest()
\r
222 Northwind db = CreateDB();
\r
223 int productCount1 = db.Products.Count();
\r
224 #if INGRES && !MONO_STRICT
\r
225 Product p_temp = new Product { ProductName = "temp_g4", Discontinued = "N" };
\r
227 Product p_temp = new Product { ProductName = "temp_g4", Discontinued = false };
\r
229 db.Products.InsertOnSubmit(p_temp);
\r
230 db.SubmitChanges();
\r
231 db.SubmitChanges();
\r
232 int productCount2 = db.Products.Count();
\r
233 Assert.IsTrue(productCount2 == productCount1 + 1, "Expected product count to grow by one");
\r
237 /// there is a bug in v0.14 where fields cannot be updated to be null.
\r
240 public void G5_SetFieldToNull()
\r
242 string productName = "temp_G5_" + Environment.TickCount;
\r
243 Northwind db = CreateDB();
\r
246 Product p1 = new Product { ProductName = productName, Discontinued = false, UnitPrice = 11 };
\r
247 #elif INGRES && !MONO_STRICT
\r
248 Product p1 = new Product { ProductName = productName, Discontinued = "N", UnitPrice = 11m };
\r
250 Product p1 = new Product { ProductName = productName, Discontinued = false, UnitPrice = 11m };
\r
252 db.Products.InsertOnSubmit(p1);
\r
253 db.SubmitChanges();
\r
255 p1.UnitPrice = null;
\r
256 db.SubmitChanges();
\r
258 Northwind db3 = CreateDB();
\r
259 Product p3 = db3.Products.Single(p => p.ProductName == productName);
\r
260 Assert.IsNull(p3.UnitPrice);
\r
264 /// there is a bug in v0.14 where table Customers cannot be updated,
\r
265 /// because quotes where missing around the primaryKey in the UPDATE statement.
\r
268 public void G6_UpdateTableWithStringPK()
\r
270 Northwind db = CreateDB();
\r
271 var customer = new Customer
\r
273 CompanyName = "Test Company",
\r
274 ContactName = "Test Customer",
\r
275 CustomerID = "BT___",
\r
277 db.Customers.InsertOnSubmit(customer);
\r
278 db.SubmitChanges();
\r
279 Customer BT = db.Customers.Single(c => c.CustomerID == "BT___");
\r
280 BT.Country = "U.K.";
\r
281 db.SubmitChanges();
\r
283 db.Customers.DeleteOnSubmit(customer);
\r
284 db.SubmitChanges();
\r
288 public void G7_InsertTableWithStringPK()
\r
290 Northwind db = CreateDB();
\r
291 db.ExecuteCommand("DELETE FROM [Customers] WHERE [CustomerID]='TEMP_'");
\r
293 Customer custTemp = new Customer
\r
295 CustomerID = "TEMP_",
\r
296 CompanyName = "Magellan",
\r
297 ContactName = "Antonio Pigafetta",
\r
300 db.Customers.InsertOnSubmit(custTemp);
\r
301 db.SubmitChanges();
\r
305 public void G8_DeleteTableWithStringPK()
\r
307 Northwind db = CreateDB();
\r
308 Customer cust = (from c in db.Customers
\r
309 where c.CustomerID == "TEMP_"
\r
310 select c).Single();
\r
311 db.Customers.DeleteOnSubmit(cust);
\r
312 db.SubmitChanges();
\r
316 public void G9_UpdateOnlyChangedProperty()
\r
318 Northwind db = CreateDB();
\r
319 var cust = (from c in db.Customers
\r
322 var old = cust.City;
\r
323 cust.City = "Tallinn";
\r
324 db.SubmitChanges();
\r
325 db.SubmitChanges(); // A second call does not update anything
\r
328 //Npgsql.NpgsqlException was unhandled
\r
329 //Message="ERROR: 23502: null value in column \"companyname\" violates not-null constraint"
\r
331 db.SubmitChanges();
\r
337 public class Northwind1 : Northwind
\r
339 public Northwind1(System.Data.IDbConnection connection)
\r
340 : base(connection) { }
\r
342 [System.Data.Linq.Mapping.Table(Name = "cust1")]
\r
346 string _customerid;
\r
348 [System.Data.Linq.Mapping.Column(Storage = "_customerid",
\r
349 Name = "customerid", IsPrimaryKey = true,
\r
350 DbType = "char(10)",
\r
351 IsDbGenerated = true,
\r
352 Expression = "nextval('seq8')")]
\r
353 public string CustomerId
\r
355 get { return _customerid; }
\r
356 set { _customerid = value; }
\r
359 // Dummy property is required only as workaround over empty insert list bug
\r
360 // If this bug is fixed this may be removed
\r
362 [System.Data.Linq.Mapping.Column(Storage = "_dummy",
\r
363 DbType = "text", Name = "dummy")]
\r
364 public string Dummy
\r
372 public Table<Cust1> Cust1s
\r
377 return base.GetTable<Cust1>();
\r
383 public void G10_InsertCharSerialPrimaryKey()
\r
385 Northwind dbo = CreateDB();
\r
386 Northwind1 db = new Northwind1(dbo.Connection);
\r
390 @"create sequence seq8;
\r
391 create temp table cust1 ( CustomerID char(10) DEFAULT nextval('seq8'),
\r
396 Table<Northwind1.Cust1> cust1s =
\r
397 db.GetTable<Northwind1.Cust1>();
\r
399 var cust1 = new Northwind1.Cust1();
\r
401 db.Cust1s.InsertOnSubmit(cust1);
\r
402 db.SubmitChanges();
\r
403 Assert.IsNotNull(cust1.CustomerId);
\r
407 try { db.ExecuteCommand("drop table cust1;"); }
\r
409 try { db.ExecuteCommand("drop sequence seq8;"); }
\r
415 public class NorthwindG11 : Northwind
\r
417 public NorthwindG11(System.Data.IDbConnection connection)
\r
418 : base(connection) { }
\r
420 [Table(Name = "rid")]
\r
421 public class Rid : INotifyPropertyChanged
\r
426 protected int _reanr;
\r
430 [System.Data.Linq.Mapping.Column(Storage = "_id", Name = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, Expression = "next value for rid_id1_seq")]
\r
432 [System.Data.Linq.Mapping.Column(Storage = "_id", Name = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, Expression = "nextval('rid_id1_seq')")]
\r
436 get { return _id; }
\r
440 OnPropertyChanged("Id");
\r
445 [System.Data.Linq.Mapping.Column(Storage = "_reanr", Name = "reanr", DbType = "integer", IsDbGenerated = true, CanBeNull = false, Expression = "next value for rid_reanr_seq")]
\r
447 [System.Data.Linq.Mapping.Column(Storage = "_reanr", Name = "reanr", DbType = "integer", IsDbGenerated = true, CanBeNull = false, Expression = "nextval('rid_reanr_seq')")]
\r
451 get { return _reanr; }
\r
455 OnPropertyChanged("Reanr");
\r
460 #region INotifyPropertyChanged handling
\r
461 public event PropertyChangedEventHandler PropertyChanged;
\r
462 protected virtual void OnPropertyChanged(string propertyName)
\r
464 if (PropertyChanged != null)
\r
466 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
\r
474 public Table<Rid> Rids
\r
478 return base.GetTable<Rid>();
\r
483 #if (POSTGRES || INGRES) && !MONO_STRICT
\r
484 #if !DEBUG && POSTGRES
\r
488 public void G11_TwoSequencesInTable()
\r
490 Northwind dbo = CreateDB();
\r
491 NorthwindG11 db = new NorthwindG11(dbo.Connection);
\r
493 db.ExecuteCommand(@"create sequence rid_id1_seq");
\r
494 db.ExecuteCommand(@"create sequence rid_reanr_seq");
\r
496 db.ExecuteCommand(@"create table Rid ( id int primary key DEFAULT rid_id1_seq.nextval, reanr int DEFAULT rid_reanr_seq.nextval)");
\r
498 db.ExecuteCommand(@"create temp table Rid ( id int primary key DEFAULT nextval('rid_id1_seq'), reanr int DEFAULT nextval('rid_reanr_seq'))");
\r
500 DbLinq.Data.Linq.Table<NorthwindG11.Rid> Rids = db.GetTable<NorthwindG11.Rid>();
\r
502 var Rid = new NorthwindG11.Rid();
\r
504 Exception e = null;
\r
505 db.Rids.InsertOnSubmit(Rid);
\r
507 Rid = new NorthwindG11.Rid();
\r
509 db.Rids.InsertOnSubmit(Rid);
\r
512 db.SubmitChanges();
\r
514 catch (Exception ex)
\r
518 db.ExecuteCommand("drop table rid");
\r
519 db.ExecuteCommand("drop sequence rid_reanr_seq");
\r
520 db.ExecuteCommand("drop sequence rid_id1_seq");
\r
525 Assert.AreEqual(2, Rid.Id);
\r
526 Assert.AreEqual(23, Rid.Reanr);
\r
531 #if !DEBUG && (SQLITE || (MSSQL && !L2SQL))
\r
535 public void G12_EmptyInsertList()
\r
537 Northwind db = CreateDB();
\r
538 Region newRegion = new Region() { RegionDescription = "" }; // RegionDescription must be non-null
\r
539 db.Regions.InsertOnSubmit(newRegion);
\r
540 db.SubmitChanges();
\r
541 Assert.IsNotNull(newRegion.RegionID);
\r
542 db.Regions.DeleteOnSubmit(newRegion);
\r
543 db.SubmitChanges();
\r
546 #if !DEBUG && (SQLITE || POSTGRES || (MSSQL && !L2SQL))
\r
550 public void G13_ProvidedAutoGeneratedColumn()
\r
552 Northwind db = CreateDB();
\r
553 Category newCat = new Category();
\r
554 newCat.CategoryID = 999;
\r
555 newCat.CategoryName = "test";
\r
556 db.Categories.InsertOnSubmit(newCat);
\r
557 db.SubmitChanges();
\r
558 // CategoryID is [Column(AutoSync=AutoSync.OnInsert)], so it's
\r
559 // value is ignored on insert and will be updated
\r
560 Assert.AreNotEqual(999, newCat.CategoryID);
\r
561 // then, load our object
\r
562 var checkCat = (from c in db.Categories where c.CategoryID == newCat.CategoryID select c).Single();
\r
563 Assert.AreEqual(newCat.CategoryID, checkCat.CategoryID);
\r
564 // remove the whole thing
\r
565 db.Categories.DeleteOnSubmit(newCat);
\r
566 db.SubmitChanges();
\r
571 public void G14_AutoGeneratedSupplierIdAndCompanyName()
\r
573 Northwind db = CreateDB();
\r
574 Supplier supplier = new Supplier()
\r
576 CompanyName = "Test Company",
\r
578 db.Suppliers.InsertOnSubmit(supplier);
\r
579 db.SubmitChanges();
\r
580 Assert.IsNotNull(supplier.SupplierID);
\r
581 Assert.AreEqual("Test Company", supplier.CompanyName);
\r
582 db.Suppliers.DeleteOnSubmit(supplier);
\r
583 db.SubmitChanges();
\r
588 [ExpectedException(typeof(InvalidOperationException))]
\r
589 public void G15_CustomerIdUpdate()
\r
591 //if you run this against Microsoft Linq-to-Sql, it throws an InvalidOperationEx:
\r
592 //{"Value of member 'CustomerID' of an object of type 'Customers' changed.
\r
593 //A member defining the identity of the object cannot be changed.
\r
594 //Consider adding a new object with new identity and deleting the existing one instead."}
\r
596 Northwind db = CreateDB();
\r
597 Customer c1 = (from c in db.Customers
\r
598 where c.CustomerID == "AIRBU"
\r
599 select c).Single();
\r
600 c1.CustomerID = "TEMP";
\r
601 db.SubmitChanges();
\r
602 Customer c2 = (from c in db.Customers
\r
603 where c.CustomerID == "TEMP"
\r
604 select c).Single();
\r
606 c2.CustomerID = "AIRBU";
\r
607 db.SubmitChanges();
\r
611 /// Quote from MSDN:
\r
612 /// If the object requested by the query is easily identifiable as one
\r
613 /// already retrieved, no query is executed. The identity table acts as a cache
\r
614 /// of all previously retrieved objects
\r
616 /// From Matt Warren: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=345635&SiteID=1
\r
617 /// The cache is checked when the query is a simple table.Where(pred) or table.First(pred) where the
\r
618 /// predicate refers only to the primary key. Otherwise the query is always sent and the cache only checked
\r
619 /// after the results are retrieved.
\r
620 /// The DLINQ cache is not distributed or shared, it is local and contained within the context. It is only a
\r
621 /// referential identity cache used to guarantee that two reads of the same entity return the same instance.
\r
622 /// You are not expected to hold the cache for an extended duration (except possibly for a client scenario),
\r
623 /// or share it across threads, processes, or machines in a cluster.
\r
625 #if !DEBUG && (SQLITE || POSTGRES || (MSSQL && !L2SQL))
\r
629 public void G16_CustomerCacheHit()
\r
631 Northwind db = CreateDB();
\r
632 Customer c1 = new Customer() { CustomerID = "temp", CompanyName = "Test", ContactName = "Test" };
\r
633 db.Customers.InsertOnSubmit(c1);
\r
634 db.SubmitChanges();
\r
635 db.ExecuteCommand("delete from \"Customers\" WHERE \"CustomerID\"='temp'");
\r
637 var res = db.Customers.First(c => c.CustomerID == "temp");
\r
638 Assert.IsNotNull(res);
\r
643 #if !DEBUG && (SQLITE || POSTGRES || MSSQL)
\r
644 // L2SQL: System.InvalidOperationException : The type 'Test_NUnit_MsSql_Strict.WriteTest+OrderDetailWithSum' is not mapped as a Table.
\r
648 public void G17_LocalPropertyUpdate()
\r
650 Northwind dbo = CreateDB();
\r
651 NorthwindLocalProperty db = new NorthwindLocalProperty(dbo.Connection);
\r
652 var det = db.OrderDetailWithSums.First();
\r
653 det.ChangeQuantity();
\r
654 Assert.AreEqual(0, db.GetChangeSet().Updates.Count);
\r
655 db.SubmitChanges();
\r
659 class NorthwindLocalProperty : Northwind
\r
661 internal NorthwindLocalProperty(System.Data.IDbConnection connection)
\r
662 : base(connection) { }
\r
664 internal Table<OrderDetailWithSum> OrderDetailWithSums
\r
668 return GetTable<OrderDetailWithSum>();
\r
674 class OrderDetailWithSum : OrderDetail, INotifyPropertyChanged
\r
676 public event PropertyChangedEventHandler PropertyChanged;
\r
677 protected virtual void OnPropertyChanged(string propertyName)
\r
679 if (PropertyChanged != null)
\r
681 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
\r
685 internal decimal? Sum
\r
689 return Quantity * UnitPrice;
\r
693 internal void ChangeQuantity()
\r
695 OnPropertyChanged("Sum");
\r
699 #if !DEBUG && (!(MSSQL && L2SQL))
\r
702 // L2SQL: System.NotSupportedException : An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.
\r
704 [ExpectedException(typeof(NotSupportedException))]
\r
705 public void G18_UpdateWithAttach()
\r
708 using (Northwind db = CreateDB())
\r
709 list = db.Orders.ToList();
\r
711 using (Northwind db = CreateDB())
\r
713 var tbl = db.GetTable<Order>();
\r
714 foreach (var order in list)
\r
716 if (order.Freight == null)
\r
720 db.SubmitChanges();
\r
725 #if !DEBUG && (SQLITE || POSTGRES || (MSSQL && !L2SQL))
\r
729 public void G19_ExistingCustomerCacheHit()
\r
731 Northwind db = CreateDB();
\r
732 string id = "ALFKI";
\r
733 Customer c1 = (from c in db.Customers
\r
734 where id == c.CustomerID
\r
735 select c).Single();
\r
737 db.Connection.ConnectionString = null;
\r
739 var x = db.Customers.First(c => id == c.CustomerID);
\r
744 public void G20_CustomerCacheHitComparingToLocalVariable()
\r
746 Northwind db = CreateDB();
\r
749 Customer c1 = new Customer() { CustomerID = "temp", CompanyName = "Test", ContactName = "Test" };
\r
750 db.Customers.InsertOnSubmit(c1);
\r
751 db.SubmitChanges();
\r
753 string id = "temp";
\r
754 var res = from c in db.Customers
\r
755 where c.CustomerID == id
\r
758 Assert.AreEqual(1, res.Count(), "#1");
\r
760 db.ExecuteCommand("DELETE FROM \"Customers\" WHERE \"CustomerID\"='temp'");
\r
762 res = from c in db.Customers
\r
763 where c.CustomerID == id
\r
765 Assert.AreEqual(0, res.Count(), "#2");
\r
769 db.ExecuteCommand("DELETE FROM \"Customers\" WHERE \"CustomerID\"='temp'");
\r
776 public void Update01()
\r
778 var db = CreateDB();
\r
779 Employee p = db.Employees.First(r => r.LastName == "Fuller");
\r
781 DateTime beforeDateTime = p.BirthDate.Value;
\r
782 DateTime now = beforeDateTime.AddMinutes(10);
\r
785 db.SubmitChanges();
\r
787 Employee p2 = db.Employees.First(r => r.LastName == "Fuller");
\r
788 Assert.AreEqual(p2.BirthDate, now);
\r
791 p.BirthDate = beforeDateTime;
\r
792 db.SubmitChanges();
\r
795 #if !DEBUG && SQLITE
\r
799 public void InsertAndDeleteWithDependencies()
\r
801 const string newCategoryName = "temp Category";
\r
802 const string newProduct1 = "temp First Test Product";
\r
803 const string newProduct2 = "temp Second Test Product";
\r
805 var db = CreateDB();
\r
807 var product = new Product
\r
810 Discontinued = "Y",
\r
812 Discontinued = true,
\r
814 ProductName = newProduct1,
\r
817 var category = new Category
\r
819 CategoryName = newCategoryName,
\r
820 Description = "Insert Description Here",
\r
822 category.Products.Add(product);
\r
824 Assert.AreEqual(0, category.CategoryID);
\r
825 Assert.AreEqual(0, product.CategoryID.Value);
\r
827 db.Categories.InsertOnSubmit(category);
\r
828 db.SubmitChanges();
\r
830 Assert.AreEqual(1, db.Categories.Where(c => c.CategoryName == newCategoryName).Count());
\r
831 Assert.AreNotEqual(0, category.CategoryID);
\r
832 Assert.AreEqual(1, db.Products.Where(p => p.ProductName == newProduct1).Count());
\r
833 Assert.AreEqual(category.CategoryID, product.CategoryID.Value);
\r
835 var p2 = new Product
\r
838 Discontinued = "Y",
\r
840 Discontinued = true,
\r
842 ProductName = newProduct2
\r
844 category.Products.Add(p2);
\r
845 db.SubmitChanges();
\r
847 Assert.AreEqual(1, db.Products.Where(p => p.ProductName == newProduct2).Count());
\r
849 db.Products.DeleteOnSubmit(product);
\r
850 db.Products.DeleteOnSubmit(p2);
\r
851 db.Categories.DeleteOnSubmit(category);
\r
852 db.SubmitChanges();
\r
854 Assert.AreEqual(0, db.Categories.Where(c => c.CategoryName == newCategoryName).Count());
\r
855 Assert.AreEqual(0, db.Products.Where(p => p.ProductName == newProduct1).Count());
\r
856 Assert.AreEqual(0, db.Products.Where(p => p.ProductName == newProduct2).Count());
\r