public async System.Threading.Tasks.Task GetAsync_InitializeCollectionProperties() { using (var httpResponseMessage = new HttpResponseMessage()) using (var responseStream = new MemoryStream()) using (var streamContent = new StreamContent(responseStream)) { httpResponseMessage.Content = streamContent; var requestUrl = string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/me/drive/items/id"; this.httpProvider.Setup( provider => provider.SendAsync( It.Is <HttpRequestMessage>( request => request.RequestUri.ToString().Equals(requestUrl)), HttpCompletionOption.ResponseContentRead, CancellationToken.None)) .Returns(System.Threading.Tasks.Task.FromResult <HttpResponseMessage>(httpResponseMessage)); var expectedChildrenPage = new DriveItemChildrenCollectionPage { new DriveItem { Id = "id" } }; var expectedItemResponse = new DriveItem { AdditionalData = new Dictionary <string, object> { { "*****@*****.**", requestUrl + "/next" } }, Children = expectedChildrenPage, }; this.serializer.Setup( serializer => serializer.DeserializeObject <DriveItem>(It.IsAny <string>())) .Returns(expectedItemResponse); var item = await this.graphServiceClient.Me.Drive.Items["id"].Request().GetAsync(); Assert.NotNull(item); Assert.NotNull(item.Children); Assert.Equal(1, item.Children.CurrentPage.Count); Assert.Equal("id", item.Children.CurrentPage[0].Id); Assert.Equal(expectedItemResponse.AdditionalData, item.Children.AdditionalData); var nextPageRequest = item.Children.NextPageRequest as DriveItemChildrenCollectionRequest; Assert.NotNull(nextPageRequest); Assert.Equal(new Uri(requestUrl + "/next"), new Uri(nextPageRequest.RequestUrl)); } }
public async Task GetAsync_InitializeCollectionProperties() { using (var httpResponseMessage = new HttpResponseMessage()) using (var responseStream = new MemoryStream()) using (var streamContent = new StreamContent(responseStream)) { httpResponseMessage.Content = streamContent; var requestUrl = string.Format(Constants.Url.GraphBaseUrlFormatString, "v1.0") + "/me/drive/items/id"; this.httpProvider.Setup( provider => provider.SendAsync( It.Is <HttpRequestMessage>( request => request.RequestUri.ToString().Equals(requestUrl)))) .Returns(Task.FromResult <HttpResponseMessage>(httpResponseMessage)); var expectedChildrenPage = new DriveItemChildrenCollectionPage { new DriveItem { Id = "id" } }; var expectedItemResponse = new DriveItem { AdditionalData = new Dictionary <string, object> { { "*****@*****.**", requestUrl + "/next" } }, Children = expectedChildrenPage, }; this.serializer.Setup( serializer => serializer.DeserializeObject <DriveItem>(It.IsAny <string>())) .Returns(expectedItemResponse); var item = await this.graphServiceClient.Me.Drive.Items["id"].Request().GetAsync(); Assert.IsNotNull(item, "DriveItem not returned."); Assert.IsNotNull(item.Children, "DriveItem children not returned."); Assert.AreEqual(1, item.Children.CurrentPage.Count, "Unexpected number of children in page."); Assert.AreEqual("id", item.Children.CurrentPage[0].Id, "Unexpected child ID in page."); Assert.AreEqual(expectedItemResponse.AdditionalData, item.Children.AdditionalData, "Additional data not initialized correctly."); var nextPageRequest = item.Children.NextPageRequest as DriveItemChildrenCollectionRequest; Assert.IsNotNull(nextPageRequest, "Children next page request not initialized correctly."); Assert.AreEqual(new Uri(requestUrl + "/next"), new Uri(nextPageRequest.RequestUrl), "Unexpected request URL for next page request."); } }
public void DeserializeInterface() { var driveItemChildrenCollectionPage = new DriveItemChildrenCollectionPage { new DriveItem { Id = "id" }, }; var serializedString = this.serializer.SerializeObject(driveItemChildrenCollectionPage); var deserializedPage = this.serializer.DeserializeObject <IDriveItemChildrenCollectionPage>(serializedString); Assert.IsType(typeof(DriveItemChildrenCollectionPage), deserializedPage); Assert.Equal(1, deserializedPage.Count); Assert.Equal("id", deserializedPage[0].Id); }
public void DeserializeInterface() { var driveItemChildrenCollectionPage = new DriveItemChildrenCollectionPage { new DriveItem { Id = "id" }, }; var serializedString = this.serializer.SerializeObject(driveItemChildrenCollectionPage); var deserializedPage = this.serializer.DeserializeObject <IDriveItemChildrenCollectionPage>(serializedString); Assert.IsInstanceOfType(deserializedPage, typeof(DriveItemChildrenCollectionPage), "Unexpected object deserialized."); Assert.AreEqual(1, deserializedPage.Count, "Unexpected driveItems deserialized."); Assert.AreEqual("id", deserializedPage[0].Id, "Unexpected driveItem deserialized."); }
public async Async.Task SharePointGetNonDefaultDocumentLibraries() { try { // Specify the search query parameter. var searchQuery = new QueryOption("search", "sales"); var options = new List <QueryOption>(); options.Add(searchQuery); // Call the Microsoft Graph API. Expecting a single search entry from the tenant. var siteSearchResults = await graphClient.Sites.Request(options).GetAsync(); Assert.IsTrue(siteSearchResults.Count > 0, "Expected at least one search result. Got zero. Check test data."); // Call the Microsoft Graph API. Get the sites drives collection page. SiteDrivesCollectionPage drives = (SiteDrivesCollectionPage)graphClient.Sites[siteSearchResults[0].Id] .Drives .Request() .GetAsync() .Result; // Call the Microsoft Graph API. Get the drives collection page. DriveItemChildrenCollectionPage library = (DriveItemChildrenCollectionPage)graphClient.Sites[siteSearchResults[0].Id] .Drives[drives[0].Id] .Root .Children .Request() .GetAsync() .Result; Assert.IsTrue(library.Count > 0, "Expected at least one driveitem result. Got zero. Check test data."); } catch (Microsoft.Graph.ServiceException e) { Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code); } }