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());
            }
        }
Beispiel #3
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);
     }
 }
Beispiel #4
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();
     }
 }
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="name">Initial value of the name property.</param>
 public static Customer CreateCustomer(global::System.Int32 id, global::System.String name)
 {
     Customer customer = new Customer();
     customer.id = id;
     customer.name = name;
     return customer;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the CustomerSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomerSet(Customer customer)
 {
     base.AddObject("CustomerSet", customer);
 }