/////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Loads a test file with an error return</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseErrorTest()
        {
            Tracing.TraceMsg("Entering GoogleBaseErrorTest");

            FeedQuery query = new FeedQuery();

            Uri uri = new Uri(CreateUri(this.resourcePath + "batcherror.xml"));

            query.Uri = uri;
            Service service = new GBaseService(this.ApplicationName, this.gBaseKey);


            AtomFeed errorFeed = service.Query(query);

            foreach (AtomEntry errorEntry in errorFeed.Entries)
            {
                GDataBatchEntryData data = errorEntry.BatchData;
                if (data.Status.Code == 400)
                {
                    Assert.IsTrue(data.Status.Errors.Count == 2);
                    GDataBatchError error = data.Status.Errors[0];

                    Assert.IsTrue(error.Type == "data");
                    Assert.IsTrue(error.Field == "expiration_date");
                    Assert.IsTrue(error.Reason != null);
                    Assert.IsTrue(error.Reason.StartsWith("Invalid type specified"));

                    error = data.Status.Errors[1];

                    Assert.IsTrue(error.Type == "data");
                    Assert.IsTrue(error.Field == "price_type");
                    Assert.IsTrue(error.Reason == "Invalid price type");
                }
            }
        }
        public void GDataBatchEntryDataConstructorTest2()
        {
            GDataBatchEntryData target = new GDataBatchEntryData();

            Assert.IsNotNull(target);
            Assert.AreEqual(GDataBatchOperationType.Default, target.Type);
        }
        public void GDataBatchEntryDataConstructorTest1()
        {
            GDataBatchOperationType type   = GDataBatchOperationType.update;
            GDataBatchEntryData     target = new GDataBatchEntryData(type);

            Assert.IsNotNull(target);
            Assert.AreEqual(type, target.Type);
        }
        public void StatusTest()
        {
            GDataBatchEntryData target   = new GDataBatchEntryData(); // TODO: Initialize to an appropriate value
            GDataBatchStatus    expected = new GDataBatchStatus();
            GDataBatchStatus    actual;

            target.Status = expected;
            actual        = target.Status;
            Assert.AreEqual(expected, actual);
        }
        public void TypeTest()
        {
            GDataBatchEntryData     target   = new GDataBatchEntryData(); // TODO: Initialize to an appropriate value
            GDataBatchOperationType expected = GDataBatchOperationType.update;
            GDataBatchOperationType actual;

            target.Type = expected;
            actual      = target.Type;
            Assert.AreEqual(expected, actual);
        }
        public void GDataBatchEntryDataConstructorTest()
        {
            string ID = "TestValue"; // TODO: Initialize to an appropriate value
            GDataBatchOperationType type   = GDataBatchOperationType.update;
            GDataBatchEntryData     target = new GDataBatchEntryData(ID, type);

            Assert.IsNotNull(target);
            Assert.AreEqual(type, target.Type);
            Assert.AreEqual(ID, target.Id);
        }
        public void IdTest()
        {
            GDataBatchEntryData target = new GDataBatchEntryData(); // TODO: Initialize to an appropriate value
            string expected            = "TestValue";
            string actual;

            target.Id = expected;
            actual    = target.Id;
            Assert.AreEqual(expected, actual);
        }
        public void InterruptTest()
        {
            GDataBatchEntryData target   = new GDataBatchEntryData(); // TODO: Initialize to an appropriate value
            GDataBatchInterrupt expected = new GDataBatchInterrupt();
            GDataBatchInterrupt actual;

            target.Interrupt = expected;
            actual           = target.Interrupt;
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void BatchDataTest()
        {
            AtomEntry           target   = new AtomEntry(); // TODO: Initialize to an appropriate value
            GDataBatchEntryData expected = new GDataBatchEntryData();
            GDataBatchEntryData actual;

            target.BatchData = expected;
            actual           = target.BatchData;
            Assert.AreEqual(expected, actual);
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchDelete()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchDelete");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);

                Tracing.TraceMsg("Queried");

                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");


                AtomFeed batchFeed = new AtomFeed(new Uri(this.gBaseURI), service);

                // set the default operation.
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.delete;

                Tracing.TraceMsg("Pouet ?");

                int i = 1;
                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    AtomEntry batchEntry = new AtomEntry();
                    batchEntry.Id = entry.Id;

                    batchEntry.BatchData      = new GDataBatchEntryData();
                    batchEntry.BatchData.Id   = i.ToString();
                    batchEntry.BatchData.Type = GDataBatchOperationType.delete;

                    batchFeed.Entries.Add(batchEntry);
                    i++;
                }
                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));
                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 200, "Status code should be 200, is:" + data.Status.Code);
                }
            }
        }
        public void GoogleBaseBatchInsert()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchUpload");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;



                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);

                // this should have a batch URI

                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                AtomFeed batchFeed = new AtomFeed(new Uri(this.gBaseURI), service);

                // set the default operation. Unneeded, as the default is insert,
                // but want to make sure the code is complete
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.delete;



                for (int i = 0; i < 20; i++)
                {
                    AtomEntry entry = ObjectModelHelper.CreateGoogleBaseEntry(i);
                    entry.BatchData = new GDataBatchEntryData();

                    entry.BatchData.Type = GDataBatchOperationType.insert;
                    entry.BatchData.Id   = i.ToString();

                    batchFeed.Entries.Add(entry);
                }

                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 201, "Status code should be 201, is:" + data.Status.Code);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchUpdateSameFeed()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchUpdateSameFeed");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);
                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                int i = 0;

                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    entry.BatchData      = new GDataBatchEntryData();
                    entry.BatchData.Id   = i.ToString();
                    entry.BatchData.Type = GDataBatchOperationType.update;
                    entry.Title.Text     = "Updated";
                    i++;
                }



                AtomFeed resultFeed = service.Batch(baseFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 200, "Status code should be 200, is:" + data.Status.Code);
                }
            }
        }
