Menu

[r15]: / trunk / UnitTests / GoogleAPITests.cs  Maximize  Restore  History

Download this file

77 lines (62 with data), 2.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using System.Configuration;
namespace WebGear.GoogleContactsSync.UnitTests
{
[TestFixture]
public class GoogleAPITests
{
[Test]
public void CreateNewContact()
{
try
{
ContactsService service = new ContactsService("WebGear.GoogleContactsSync");
service.setUserCredentials(ConfigurationManager.AppSettings["Gmail.Username"],
ConfigurationManager.AppSettings["Gmail.Password"]);
#region Delete previously created test contact.
ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
query.NumberToRetrieve = 500;
ContactsFeed feed = service.Query(query);
foreach (ContactEntry entry in feed.Entries)
{
if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "johndoe@example.com")
{
entry.Delete();
break;
}
}
#endregion
ContactEntry newEntry = new ContactEntry();
newEntry.Title.Text = "John Doe";
EMail primaryEmail = new EMail("johndoe@example.com");
primaryEmail.Primary = true;
primaryEmail.Rel = ContactsRelationships.IsWork;
newEntry.Emails.Add(primaryEmail);
PhoneNumber phoneNumber = new PhoneNumber("555-555-5551");
phoneNumber.Primary = true;
phoneNumber.Rel = ContactsRelationships.IsMobile;
newEntry.Phonenumbers.Add(phoneNumber);
PostalAddress postalAddress = new PostalAddress();
postalAddress.Value = "123 somewhere lane";
postalAddress.Primary = true;
postalAddress.Rel = ContactsRelationships.IsHome;
newEntry.PostalAddresses.Add(postalAddress);
newEntry.Content.Content = "Who is this guy?";
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
ContactEntry createdEntry = (ContactEntry)service.Insert(feedUri, newEntry);
Assert.IsNotNull(createdEntry.Id.Uri);
//delete this temp contact
createdEntry.Delete();
}
catch (Exception)
{
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.