コード例 #1
0
ファイル: MySqlTest.cs プロジェクト: yhhno/Adhesive
        public void TestConcurrency()
        {
            string customerId = null;
            using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
            {
                context.Customers.Each(e => context.Customers.Remove(e));
                context.SaveChanges();
            }
            using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
            {
                Customer c = new Customer();
                c.FirstName = "James";
                c.LastName = "Chan";
                context.Customers.Add(c);
                context.SaveChanges();
                customerId = c.Id;
            }
            var th1 = new Thread(() =>
            {
                int n = 0;
                do
                {
                    using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
                    {
                        Customer c = context.Customers.Find(customerId);
                        if (c != null)
                        {
                            c.FirstName = "Alex";
                            context.SaveChanges();
                        }
                    }
                    n++;
                }
                while (n < 2);
            });
            th1.Start();

            var th2 = new Thread(() =>
            {
                int n = 0;
                do
                {
                    using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
                    {
                        Customer c = context.Customers.Find(customerId);
                        if (c != null)
                        {
                            c.FirstName = "Jhon";
                            context.SaveChanges();
                        }
                    }
                    n++;
                }
                while (n < 2);
            });
            th2.Start();

            th1.Join();
            th2.Join();
        }
コード例 #2
0
ファイル: RepositoryTest.cs プロジェクト: yhhno/Adhesive
        public void TestRepository()
        {
            AdhesiveFramework.Start();
            Customer c2 = null;
            IDbContextFactory dbContextFactory = LocalServiceLocator.GetService<IDbContextFactory>();
            IRepositoryFactory repositoryFactory = LocalServiceLocator.GetService<IRepositoryFactory>();
            using (IAdhesiveUnitOfwork adhesiveUnitOfWork = dbContextFactory.CreateContext<AdhesiveUnitOfwork>())
            {
                ICustomerRepository customerRepository = repositoryFactory.CreateRepository<Customer, CustomerRepository>(adhesiveUnitOfWork);
                var c1 = new Customer { FirstName = "James" ,LastName = "Chan"};
                customerRepository.Add(c1);
                customerRepository.UnitOfWork.Commit();
                c2 = customerRepository.Get(c1.Id);
                Assert.IsNotNull(c2);
            }
            using (IAdhesiveUnitOfwork adhesiveUnitOfWork = dbContextFactory.CreateContext<AdhesiveUnitOfwork>())
            {
                ICustomerRepository customerRepository = repositoryFactory.CreateRepository<Customer, CustomerRepository>(adhesiveUnitOfWork);
                customerRepository.TrackItem(c2);
                c2.FirstName = "James";
                customerRepository.UnitOfWork.Commit();
            }

            AdhesiveFramework.End();
        }
コード例 #3
0
ファイル: MySqlTest.cs プロジェクト: yhhno/Adhesive
        public void TestLargeWrite()
        {
            using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
            {
                for (int i = 0; i < 10000000; i++)
                {
                    Customer c = new Customer { FirstName = "James",LastName="Chan" };
                    context.Customers.Add(c);
                    context.SaveChanges();
                }

            }
        }
コード例 #4
0
ファイル: MySqlTest.cs プロジェクト: yhhno/Adhesive
 public void TestStorageContext()
 {
     string customerId = null;
     using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
     {
         context.Customers.Each(e => context.Customers.Remove(e));
         context.SaveChanges();
     }
     using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
     {
         Customer c = new Customer();
         c.FirstName = "James";
         c.LastName = "Chan";
         context.Customers.Add(c);
         context.SaveChanges();
         customerId = c.Id;
     }
     using (MySqlContext context = LocalServiceLocator.GetService<IDbContextFactory>().CreateContext<MySqlContext>())
     {
         Customer c = context.Customers.Find(customerId);
         if (c != null)
         {
             c.FirstName = "Alex";
             context.SaveChanges();
         }
     }
 }
コード例 #5
0
ファイル: SqlContextTest.cs プロジェクト: yhhno/Adhesive
 public void TestStorageContext()
 {
     AdhesiveFramework.Start();
     IDbContextFactory dbContextFactory = LocalServiceLocator.GetService<IDbContextFactory>();
     //string customerId = null;
     //using (CustomerDbContext context = dbContextFactory.CreateContext<CustomerDbContext>())
     //{
     //    context.Customers.Each(e => context.Customers.Remove(e));
     //    context.SaveChanges();
     //}
     using (CustomerDbContext context = dbContextFactory.CreateContext<CustomerDbContext>())
     {
         Customer c = new Customer();
         c.FirstName = "James";
         c.LastName = "Chan";
         context.Customers.Add(c);
         context.SaveChanges();
         //customerId = c.Id;
     }
     //using (CustomerDbContext context = dbContextFactory.CreateContext<CustomerDbContext>())
     //{
     //    Customer c = context.Customers.Find(customerId);
     //    if (c != null)
     //    {
     //        c.FirstName = "Alex";
     //        context.SaveChanges();
     //    }
     //}
     AdhesiveFramework.End();
 }