Esempio n. 1
0
        public void Execute()
        {
            GBaseFeed feed = ReadFromStandardInput();

            GBaseEntry result = service.Insert(uriFactory.ItemsFeedUri,
                                               feed.Entries[0] as GBaseEntry);

            WriteToStandardOutput(result);
        }
Esempio n. 2
0
        public void Execute()
        {
            GBaseFeed  feed  = ReadFromStandardInput();
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            entry.EditUri = entry.Id.Uri;
            service.Update(entry);

            Console.WriteLine("Item updated: " + entry.Id.Uri);
        }
        public void ReadItemTypesFeedFromXml()
        {
            string xml = "<?xml version='1.0' encoding='UTF-8'?>\n" +
                         "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-metadata/1.0'>\n" +
                         "  <id>http://www.google.com/base/feeds/itemtypes/en_US</id>\n" +
                         "  <updated>2006-08-24T14:32:27.228Z</updated>\n" +
                         "  <title type='text'>Item types for locale en_US</title>\n" +
                         "  <link rel='alternate' type='text/html' href='http://www.google.com'/>\n" +
                         "  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/base/feeds/itemtypes/en_US'/>\n" +
                         "  <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/itemtypes/en_US?max-results=1&amp;key=ABQIAAAAfW6XRFfnNGUiegdqIq0KExT2yXp_ZAY8_ufC3CFXhHIE1NvwkxS8MfEf7Ag6UI0Ony8Yq3gZHm6c9w'/>\n" +
                         "  <author>\n" +
                         "    <name>Google Inc.</name>\n" +
                         "    <email>[email protected]</email>\n" +
                         "  </author>\n" +
                         "  <generator version='1.0' uri='http://www.google.com'>GoogleBase</generator>\n" +
                         "  <openSearch:totalResults>1</openSearch:totalResults>\n" +
                         "  <openSearch:itemsPerPage>1</openSearch:itemsPerPage>\n" +
                         "  <entry>\n" +
                         "    <id>http://www.google.com/base/feeds/itemtypes/en_US/products</id>\n" +
                         "    <updated>2006-08-24T14:32:27.233Z</updated>\n" +
                         "    <category scheme='http://www.google.com/categories/itemtypes' term='products'/>\n" +
                         "    <title type='text'>products</title>\n" +
                         "    <content type='text'>products</content>\n" +
                         "    <gm:item_type>products</gm:item_type>\n" +
                         "    <gm:attributes>\n" +
                         "      <gm:attribute name='product type' type='text'/>\n" +
                         "      <gm:attribute name='condition' type='text'/>\n" +
                         "      <gm:attribute name='count' type='int'/>\n" +
                         "    </gm:attributes>\n" +
                         "  </entry>\n" +
                         "</feed>";
            GBaseFeed  feed  = Parse(xml);
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            Assert.IsNotNull(entry, "entry");

            ItemTypeDefinition def = entry.ItemTypeDefinition;

            Assert.IsNotNull(def, "ItemTypeDefinition");
            Assert.AreEqual("products", def.ItemType);
            Assert.AreEqual(3, def.Attributes.Count);
            Assert.AreEqual("product type", def.Attributes[0].Name);
            Assert.AreEqual(GBaseAttributeType.Text, def.Attributes[0].Type);
            Assert.AreEqual("condition", def.Attributes[1].Name);
            Assert.AreEqual(GBaseAttributeType.Text, def.Attributes[1].Type);
            Assert.AreEqual("count", def.Attributes[2].Name);
            Assert.AreEqual(GBaseAttributeType.Int, def.Attributes[2].Type);
        }
        public void ReadAttributesFeedFromXml()
        {
            string xml = "<?xml version='1.0' encoding='UTF-8'?>" +
                         "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-metadata/1.0'>" +
                         "  <id>http://www.google.com/base/feeds/attributes</id>" +
                         "  <updated>2006-08-24T14:26:45.558Z</updated>" +
                         "  <title type='text'>Attribute histogram for query: </title>" +
                         "  <link rel='alternate' type='text/html' href='http://www.google.com'/>" +
                         "  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes'/>" +
                         "  <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes?max-results=1&amp;key=ABQIAAAA7VerLsOcLuBYXR7vZI2NjhTRERdeAiwZ9EeJWta3L_JZVS0bOBRIFbhTrQjhHE52fqjZvfabYYyn6A'/>" +
                         "  <generator version='1.0' uri='http://www.google.com'>GoogleBase</generator>" +
                         "  <openSearch:totalResults>1</openSearch:totalResults>" +
                         "  <openSearch:itemsPerPage>1</openSearch:itemsPerPage>" +
                         "  <entry>" +
                         "    <id>http://www.google.com/base/feeds/attributes/label%28text%29N</id>" +
                         "    <updated>2006-08-24T14:26:45.651Z</updated>" +
                         "    <title type='text'>label(text)</title>" +
                         "    <content type='text'>Attribute label of type text.</content>" +
                         "    <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes/label%28text%29N'/>" +
                         "    <gm:attribute name='label' type='text' count='158778'>" +
                         "      <gm:value count='47544'>housing</gm:value>" +
                         "      <gm:value count='36954'>reviews</gm:value>" +
                         "    </gm:attribute>" +
                         "  </entry>" +
                         "</feed>";
            GBaseFeed  feed  = Parse(xml);
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            Assert.IsNotNull(entry, "entry");

            AttributeHistogram hist = entry.AttributeHistogram;

            Assert.AreEqual("label", hist.Name, "name");
            Assert.AreEqual(GBaseAttributeType.Text, hist.Type, "type");
            Assert.AreEqual(158778, hist.Count, "count");

            List <HistogramValue> values = hist.Values;

            Assert.AreEqual(2, values.Count, "values.Length");
            Assert.AreEqual("housing", values[0].Content);
            Assert.AreEqual(47544, values[0].Count);
            Assert.AreEqual("reviews", values[1].Content);
            Assert.AreEqual(36954, values[1].Count);
        }
        private void CheckParsedFeedEntries(GBaseFeed feed)
        {
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            Assert.IsNotNull(entry, "entry");
            GBaseAttributes attrs = entry.GBaseAttributes;

            Assert.AreEqual("Recipes", attrs.ItemType, "item type");
            Assert.AreEqual("Mountain View, CA 94043", attrs.Location, "location");
            String[] labels = attrs.Labels;
            Assert.AreEqual("kung pao chicken", labels[0], "label");
            Assert.AreEqual("chinese cuisine", labels[1], "label");
            Assert.AreEqual("recipes", labels[2], "label");
            Assert.AreEqual("asian", labels[3], "label");
            Assert.AreEqual("sichuan", labels[4], "label");
            Assert.AreEqual(5f, attrs.GetNumberAttribute("serving count", 0f));
            Assert.IsNotNull(entry.Stats, "gm:stats");
            Assert.AreEqual(100, entry.Stats.Impressions.Total, "gm:impressions");
        }
        public void testGetSetAttributeHistogram()
        {
            AttributeHistogram xHistogram = new AttributeHistogram("x",
                                                                   GBaseAttributeType.Int,
                                                                   2);
            AttributeHistogram yHistogram = new AttributeHistogram("x",
                                                                   GBaseAttributeType.Int,
                                                                   2);
            GBaseEntry entry = new GBaseEntry();

            Assert.IsNull(entry.AttributeHistogram);

            entry.AttributeHistogram = xHistogram;

            Assert.AreEqual(xHistogram, entry.AttributeHistogram);

            entry.AttributeHistogram = yHistogram;

            Assert.AreEqual(yHistogram, entry.AttributeHistogram);

            entry.AttributeHistogram = null;

            Assert.AreEqual(null, entry.AttributeHistogram);
        }
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Base AuthenticationTest");

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

            int iCount;

            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");

                ObjectModelHelper.DumpAtomObject(baseFeed, CreateDumpFileName("AuthenticationTest"));
                iCount = baseFeed.Entries.Count;

                String strTitle = "Dinner time" + Guid.NewGuid().ToString();

                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // get the first entry
                    AtomEntry entry = baseFeed.Entries[0];

                    entry            = ObjectModelHelper.CreateGoogleBaseEntry(1);
                    entry.Title.Text = strTitle;

                    GBaseEntry newEntry = baseFeed.Insert(entry) as GBaseEntry;

                    newEntry.PublishingPriority = new PublishingPriority("high");

                    GBaseEntry updatedEntry = newEntry.Update() as GBaseEntry;

                    //  publishing priority does not seem to be echoed back
                    // Assert.IsTrue(updatedEntry.PublishingPriority.Value == "high");
                    iCount++;
                    Tracing.TraceMsg("Created google base  entry");

                    // try to get just that guy.....
                    FeedQuery singleQuery = new FeedQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString());

                    AtomFeed newFeed = service.Query(singleQuery);

                    AtomEntry sameGuy = newFeed.Entries[0];

                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical");
                }

                baseFeed = service.Query(query);


                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in baseFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
                        if (String.Compare(entry.Title.Text, strTitle) == 0)
                        {
                            entry.Content.Content = "Maybe stay until breakfast";
                            entry.Content.Type    = "text";
                            entry.Update();
                            Tracing.TraceMsg("Updated entry");
                        }
                    }
                }

                baseFeed = service.Query(query);

                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in baseFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
                        if (String.Compare(entry.Title.Text, strTitle) == 0)
                        {
                            entry.Delete();
                            iCount--;
                            Tracing.TraceMsg("deleted entry");
                        }
                    }
                }
                baseFeed            = service.Query(query);
                service.Credentials = null;
            }
        }