Example #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);
        }
        public void addPymentMethodWithEntityFramework()
        {
            var customer = new Customer { name = "Sciemniacz" };
            var creditCardPaymentMethod = new CreditCardPaymentMethod() { cardHolderName = "Roman", cardNumber = "123123", cardType = "visa", registrationDate = DateTime.Now, status = 1, AssignedTo = customer};
            var directDebitPaymentMethod = new DirectDebitPaymentMethod()
                                    {bankAccountNumber = "12345", holderName = "Roman", registrationDate = DateTime.Now, status = 2, AssignedTo = customer};
            customer.UsedPaymentMethod = creditCardPaymentMethod;
            var entities = new Entities();

            entities.AddToPaymentMethodSet(creditCardPaymentMethod);
            entities.AddToPaymentMethodSet(directDebitPaymentMethod);
            entities.SaveChanges();

            var entities1 = new Entities();
            List<PaymentMethod> paymentMethods = entities1.PaymentMethodSet
                .Where(x => x.registrationDate < DateTime.Now)
                .ToList();
            foreach (var paymentMethod in paymentMethods)
            {
                   Console.WriteLine(paymentMethod.GetType());
            }
        }
Example #4
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);
     }
 }
Example #5
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();
     }
 }
Example #6
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();
     }
 }