public async Task GetChanges_ReturnsCorrectDerivedClasses() { // ARRANGE var responseContent = ResourceManager.GetHttpResponseContent("GetChangesResponse.json"); var responseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(responseContent), }; var query = new ChangeQuery() { Add = true }; var mockAuthProvider = new MockAuthenticationProvider(); var mockHttpProvider = new MockHttpProvider(responseMessage, new Serializer()); var graphServiceClient = new GraphServiceClient(mockAuthProvider.Object, mockHttpProvider.Object); // ACT var response = await graphServiceClient .SharePointAPI(mockWebUrl) .Web .Request() .GetChangesAsync(query); var actual = response.CurrentPage; responseMessage.Dispose(); // ASSERT Assert.Equal(5, actual.Count); Assert.IsType <ChangeSite>(actual[0]); Assert.IsType <ChangeUser>(actual[1]); Assert.IsType <ChangeItem>(actual[2]); Assert.IsType <ChangeWeb>(actual[3]); Assert.IsType <ChangeList>(actual[4]); }
public static async Task Run() { ///////////////////////////// // // Programmer configuration // ///////////////////////////// var sharepointDomain = "demo.sharepoint.com"; var siteCollectionPath = "/sites/GraphCommunityDemo"; ///////////////// // // Configuration // ///////////////// AzureAdOptions azureAdOptions = new AzureAdOptions(); var settingsFilename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "appsettings.json"); var builder = new ConfigurationBuilder() .AddJsonFile(settingsFilename, optional: false) .AddUserSecrets <Program>(); var config = builder.Build(); config.Bind("AzureAd", azureAdOptions); //////////////////////////// // // Graph Client with Logger // //////////////////////////// var logger = new StringBuilderHttpMessageLogger(); /* * Could also use the Console if preferred... * * var logger = new ConsoleHttpMessageLogger(); */ // Use the system browser to login // https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/System-Browser-on-.Net-Core#how-to-use-the-system-browser-ie-the-default-browser-of-the-os var options = new PublicClientApplicationOptions() { AadAuthorityAudience = AadAuthorityAudience.AzureAdMyOrg, AzureCloudInstance = AzureCloudInstance.AzurePublic, ClientId = azureAdOptions.ClientId, TenantId = azureAdOptions.TenantId, RedirectUri = "http://localhost" }; // Create the public client application (desktop app), with a default redirect URI var pca = PublicClientApplicationBuilder .CreateWithApplicationOptions(options) .Build(); // Enable a simple token cache serialiation so that the user does not need to // re-sign-in each time the application is run TokenCacheHelper.EnableSerialization(pca.UserTokenCache); var scopes = new string[] { $"https://{sharepointDomain}/AllSites.FullControl" }; IAuthenticationProvider ap = new InteractiveAuthenticationProvider(pca, scopes); using (LoggingMessageHandler loggingHandler = new LoggingMessageHandler(logger)) using (HttpProvider hp = new HttpProvider(loggingHandler, false, new Serializer())) { GraphServiceClient graphServiceClient = new GraphServiceClient(ap, hp); //////////////////////////// // // Setup is complete, run the sample // //////////////////////////// var WebUrl = $"https://{sharepointDomain}{siteCollectionPath}"; var queryText = $"adaptive"; var propsToSelect = new List <string>() { "Title", "Path", "DocId]" }; var sortList = new List <SearchQuery.Sort>() { new SearchQuery.Sort("DocId", SearchQuery.SortDirection.Ascending) }; var query = new SearchQuery( queryText: queryText, selectProperties: propsToSelect, sortList: sortList); try { var results = await graphServiceClient .SharePointAPI(WebUrl) .Search .Request() .PostQueryAsync(query); var rowCount = results.PrimaryQueryResult.RelevantResults.RowCount; var totalRows = results.PrimaryQueryResult.RelevantResults.TotalRows; Console.WriteLine($"rowCount: {rowCount}"); string lastDocId = null; foreach (var item in results.PrimaryQueryResult.RelevantResults.Table.Rows) { Console.WriteLine(item.Cells.FirstOrDefault(c => c.Key == "Path").Value); var docId = item.Cells.FirstOrDefault(c => c.Key == "DocId")?.Value; if (docId != null) { lastDocId = docId; } } if (totalRows > rowCount && !string.IsNullOrEmpty(lastDocId)) { var nextPageQuery = new SearchQuery( queryText: $"{queryText} indexdocid>{lastDocId}", selectProperties: propsToSelect, sortList: sortList); var page2results = await graphServiceClient .SharePointAPI(WebUrl) .Search .Request() .PostQueryAsync(nextPageQuery); foreach (var item in page2results.PrimaryQueryResult.RelevantResults.Table.Rows) { Console.WriteLine(item.Cells.FirstOrDefault(c => c.Key == "Path").Value); } } Console.WriteLine($"totalRows: {totalRows}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Press enter to show log"); Console.ReadLine(); Console.WriteLine(); var log = logger.GetLog(); Console.WriteLine(log); } }
public static async Task Run() { ///////////////////////////// // // Programmer configuration // ///////////////////////////// var sharepointDomain = "demo.sharepoint.com"; var siteCollectionPath = "/sites/SiteDesignTest"; ///////////////// // // Configuration // ///////////////// AzureAdOptions azureAdOptions = new AzureAdOptions(); var settingsFilename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "appsettings.json"); var builder = new ConfigurationBuilder() .AddJsonFile(settingsFilename, optional: false) .AddUserSecrets <Program>(); var config = builder.Build(); config.Bind("AzureAd", azureAdOptions); //////////////////////////// // // Graph Client with Logger // //////////////////////////// var logger = new StringBuilderHttpMessageLogger(); /* * Could also use the Console if preferred... * * var logger = new ConsoleHttpMessageLogger(); */ var pca = PublicClientApplicationBuilder .Create(azureAdOptions.ClientId) .WithTenantId(azureAdOptions.TenantId) .Build(); var scopes = new string[] { $"https://{sharepointDomain}/AllSites.FullControl" }; IAuthenticationProvider ap = new DeviceCodeProvider(pca, scopes); using (LoggingMessageHandler loggingHandler = new LoggingMessageHandler(logger)) using (HttpProvider hp = new HttpProvider(loggingHandler, false, new Serializer())) { GraphServiceClient graphServiceClient = new GraphServiceClient(ap, hp); //////////////////////////// // // Setup is complete, run the sample // //////////////////////////// var WebUrl = $"https://{sharepointDomain}{siteCollectionPath}"; var siteScript = new SiteScriptMetadata() { Title = "Green Theme", Description = "Apply the Green Theme", Content = "{\"$schema\": \"schema.json\",\"actions\": [{\"verb\": \"applyTheme\",\"themeName\": \"Green\"}],\"bindata\": { },\"version\": 1}", }; var createdScript = await graphServiceClient .SharePointAPI(WebUrl) .SiteScripts .Request() .CreateAsync(siteScript); var siteDesign = new SiteDesignMetadata() { Title = "Green Theme", Description = "Apply the Green theme", SiteScriptIds = new System.Collections.Generic.List <Guid>() { new Guid(createdScript.Id) }, WebTemplate = "64" // 64 = Team Site, 68 = Communication Site, 1 = Groupless Team Site }; var createdDesign = await graphServiceClient .SharePointAPI(WebUrl) .SiteDesigns .Request() .CreateAsync(siteDesign); var applySiteDesignRequest = new ApplySiteDesignRequest { SiteDesignId = createdDesign.Id, WebUrl = WebUrl }; var applySiteDesignResponse = await graphServiceClient .SharePointAPI(WebUrl) .SiteDesigns.Request() .ApplyAsync(applySiteDesignRequest); foreach (var outcome in applySiteDesignResponse.ActionOutcomes) { Console.WriteLine(outcome.OutcomeText); } Console.WriteLine("Press enter to show log"); Console.ReadLine(); Console.WriteLine(); var log = logger.GetLog(); Console.WriteLine(log); } }
public static async Task Run() { ///////////////////////////// // // Programmer configuration // ///////////////////////////// var sharepointDomain = "demo.sharepoint.com"; var siteCollectionPath = "/sites/SiteGroupsTest"; ///////////////// // // Configuration // ///////////////// AzureAdOptions azureAdOptions = new AzureAdOptions(); var settingsFilename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "appsettings.json"); var builder = new ConfigurationBuilder() .AddJsonFile(settingsFilename, optional: false) .AddUserSecrets <Program>(); var config = builder.Build(); config.Bind("AzureAd", azureAdOptions); //////////////////////////// // // Graph Client with Logger // //////////////////////////// var logger = new StringBuilderHttpMessageLogger(); /* * Could also use the Console if preferred... * * var logger = new ConsoleHttpMessageLogger(); */ var pca = PublicClientApplicationBuilder .Create(azureAdOptions.ClientId) .WithTenantId(azureAdOptions.TenantId) .Build(); var scopes = new string[] { $"https://{sharepointDomain}/AllSites.FullControl" }; IAuthenticationProvider ap = new DeviceCodeProvider(pca, scopes); using (LoggingMessageHandler loggingHandler = new LoggingMessageHandler(logger)) using (HttpProvider hp = new HttpProvider(loggingHandler, false, new Serializer())) { GraphServiceClient graphServiceClient = new GraphServiceClient(ap, hp); //////////////////////////// // // Setup is complete, run the sample // //////////////////////////// var WebUrl = $"https://{sharepointDomain}{siteCollectionPath}"; var groups = await graphServiceClient .SharePointAPI(WebUrl) .Web .SiteGroups .Request() .Expand(g => g.Users) .Expand("Owner") .GetAsync(); foreach (var group in groups) { Console.WriteLine(group.Title); foreach (var user in group.Users) { Console.WriteLine($" {user.LoginName}"); } } Console.WriteLine("Press enter to show log"); Console.ReadLine(); Console.WriteLine(); var log = logger.GetLog(); Console.WriteLine(log); } }
public static async Task Run() { ///////////////////////////// // // Programmer configuration // ///////////////////////////// var sharepointDomain = "demo.sharepoint.com"; var siteCollectionPath = "/sites/GraphCommunityDemo"; ///////////////// // // Configuration // ///////////////// AzureAdOptions azureAdOptions = new AzureAdOptions(); var settingsFilename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "appsettings.json"); var builder = new ConfigurationBuilder() .AddJsonFile(settingsFilename, optional: false) .AddUserSecrets <Program>(); var config = builder.Build(); config.Bind("AzureAd", azureAdOptions); //////////////////////////// // // Graph Client with Logger // //////////////////////////// var logger = new StringBuilderHttpMessageLogger(); /* * Could also use the Console if preferred... * * var logger = new ConsoleHttpMessageLogger(); */ var pca = PublicClientApplicationBuilder .Create(azureAdOptions.ClientId) .WithTenantId(azureAdOptions.TenantId) .Build(); var scopes = new string[] { $"https://{sharepointDomain}/AllSites.FullControl" }; IAuthenticationProvider ap = new DeviceCodeProvider(pca, scopes); using (LoggingMessageHandler loggingHandler = new LoggingMessageHandler(logger)) using (HttpProvider hp = new HttpProvider(loggingHandler, false, new Serializer())) { GraphServiceClient graphServiceClient = new GraphServiceClient(ap, hp); //////////////////////////// // // Setup is complete, run the sample // //////////////////////////// var WebUrl = $"https://{sharepointDomain}{siteCollectionPath}"; var web = await graphServiceClient .SharePointAPI(WebUrl) .Web .Request() .GetAsync(); var changeToken = web.CurrentChangeToken; Console.WriteLine($"current change token: {changeToken.StringValue}"); Console.WriteLine($"Make an update to the site {WebUrl}"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); var qry = new ChangeQuery(true, true); qry.ChangeTokenStart = changeToken; var changes = await graphServiceClient .SharePointAPI(WebUrl) .Web .Request() .GetChangesAsync(qry); Console.WriteLine(changes.Count); foreach (var item in changes) { Console.WriteLine($"{item.ChangeType}"); } Console.WriteLine("Press enter to show log"); Console.ReadLine(); Console.WriteLine(); var log = logger.GetLog(); Console.WriteLine(log); } }