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);
        }
Exemple #2
0
 public void ShouldRetrieveAllCustomerRelatioinshipsWithAPerformantQuery_EF()
 {
     using (new TransactionScope())
     {
         var customer = new Customer { name = "Test Customer" };
         var paymentMethod = new DirectDebitPaymentMethod
                                 {
                                     AssignedTo = customer,
                                     bankAccountNumber= "1234",
                                     holderName = "Test Customer",
                                     registrationDate= DateTime.Today,
                                     status = 1
                                 };
         customer.Services.Add(new Service { BoughtBy = customer, MonthlyFee = 20, Name = "Voip" });
         var entities = new Entities();
         entities.AddToCustomerSet(customer);
         entities.AddToPaymentMethodSet(paymentMethod);
         entities.SaveChanges();
         customer.UsedPaymentMethod = paymentMethod;
         entities.SaveChanges();
         entities = new Entities();
         List<Customer> customers = entities.CustomerSet.Include("UsedPaymentMethod").Include("Services").Where(
             x => x.name == "Test Customer").ToList();
         Assert.That(customers, Has.Count.EqualTo(1));
         Assert.That(customer.Services, Has.Count.EqualTo(1));
         Assert.That(customer.UsedPaymentMethod, Is.Not.Null);
     }
 }
Exemple #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();
     }
 }