public void Test_CommitLinks_NonSavedEntity() { var left = new ExampleInvoice (); var right = new ExampleInvoiceItem (); right.Invoice = left; var data = GetDataManager (); // Try to save the "right" object without first saving the "left" object. It should throw an exception because it can't sync with // a non-existent entity data.Linker.CommitLinks(right); }
public static void Main(string[] args) { var dataManager = new DataManager(); for (int i = 0; i < 500; i++) { var item = new ExampleInvoiceItem (); var invoice = new ExampleInvoice (); invoice.Items = new ExampleInvoiceItem[]{ item }; dataManager.Save (invoice); dataManager.SaveLinkedEntities (invoice); } }
public void Test_TwoWayReference_Add() { var invoice = new ExampleInvoice (); var data = GetDataManager (); data.Save(invoice); var invoiceItem = new ExampleInvoiceItem (); invoiceItem.AddLink("Invoice", invoice); data.Save (invoiceItem); // The "left.Right" property should now contain a link to the "right" object Assert.IsNotNull (invoice.Items, "Linker failed to add the link to the other entity."); }
public void Test_SaveLinkedEntities() { Console.WriteLine (""); Console.WriteLine ("Preparing test"); Console.WriteLine (""); var data = GetDataManager (); var invoice = new ExampleInvoice (); var invoiceItem = new ExampleInvoiceItem (invoice); Console.WriteLine (""); Console.WriteLine ("Starting test"); Console.WriteLine (""); data.SaveLinkedEntities (invoice); var foundItem = data.Get<ExampleInvoiceItem> (invoiceItem.Id); Assert.IsNotNull (foundItem, "Linker failed to save the other entity."); }
// TODO: Remove or reimplement //[Test] public void Test_TwoWayReference_RemoveOnDelete() { Console.WriteLine (""); Console.WriteLine ("Preparing test..."); Console.WriteLine (""); var data = new DataManager(); data.Settings.IsVerbose = true; data.WriteSummary (); var invoiceItem = new ExampleInvoiceItem (); var invoice = new ExampleInvoice (invoiceItem); data.Save(invoice, true); data.WriteSummary (); Console.WriteLine (""); Console.WriteLine ("Executing test code..."); Console.WriteLine (""); data.Delete(invoice); data.WriteSummary (); var newInvoice = data.Get<ExampleInvoice> (invoice.Id); Assert.AreEqual(0, newInvoice.Items.Length, "Linker failed to remove the link."); }
public void Test_UpdateLinkedEntities() { Console.WriteLine (""); Console.WriteLine ("Preparing test"); Console.WriteLine (""); var data = GetDataManager (); var invoice = new ExampleInvoice (); var invoiceItem = new ExampleInvoiceItem (invoice); data.Save(invoice); data.Save (invoiceItem); invoiceItem.Amount = 2; Console.WriteLine (""); Console.WriteLine ("Starting test"); Console.WriteLine (""); data.UpdateLinkedEntities (invoice); var foundRight = data.Get<ExampleInvoiceItem> (invoiceItem.Id); // The "right" object should have been updated in the data store Assert.AreEqual(2, foundRight.Amount, "Linker failed to update the other entity."); }
public ExampleInvoiceItem(ExampleInvoice invoice) { Invoice = invoice; invoice.Add (this); }