Example #13
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>uses GData batch to batchupdate the cell feed. If the returned
        /// batch result set contained an error, it will throw a GDataRequestBatchException</summary>
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        public override void Publish()
        {
            if (this.Batch == null)
            {
                throw new InvalidOperationException("This feed has no batch URI");
            }

            AtomFeed batchFeed = CreateBatchFeed(GDataBatchOperationType.update);

            if (batchFeed != null)
            {
                AtomFeed resultFeed = this.Service.Batch(batchFeed, new Uri(this.Batch));
                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    if (data.Status.Code != (int)HttpStatusCode.OK)
                    {
                        throw new GDataBatchRequestException(resultFeed);
                    }
                }

                // if we get here, everything is fine. So update the edit URIs in the original feed,
                // because those might have changed.
                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    AtomEntry originalEntry = this.Entries.FindById(resultEntry.Id);
                    if (originalEntry == null)
                    {
                        throw new GDataBatchRequestException(resultFeed);
                    }
                    if (originalEntry != null)
                    {
                        originalEntry.EditUri = resultEntry.EditUri;
                    }
                }
            }
            this.Dirty = false;
        }
        /// <summary>
        /// Demonstrates inserting several mail items in a batch.
        /// </summary>
        /// <param name="numToInsert">the number of entries to insert</param>
        /// <returns>a <code>MailItemFeed</code> with the results of the insertions</returns>
        private static MailItemFeed BatchInsertMailItems(int numToInsert)
        {
            MailItemEntry[] entries = new MailItemEntry[numToInsert];

            // Set up the mail item entries to insert.
            for (int i = 0; i < numToInsert; i++)
            {
                entries[i] = SetupMailItemEntry(i.ToString());
            }

            // Execute the batch request and print the results.
            MailItemFeed batchResult = mailItemService.Batch(domain, destinationUser, entries);

            foreach (AtomEntry entry in batchResult.Entries)
            {
                GDataBatchEntryData batchData = entry.BatchData;

                Console.WriteLine("Mail message {0}: {1} {2}",
                                  batchData.Id, batchData.Status.Code, batchData.Status.Reason);
            }

            return(batchResult);
        }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new contact</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void ModelBatchContactsTest()
        {
            const int numberOfInserts = 5;

            Tracing.TraceMsg("Entering ModelInsertContactsTest");

            DeleteAllContacts();

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);

            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);

            List <Contact> list = new List <Contact>();

            Feed <Contact> f = cr.GetContacts();

            for (int i = 0; i < numberOfInserts; i++)
            {
                Contact entry = new Contact();
                entry.AtomEntry            = ObjectModelHelper.CreateContactEntry(i);
                entry.PrimaryEmail.Address = "joe" + i.ToString() + "@doe.com";
                GDataBatchEntryData g = new GDataBatchEntryData();
                g.Id            = i.ToString();
                g.Type          = GDataBatchOperationType.insert;
                entry.BatchData = g;
                list.Add(entry);
            }

            Feed <Contact> r = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default);

            list.Clear();

            int iVerify = 0;

            foreach (Contact c in r.Entries)
            {
                // let's count and update them
                iVerify++;
                c.Name.FamilyName = "get a nother one";
                c.BatchData.Type  = GDataBatchOperationType.update;
                list.Add(c);
            }
            Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 inserts");

            Feed <Contact> u = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default);

            list.Clear();

            iVerify = 0;
            foreach (Contact c in u.Entries)
            {
                // let's count and update them
                iVerify++;
                c.BatchData.Type = GDataBatchOperationType.delete;
                list.Add(c);
            }
            Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 updates");

            Feed <Contact> d = cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.Default);

            iVerify = 0;
            foreach (Contact c in d.Entries)
            {
                if (c.BatchData.Status.Code == 200)
                {
                    // let's count and update them
                    iVerify++;
                }
            }
            Assert.IsTrue(iVerify == numberOfInserts, "should have gotten 5 deletes");
        }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchMix()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchMix");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);
                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                AtomFeed batchFeed = new AtomFeed(baseFeed);

                // set the default operation.
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.insert;

                int  id      = 1;
                bool fUpdate = true;
                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    AtomEntry batchEntry = batchFeed.Entries.CopyOrMove(entry);

                    if (fUpdate == true)
                    {
                        batchEntry.BatchData      = new GDataBatchEntryData();
                        batchEntry.BatchData.Id   = id.ToString();
                        batchEntry.BatchData.Type = GDataBatchOperationType.update;
                        batchEntry.Title.Text     = "Updated";
                        fUpdate = false;
                    }
                    else
                    {
                        batchEntry.BatchData      = new GDataBatchEntryData();
                        batchEntry.BatchData.Id   = id.ToString();
                        batchEntry.BatchData.Type = GDataBatchOperationType.delete;
                        fUpdate = true;
                    }


                    // insert one
                    id++;
                    batchEntry                = ObjectModelHelper.CreateGoogleBaseEntry(1);
                    batchEntry.BatchData      = new GDataBatchEntryData();
                    batchEntry.BatchData.Type = GDataBatchOperationType.insert;
                    batchEntry.BatchData.Id   = id.ToString();
                    batchFeed.Entries.Add(batchEntry);
                    id++;
                }



                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    int testcode             = 200;
                    if (data.Type == GDataBatchOperationType.insert)
                    {
                        testcode = 201;
                    }
                    Assert.IsTrue(data.Status.Code == testcode, "Status code should be: " + testcode + ", is:" + data.Status.Code);
                }
            }
        }