Skip to content

Commit

Permalink
Split batches containing Graph Beta and Graph V1 requests into indivi…
Browse files Browse the repository at this point in the history
…dual batches + Prevent unneeded extra requests in a batch when the a previous batch was reused
  • Loading branch information
jansenbe committed Jun 2, 2021
1 parent d6f8ed8 commit e6b5829
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed

- Split batches containing Graph Beta and Graph V1 requests into individual batches [jansenbe - Bert Jansen]
- Prevent unneeded extra requests in a batch when the a previous batch was reused [jansenbe - Bert Jansen]
- Fixed loading of extra properties on retrieved content types [jansenbe - Bert Jansen]
- Renamed GetFolder methods on IListItem to GetParentFolder [jansenbe - Bert Jansen]
- Improved reliability for ChunkedFileUpload #465 [thechriskent - Chris Kent]
Expand Down
122 changes: 122 additions & 0 deletions src/sdk/PnP.Core.Test/Base/BatchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,62 @@ public async Task RemoveProcessedExplicitBatch()
}
}

[TestMethod]
public async Task RemoveProcessedExplicitGraphBatch()
{
//TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
var batch = context.NewBatch();
var team = context.Team.GetBatch(batch, o => o.Channels);
context.Execute(batch);
Assert.IsTrue(team.Result.Channels.Length > 0);
Assert.IsTrue(batch.Executed);
Assert.IsTrue(batch.Requests.Count == 2);

var firstChannel = team.Result.Channels.AsRequested().FirstOrDefault(i => i.DisplayName == "General");
Assert.IsNotNull(firstChannel);

var channel = firstChannel.GetBatch(batch, o => o.Tabs);

Assert.IsTrue(batch.Requests.Where(p => p.Value.ExecutionNeeded).Count() == 2);
Assert.IsTrue(batch.Requests.Count == 4);

context.Execute(batch);

Assert.IsTrue(batch.Executed);
Assert.IsTrue(batch.Requests.Where(p => p.Value.ExecutionNeeded).Count() == 0);
Assert.IsTrue(batch.Requests.Count == 4);
}
}

[TestMethod]
public async Task RemoveProcessedExplicitRestBatch()
{
//TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
var batch = context.NewBatch();
var site = context.Site.GetBatch(batch, p => p.AllowMasterPageEditing);
context.Execute(batch);
Assert.IsTrue(site.Result.IsPropertyAvailable(p => p.AllowMasterPageEditing));
Assert.IsTrue(batch.Executed);
Assert.IsTrue(batch.Requests.Count == 1);

var web = context.Web.GetBatch(batch, p => p.MasterUrl, p => p.CustomMasterUrl);

Assert.IsTrue(batch.Requests.Where(p => p.Value.ExecutionNeeded).Count() == 1);
Assert.IsTrue(batch.Requests.Count == 2);

context.Execute(batch);
Assert.IsTrue(web.Result.IsPropertyAvailable(p => p.CustomMasterUrl));

Assert.IsTrue(batch.Executed);
Assert.IsTrue(batch.Requests.Where(p => p.Value.ExecutionNeeded).Count() == 0);
Assert.IsTrue(batch.Requests.Count == 2);
}
}

[TestMethod]
public async Task RemoveProcessedBatch()
{
Expand Down Expand Up @@ -161,6 +217,72 @@ public async Task SplitSharePointAndGraphRequestsInTwoBatches()
}
}

[TestMethod]
public async Task SplitGraphAndGraphBetaRequestsInTwoBatches()
{
//TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
// Graph only request (there's no option to fallback to a SharePoint REST call)
await context.Team.LoadBatchAsync();
// Graph beta request
await context.TermStore.LoadBatchAsync();

// Grab the id of the current batch so we can later on find it back
Guid currentBatchId = context.CurrentBatch.Id;
var batchToExecute = context.BatchClient.GetBatchById(currentBatchId);
// We added 2 requests to the the current batch
Assert.IsTrue(batchToExecute.Requests.Count == 2);

// The first call in the batch are graph calls
Assert.IsTrue(batchToExecute.Requests[0].ApiCall.Type == ApiType.Graph);
// The second one is rest
Assert.IsTrue(batchToExecute.Requests[1].ApiCall.Type == ApiType.GraphBeta);
// Execute the batch, this will result in 2 individual batches being executed, one graph and one graph beta
await context.ExecuteAsync();

// verify data was loaded
Assert.IsTrue(context.Team.Requested);
Assert.IsTrue(context.Team.IsPropertyAvailable(p => p.Id));
Assert.IsTrue(context.TermStore.Requested);
Assert.IsTrue(context.TermStore.IsPropertyAvailable(p => p.Id));
}
}

[TestMethod]
public async Task SplitGraphAndGraphBetaRequestsInTwoBatchesWhileForcingGraphBeta()
{
//TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
context.GraphAlwaysUseBeta = true;

// Graph only request (there's no option to fallback to a SharePoint REST call)
await context.Team.LoadBatchAsync();
// Graph beta request
await context.TermStore.LoadBatchAsync();

// Grab the id of the current batch so we can later on find it back
Guid currentBatchId = context.CurrentBatch.Id;
var batchToExecute = context.BatchClient.GetBatchById(currentBatchId);
// We added 2 requests to the the current batch
Assert.IsTrue(batchToExecute.Requests.Count == 2);

// The first call in the batch are graph calls
Assert.IsTrue(batchToExecute.Requests[0].ApiCall.Type == ApiType.Graph);
// The second one is rest
Assert.IsTrue(batchToExecute.Requests[1].ApiCall.Type == ApiType.GraphBeta);
// Execute the batch, this will result in 1 graph beta batch being executed
await context.ExecuteAsync();

// verify data was loaded
Assert.IsTrue(context.Team.Requested);
Assert.IsTrue(context.Team.IsPropertyAvailable(p => p.Id));
Assert.IsTrue(context.TermStore.Requested);
Assert.IsTrue(context.TermStore.IsPropertyAvailable(p => p.Id));
}
}

[TestMethod]
public async Task MergeGetBatchResults()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e6b5829

Please sign in to comment.