diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 85dc914..83da393 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.Services.Graph; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Graph; using Microsoft.VisualStudio.Services.Graph.Client; using Microsoft.VisualStudio.Services.WebApi; using System; @@ -82,6 +83,64 @@ namespace Microsoft.TeamServices.Samples.Client.Graph } } + /// + /// Create a new project level group and then delete the group + /// + [ClientSampleMethod] + public void CreateDeleteProjectVSTSGroup() + { + // Get the client + VssConnection connection = Context.Connection; + + // + // Part 1: get the project id + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectId"); + ProjectHttpClient projectClient = connection.GetClient(); + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; + Guid projectId = project.Id; + + // + // Part 2: get the project scope descriptor + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectScopeDescriptor"); + GraphHttpClient graphClient = connection.GetClient(); + GraphDescriptorResult projectDescriptor = graphClient.GetDescriptorAsync(projectId).Result; + + // + // Part 3: create a group at the project level + // + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroupInProject"); + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Project Developers-" + Guid.NewGuid(), + Description = "Group at project level created via client library" + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext, projectDescriptor.Value).Result; + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 4: delete the group + // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup"); + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group (should result in an exception) + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); + try + { + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted group:" + e.Message); + } + } + /// /// Add an existing Azure Active Directory group to the VSTS account, and then remove it ///