public async Task DeleteListViaExplicitBatchRest() { //TestCommon.Instance.Mocking = false; using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite)) { // Get the lists await context.Web.LoadAsync(p => p.Lists); Core.Services.Batch batch = null; string listTitle = "DeleteListViaExplicitBatchRest"; var myList = context.Web.Lists.AsRequested().FirstOrDefault(p => p.Title == listTitle); if (myList == null) { batch = context.BatchClient.EnsureBatch(); myList = await context.Web.Lists.AddBatchAsync(batch, listTitle, ListTemplateType.GenericList); await context.ExecuteAsync(batch); } else { Assert.Inconclusive("Test data set should be setup to not have the list available."); } var listCount = context.Web.Lists.Length; // Delete the list batch = context.BatchClient.EnsureBatch(); await myList.DeleteBatchAsync(batch); await context.ExecuteAsync(batch); // Was the list added bool exceptionThrown = false; try { var deletedListDescription = myList.Description; } catch (Exception) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); // Get the lists again batch = context.BatchClient.EnsureBatch(); await context.Web.LoadBatchAsync(batch, p => p.Lists); await context.ExecuteAsync(batch); Assert.IsTrue(context.Web.Lists.Length == listCount - 1); } }
public async Task DeleteChannelViaExplicitBatchGraph() { //TestCommon.Instance.Mocking = false; using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite)) { // Initial load of channels await context.Team.LoadBatchAsync(p => p.Channels); await context.ExecuteAsync(); Core.Services.Batch batch = null; string channelName = $"Channel test {new Random().Next()}"; // Find first updatable channel var channelToDelete = context.Team.Channels.AsRequested().FirstOrDefault(p => p.DisplayName == channelName); if (channelToDelete == null) { batch = context.BatchClient.EnsureBatch(); channelToDelete = await context.Team.Channels.AddBatchAsync(batch, channelName, "Test channel, will be deleted in 21 days"); await context.ExecuteAsync(batch); } else { Assert.Inconclusive("Test data set should be setup to not have the channel available."); } var channelCount = context.Team.Channels.Length; // Delete channel batch = context.BatchClient.EnsureBatch(); await channelToDelete.DeleteBatchAsync(batch); await context.ExecuteAsync(batch); // Was the channel deleted? Assert.ThrowsException <ClientException>(() => { var deletedChannelDescription = channelToDelete.Description; }); // Get the channel again batch = context.BatchClient.EnsureBatch(); await context.Team.LoadBatchAsync(batch, p => p.Channels); await context.ExecuteAsync(batch); // We should have one channel less Assert.IsTrue(context.Team.Channels.Length == channelCount - 1); } }