Exemplo n.º 1
0
        public void IDataContext_Dispose_Test()
        {
            IRepositoryProvider repositoryProvider = new RepositoryProvider(new RepositoryFactories());
            IDataContextAsync   context            = new ProjectXContext();
            IUnitOfWorkAsync    unitOfWork         = new UnitOfWork(context, repositoryProvider);

            // opening connection
            unitOfWork.BeginTransaction();
            unitOfWork.Commit();

            // calling dispose 1st time
            context.Dispose();

            var isDisposed = (bool)GetInstanceField(typeof(DataContext), context, "_disposed");

            Assert.IsTrue(isDisposed);

            // calling dispose 2nd time, should not throw any excpetions
            unitOfWork.Dispose();
            context.Dispose();

            // calling dispose 3rd time, should not throw any excpetions
            unitOfWork.Dispose();
            context.Dispose();
        }
Exemplo n.º 2
0
        public void GetItemsWithDetail()
        {
            using (IDataContextAsync context = new ProjectXContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context, _repositoryProvider))
                {
                    IRepositoryAsync <Item> itemRepository = new Repository <Item>(context, unitOfWork);
                    ItemService             itemService    = new ItemService(itemRepository);

                    var items = itemService.GetTransactionItems();

                    Assert.IsTrue(items.Count <Item>() > 0);
                }
        }
Exemplo n.º 3
0
        public void GetItems()
        {
            using (IDataContextAsync context = new ProjectXContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context, _repositoryProvider))
                {
                    IRepositoryAsync <Item> itemRepository = new Repository <Item>(context, unitOfWork);
                    ItemService             itemService    = new ItemService(itemRepository);

                    var item = itemService.GetTransactionItems().Where(i => i.ItemFullCode == "10-01-01-00004").FirstOrDefault();
                    //var item = itemService.GetAllTransactionItems().FirstOrDefault();

                    Assert.IsNotNull(item.SubInventory);
                }
        }
Exemplo n.º 4
0
        public static System.Collections.IEnumerable GetSubInventory()
        {
            using (IDataContextAsync context = new ProjectXContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context, _repositoryProvider))
                {
                    IRepositoryAsync <SubInventory> repo    = new Repository <SubInventory>(context, unitOfWork);
                    SubInventoryService             service = new SubInventoryService(repo);

                    return(service.Queryable()
                           .Select(s => new SubInventoryModel
                    {
                        SubInvCode = s.SubInvCode,
                        SubInvName = s.SubInvName
                    }).OrderBy(o => o.SubInvCode).ToList());
                }
        }
Exemplo n.º 5
0
        public void UnitOfWork_Transaction_Test()
        {
            IRepositoryProvider repositoryProvider = new RepositoryProvider(new RepositoryFactories());

            using (IDataContextAsync context = new ProjectXContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context, repositoryProvider))
                {
                    //IRepositoryAsync<Customer> customerRepository = new Repository<Customer>(context, unitOfWork);
                    //IService<Customer> customerService = new CustomerService(customerRepository);

                    //try
                    //{
                    //    unitOfWork.BeginTransaction();

                    //    customerService.Insert(new Customer { CustomerID = "YODA", CompanyName = "SkyRanch", ObjectState = ObjectState.Added});
                    //    customerService.Insert(new Customer { CustomerID = "JEDI", CompanyName = "SkyRanch", ObjectState = ObjectState.Added});

                    //    var customer = customerService.Find("YODA");
                    //    Assert.AreSame(customer.CustomerID, "YODA");

                    //    customer = customerService.Find("JEDI");
                    //    Assert.AreSame(customer.CustomerID, "JEDI");

                    //    // save
                    //    var saveChangesAsync = unitOfWork.SaveChanges();
                    //    //Assert.AreSame(saveChangesAsync, 2);

                    //    // Will cause an exception, cannot insert customer with the same CustomerId (primary key constraint)
                    //    customerService.Insert(new Customer { CustomerID = "JEDI", CompanyName = "SkyRanch", ObjectState = ObjectState.Added });
                    //    //save
                    //    unitOfWork.SaveChanges();

                    //    unitOfWork.Commit();
                    //}
                    //catch (Exception e)
                    //{
                    //    unitOfWork.Rollback();
                    //}
                }
        }