コード例 #1
0
 public static void MyClassInitialize(TestContext testContext)
 {
     context = Initializer.InitializeServiceContextQbo();
     dataServiceTestCases = new DataServiceTestCases(context);
 }
コード例 #2
0
ファイル: BatchTests.cs プロジェクト: RVDtech1/QB-V3-NET-SDK
        public void BatchTestAsync()
        {
            ServiceContext context  = Initializer.InitializeServiceContextQbo();
            DataService    service  = new DataService(context);
            Customer       customer = new Customer();
            string         guid     = Guid.NewGuid().ToString("N");

            customer.GivenName   = guid.Substring(0, 25);
            customer.Title       = guid.Substring(0, 15);
            customer.MiddleName  = guid.Substring(0, 5);
            customer.FamilyName  = guid.Substring(0, 25);
            customer.DisplayName = guid.Substring(0, 20);

            try
            {
                ManualResetEvent manualEvent = new ManualResetEvent(false);
                Batch            batch       = service.CreateNewBatch();
                batch.Add(customer, "addCustomer", OperationEnum.create);
                batch.Add("select * from Customer startPosition 0 maxResults 10", "queryCustomer");
                batch.OnBatchExecuteAsyncCompleted += (sender, e) =>
                {
                    Assert.IsNotNull(e);
                    if (e.Batch != null)
                    {
                        IntuitBatchResponse addCustomerResponse = e.Batch.IntuitBatchItemResponses[0];
                        if (addCustomerResponse.ResponseType != ResponseType.Exception)
                        {
                            Customer addedcustomer = addCustomerResponse.Entity as Customer;
                            Assert.IsNotNull(customer);
                            Assert.IsFalse(string.IsNullOrEmpty(addedcustomer.Id));
                        }
                        else
                        {
                            Assert.Fail();
                        }

                        IntuitBatchResponse queryCustomerResponse = e.Batch.IntuitBatchItemResponses[1];
                        if (queryCustomerResponse.ResponseType != ResponseType.Exception)
                        {
                            List <Customer> customers = queryCustomerResponse.Entities.ToList().ConvertAll(item => item as Customer);
                            Assert.IsNotNull(customers);
                            Assert.IsTrue(customers.Count > 1);
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }
                    else
                    {
                        Assert.Fail();
                    }

                    manualEvent.Set();
                };

                batch.ExecuteAsync();
                manualEvent.WaitOne(30000);
            }
            catch (Ipp.Exception.IdsException ex)
            {
                Assert.Fail(ex.ToString());
            }
        }