Or, you use the new and improved contacts object model that is
currently only available over subversion. You find this and more code
like it in src/unittests/contactstest.cs. Removed code here that is
not relevant. This method gets' the groups feed, inserst 2 groups,
creates a contact, inserts the contact, adds the contact to groups,
removes it and deletes the whole thing again...
[Test] public void GroupsModelTest()
{
RequestSettings rs = new
RequestSettings(this.ApplicationName, this.userName, this.passWord);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Group> fg = cr.GetGroups();
Group newGroup = new Group();
newGroup.Title = "Private Data";
Group insertedGroup = cr.Insert(fg, newGroup);
Group g2 = new Group();
g2.Title = "Another private Group";
Group insertedGroup2 = cr.Insert(fg, g2);
// now insert a new contact that belongs to that group
Feed<Contact> fc = cr.GetContacts();
Contact c = new Contact();
/// set up contat properties
Contact insertedEntry = cr.Insert(fc, c);
GroupMembership member = new GroupMembership();
member.HRef = insertedGroup.Id;
GroupMembership member2 = new GroupMembership();
member2.HRef = insertedGroup2.Id;
// now change the group membership
insertedEntry.GroupMembership.Add(member);
insertedEntry.GroupMembership.Add(member2);
Contact currentEntry = cr.Update(insertedEntry);
Assert.IsTrue(currentEntry.GroupMembership.Count == 2,
"The entry should be in 2 groups");
currentEntry.GroupMembership.Clear();
currentEntry = cr.Update(currentEntry);
Assert.IsTrue(currentEntry.GroupMembership.Count == 0,
"The entry should not be in groups");
cr.Delete(currentEntry);
cr.Delete(insertedGroup);
cr.Delete(insertedGroup2);
}
Frank