Esempio n. 1
0
 public void Can_Get_Customers_From_Database()
 {
     using (var repo = new RepositoryFactory().Create())
     {
         var customers = repo.All<Customer>().ToList();
         CollectionAssert.IsNotEmpty(customers);
     }
 }
Esempio n. 2
0
 public void RepositoryFactory_Should_Return_New_Repository_Every_Time()
 {
     var factory = new RepositoryFactory();
     var repo1 = factory.Create();
     var repo2 = factory.Create();
     Assert.AreNotSame(repo1, repo2);
     repo2.Dispose();
     repo1.Dispose();
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }