示例#1
0
        public void BatchEntityTest()
        {
            ServiceContext context = Initializer.InitializeQBOServiceContextUsingoAuth();

            DataService.DataService service = new DataService.DataService(context);

            Customer customer      = CreateCustomer();
            Customer addedCustomer = service.Add(customer);

            Invoice invoice = QBOHelper.CreateInvoice(context);

            QueryService <Term> termContext = new QueryService <Term>(context);

            QueryService <TaxRate> taxRateContext = new QueryService <TaxRate>(context);
            QueryService <TaxCode> taxCodeContext = new QueryService <TaxCode>(context);
            QueryService <Item>    itemContext    = new QueryService <Item>(context);

            DataService.Batch batch = service.CreateNewBatch();
            batch.Add(addedCustomer, "UpdateCustomer", OperationEnum.update);
            batch.Add(invoice, "AddInvoice", OperationEnum.create);
            batch.Add(termContext.Take(5).ToIdsQuery(), "QueryTerm");
            batch.Add(taxRateContext.Take(5).ToIdsQuery(), "QueryTaxRate");
            batch.Add(taxCodeContext.Take(5).ToIdsQuery(), "QueryTaxCode");
            batch.Add(itemContext.Take(5).ToIdsQuery(), "QueryItem");

            batch.Execute();
            foreach (IntuitBatchResponse resp in batch.IntuitBatchItemResponses)
            {
                if (resp.ResponseType == ResponseType.Exception)
                {
                    Assert.Fail(resp.Exception.ToString());
                }
            }
        }
示例#2
0
        internal static Item FindOrAddItem(ServiceContext context, ItemTypeEnum type)
        {
            Item        typeOfItem = null;
            List <Item> listOfItem = FindAll <Item>(context, new Item(), 1, 500).Where(i => i.status != EntityStatusEnum.SyncError).ToList();

            if (listOfItem.Count > 0)
            {
                foreach (Item item in listOfItem)
                {
                    if (item.Type == type)
                    {
                        typeOfItem = item;
                        break;
                    }
                }
            }

            if (typeOfItem == null)
            {
                DataService.DataService service = new DataService.DataService(context);
                Item item;

                item = QBOHelper.CreateItem(context);
                Item createdItem = service.Add <Item>(item);
                typeOfItem = createdItem;
            }

            return(typeOfItem);
        }
示例#3
0
        internal static PaymentMethod FindOrAddPaymentMethod(ServiceContext context, string paymentType)
        {
            PaymentMethod        typeOfPayment = null;
            List <PaymentMethod> listOfPayment = FindAll <PaymentMethod>(context, new PaymentMethod(), 1, 10).Where(p => p.status != EntityStatusEnum.SyncError).ToList();

            if (listOfPayment.Count > 0)
            {
                if (context.ServiceType == IntuitServicesType.QBO)
                {
                    foreach (PaymentMethod payment in listOfPayment)
                    {
                        if (payment.Type == paymentType)
                        {
                            typeOfPayment = payment;
                            break;
                        }
                    }

                    if (typeOfPayment == null)
                    {
                        //Create a new purchase account
                        DataService.DataService service = new DataService.DataService(context);
                        PaymentMethod           payment;
                        payment = QBOHelper.CreatePaymentMethod(context);
                        PaymentMethod createdPurchase = service.Add <PaymentMethod>(payment);
                        typeOfPayment = createdPurchase;
                    }
                }
            }

            return(typeOfPayment);
        }
示例#4
0
        internal static Purchase FindOrAddPurchase(ServiceContext context, PaymentTypeEnum paymentType)
        {
            Purchase        typeOfPurchase = null;
            List <Purchase> listOfPurchase = FindAll <Purchase>(context, new Purchase(), 1, 10).Where(p => p.status != EntityStatusEnum.SyncError).ToList();

            if (listOfPurchase.Count > 0)
            {
                if (context.ServiceType == IntuitServicesType.QBO)
                {
                    foreach (Purchase payment in listOfPurchase)
                    {
                        if (payment.PaymentType == paymentType)
                        {
                            typeOfPurchase = payment;
                            break;
                        }
                    }

                    if (typeOfPurchase == null)
                    {
                        //create a new purchase account
                        DataService.DataService service = new DataService.DataService(context);
                        Purchase purchase;
                        purchase = QBOHelper.CreatePurchase(context, PaymentTypeEnum.Cash);
                        //purchase.PaymentType = paymentType;
                        //purchase.PaymentTypeSpecified = true;
                        Purchase createdPurchase = service.Add <Purchase>(purchase);
                        typeOfPurchase = createdPurchase;
                    }
                }
            }

            return(typeOfPurchase);
        }
