Beispiel #1
0
 public void ContactHasOneOrZeroAddresses_AddressHasOneContact_WithEF()
 {
     using (new TransactionScope())
     {
         var entities = new Entities();
         var contact = new Contact{Name = "Test"};
         contact.Address = new Address {Street = "Lipowa"};
         entities.AddToContactSet(contact);
         entities.SaveChanges();
         List<Contact> contacts = entities.ContactSet.Where(x=>x.Name == "Test").ToList();
         entities.DeleteObject(contacts[0].Address);
         contacts[0].Address = null;
         entities.SaveChanges();
     }
 }
        public void Should_Not_Save_All_Changes_To_The_Database_When_Commiting_A_Transactio_Scope()
        {
            var customer = new Customer { name = "Tester" };
            var entities = new Entities();
            entities.AddToCustomerSet(customer);
            entities.SaveChanges();
            using (var transactionScope = new TransactionScope())
            {
                customer.name = "Updated tester";
                transactionScope.Complete();
            }
            entities.Refresh(RefreshMode.StoreWins, customer);
            Assert.That(customer.name, Is.EqualTo("Tester"));

            entities.DeleteObject(customer);
        }
Beispiel #3
0
 public void WhenRemovingCustomerShouldRemoveAlsoServices_withEF()
 {
     using (new TransactionScope())
     {
         var entities = new Entities();
         var customer = new Customer {name = "RJ"};
         customer.Services.Add(new Service{Name = "VOIP", MonthlyFee = 20});
         entities.AddToCustomerSet(customer);
         entities.SaveChanges();
         entities = new Entities();
         Customer retrievedCustomer = entities.CustomerSet.Include("Services").Where(c => c.id == customer.id).First();
         entities.DeleteObject(retrievedCustomer);
         entities.SaveChanges();
     }
 }
Beispiel #4
0
 public void WhenRemovingContactShouldAlsoRemoveReferencedAddress_withEF()
 {
     using (new TransactionScope())
     {
         var contact = new Contact {Name = "Test", Address = new Address {Street = "Lipowa"}};
         var entities = new Entities();
         entities.AddToContactSet(contact);
         entities.SaveChanges();
         entities.DeleteObject(contact);
         entities.SaveChanges();
     }
 }