Beispiel #1
0
 public void Can_Get_Customers_From_Database()
 {
     using (var repo = new RepositoryFactory().Create())
     {
         var customers = repo.All<Customer>().ToList();
         CollectionAssert.IsNotEmpty(customers);
     }
 }
Beispiel #2
0
        public void Can_Save_New_Customer_With_Orders_And_Details()
        {
            var customer = GetCustomer();

            using (var repo = new RepositoryFactory().Create())
            {
                repo.Add(customer);
                repo.Save();
            }

            using (var repo = new RepositoryFactory().Create())
            {
                var cust = repo.All<Customer>().SingleOrDefault(c => c.Email == "*****@*****.**");
                Assert.IsNotNull(cust);
                CollectionAssert.IsNotEmpty(cust.Orders);
                Assert.IsNotNull(cust.Orders.First(o => o.OrderDetail != null).OrderDetail);
            }
        }
Beispiel #3
0
        public void Can_Save_New_Customer()
        {
            var customer = new Customer
            {
                ContactName = "johnny",
                Email = "*****@*****.**"
            };

            using (var repo = new RepositoryFactory().Create())
            {
                repo.Add(customer);
                repo.Save();
            }

            using (var repo = new RepositoryFactory().Create())
            {
                var cust = repo.All<Customer>().SingleOrDefault(c => c.Email == "*****@*****.**");
                Assert.IsNotNull(cust);
            }
        }
Beispiel #4
0
        public void Can_Use_UoW_To_Remove_And_Add_Customer_In_A_Transaction()
        {
            using(var uow = new MegaNHibernateUnitOfWorkFactory().Create())
            {
                var repo = new RepositoryFactory().Create(uow);
                var c1 = repo.All<Customer>().Single(c => c.Email == "*****@*****.**");
                repo.Delete(c1);
                var c2 = GetCustomer();
                repo.Add(c2);
                c2.Country = "Italy";
                repo.Update(c2);
                uow.Commit();
            }

            using(var repo = new RepositoryFactory().Create())
            {
                var x = repo.All<Customer>().SingleOrDefault(c => c.Email == "*****@*****.**");
                Assert.IsNull(x);
                var y = repo.All<Customer>().Any(c => c.Country == "Italy");
                Assert.IsTrue(y);
            }
        }