示例#5
0
        internal static Account FindOrAddAccount(ServiceContext context, AccountTypeEnum accountType, AccountClassificationEnum classification)
        {
            Account        typeOfAccount = null;
            List <Account> listOfAccount = FindAll <Account>(context, new Account(), 1, 500);

            if (listOfAccount.Count > 0)
            {
                foreach (Account acc in listOfAccount)
                {
                    if (acc.AccountType == accountType && acc.Classification == classification && acc.status != EntityStatusEnum.SyncError)
                    {
                        typeOfAccount = acc;
                        break;
                    }
                }
            }

            if (typeOfAccount == null)
            {
                DataService.DataService service = new DataService.DataService(context);
                Account account;

                account = QBOHelper.CreateAccount(context, accountType, classification);
                account.Classification = classification;
                account.AccountType    = accountType;
                Account createdAccount = service.Add <Account>(account);
                typeOfAccount = createdAccount;
            }

            return(typeOfAccount);
        }
示例#6
0
        internal static Customer AddCustomerHelper(ServiceContext context, Customer customer)
        {
            //Initializing the Dataservice object with ServiceContext
            DataService.DataService service = new DataService.DataService(context);

            //Adding the Customer using Dataservice object
            Customer addedCustomer = service.Add <Customer>(customer);



            return(addedCustomer);
        }
示例#7
0
        internal static T Add <T>(ServiceContext context, T entity) where T : IEntity
        {
            //Initializing the Dataservice object with ServiceContext
            DataService.DataService service = new DataService.DataService(context);

            //Adding the Bill using Dataservice object

            T added = service.Add <T>(entity);

            //get IntuitEntity from entity
            if (added.GetType().IsSubclassOf(typeof(IntuitEntity)))
            {
                IntuitEntity addedEntity = (IntuitEntity)(object)added;

                //Checking id of added Bill is not Null. If it is Null, Bill is not added properly
                Assert.IsNotNull(addedEntity.Id);
            }

            return(added);
        }
示例#8
0
        public void BatchInvoiceTest()
        {
            ServiceContext context = Initializer.InitializeQBOServiceContextUsingoAuth();

            DataService.DataService service          = new DataService.DataService(context);
            List <Invoice>          addedInvoiceList = new List <Invoice>();
            List <Invoice>          newInvoiceList   = new List <Invoice>();

            for (int i = 0; i < 5; i++)
            {
                Invoice invoice = QBOHelper.CreateInvoice(context);
                addedInvoiceList.Add(service.Add <Invoice>(invoice));
            }

            for (int i = 0; i < 5; i++)
            {
                newInvoiceList.Add(QBOHelper.CreateInvoice(context));
            }

            QueryService <Invoice> invoiceContext = new QueryService <Invoice>(context);

            DataService.Batch batch = service.CreateNewBatch();

            int count = 1;

            foreach (Invoice invoice in newInvoiceList)
            {
                batch.Add(invoice, "AddInvoice" + count, OperationEnum.create);
                count++;
            }

            count = 0;

            List <string> docNumbers = new List <string>();

            foreach (Invoice invoice in addedInvoiceList)
            {
                invoice.DocNumber = "SUDoc" + Guid.NewGuid().ToString().Substring(0, 6);
                docNumbers.Add(invoice.DocNumber);
                invoice.sparse          = true;
                invoice.sparseSpecified = true;
                invoice.TxnTaxDetail    = null;
                batch.Add(invoice, "UpdateInvoice" + count, OperationEnum.update);
                count++;
            }

            string[] values = docNumbers.ToArray();
            batch.Add(invoiceContext.Where(c => c.DocNumber.In(values)).ToIdsQuery(), "QueryInvoice1");
            batch.Execute();

            int position = 0;

            foreach (IntuitBatchResponse resp in batch.IntuitBatchItemResponses)
            {
                if (resp.ResponseType == ResponseType.Exception)
                {
                    Assert.Fail(resp.Exception.ToString());
                }

                if (position <= 4)
                {
                    Assert.IsFalse(string.IsNullOrEmpty((resp.Entity as Invoice).Id));
                }

                if (position > 4 && position < 10)
                {
                    Assert.IsTrue(((Invoice)resp.Entity).DocNumber.Contains("SUDoc"));
                }

                if (position == 10)
                {
                    Assert.IsTrue(resp.Entities.Count == 5);
                }

                position++;
            }
        }