public async System.Threading.Tasks.Task AddAsync() { using (var httpResponseMessage = new HttpResponseMessage()) using (var responseStream = new MemoryStream()) using (var streamContent = new StreamContent(responseStream)) { var requestUrl = string.Format("{0}/groups/groupId/members/$ref", this.graphBaseUrl); this.httpProvider.Setup( provider => provider.SendAsync( It.Is <HttpRequestMessage>( request => request.RequestUri.ToString().Equals(requestUrl) && request.Method == HttpMethod.Post && string.Equals(request.Content.Headers.ContentType.ToString(), "application/json")), HttpCompletionOption.ResponseContentRead, CancellationToken.None)) .Returns(System.Threading.Tasks.Task.FromResult(httpResponseMessage)); var userToCreate = new User { Id = "id" }; var expectedRequestBody = new ReferenceRequestBody { ODataId = string.Format("{0}/directoryObjects/{1}", this.graphBaseUrl, userToCreate.Id), }; this.serializer.Setup( serializer => serializer.SerializeObject(It.Is <ReferenceRequestBody>(requestBody => string.Equals(expectedRequestBody.ODataId, requestBody.ODataId)))) .Returns("RequestBodyString"); await this.graphServiceClient.Groups["groupId"].Members.References.Request().AddAsync(userToCreate); } }
/// <summary> /// Puts the specified ManagementTemplate reference and returns <see cref="GraphResponse"/> object. /// </summary> /// <param name="id">The ManagementTemplate reference to update.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>The task to await of <see cref="GraphResponse"/>.</returns> public System.Threading.Tasks.Task <GraphResponse> PutResponseAsync(string id, CancellationToken cancellationToken = default) { this.Method = HttpMethods.PUT; this.ContentType = CoreConstants.MimeTypeNames.Application.Json; var referenceRequestBody = new ReferenceRequestBody() { ODataId = string.Format(@"{0}/users/{1}", this.Client.BaseUrl, id) }; return(this.SendAsyncWithGraphResponse(referenceRequestBody, cancellationToken)); }