From 3df04c314887ccdd946160b33e04b8dfcefc1158 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 31 Aug 2021 09:46:39 -0700 Subject: [PATCH] Updated WCT to 7.1.0rc --- .../CommunityToolkit.Graph.Uwp.csproj | 5 ++- .../Controls/GraphPresenter/GraphPresenter.cs | 1 - .../CommunityToolkit.Graph.csproj | 4 +-- .../Extensions/GraphExtensions.OneDrive.cs | 30 ++++++++++++++++++ .../RoamingSettings/OneDriveStorageHelper.cs | 31 +++++++++++++++++-- SampleTest/SampleTest.csproj | 2 +- .../Providers/Test_MockProvider.cs | 4 +-- .../Providers/Test_WindowsProvider.cs | 4 +-- .../RoamingSettings/Test_OneDriveDataStore.cs | 14 +++++---- .../Test_UserExtensionDataStore.cs | 4 +-- UnitTests/UnitTests.UWP/VisualUITestBase.cs | 4 +-- 11 files changed, 79 insertions(+), 24 deletions(-) diff --git a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj index f7a121f..8305660 100644 --- a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj +++ b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj @@ -23,9 +23,8 @@ - - - + + diff --git a/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs b/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs index abc710b..a9ba80a 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs +++ b/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs @@ -20,7 +20,6 @@ namespace CommunityToolkit.Graph.Uwp.Controls /// public class GraphPresenter : ContentPresenter { - /// /// Identifies the dependency property. /// diff --git a/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj b/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj index 18f7b16..f5b290f 100644 --- a/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj +++ b/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj @@ -20,8 +20,8 @@ - - + + diff --git a/CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs b/CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs index ee5c93e..206afaa 100644 --- a/CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs +++ b/CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs @@ -20,6 +20,11 @@ public static partial class GraphExtensions /// /// Updates or create a new file on the remote with the provided content. /// + /// Instance of the . + /// The id of the target Graph user. + /// The path of the target item. + /// The contents to put in the file. + /// A serializer for converting stored values. /// The type of object to save. /// A representing the asynchronous operation. public static async Task SetFileAsync(this GraphServiceClient graph, string userId, string itemPath, T fileContents, IObjectSerializer serializer) @@ -33,6 +38,10 @@ public static async Task SetFileAsync(this GraphServiceClient grap /// /// Get a file from the remote. /// + /// Instance of the . + /// The id of the target Graph user. + /// The path of the target item. + /// A serializer for converting stored values. /// The type of object to return. /// A representing the asynchronous operation. public static async Task GetFileAsync(this GraphServiceClient graph, string userId, string itemPath, IObjectSerializer serializer) @@ -47,12 +56,33 @@ public static async Task GetFileAsync(this GraphServiceClient graph, strin /// /// Delete the file from the remote. /// + /// Instance of the . + /// The id of the target Graph user. + /// The path of the target item. /// A representing the asynchronous operation. public static async Task DeleteItemAsync(this GraphServiceClient graph, string userId, string itemPath) { await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().DeleteAsync(); } + /// + /// Rename an item. + /// + /// Instance of the . + /// The id of the target Graph user. + /// The path of the target item. + /// The new name for the item. + /// A representing the asynchronous operation. + public static async Task RenameItemAsync(this GraphServiceClient graph, string userId, string itemPath, string newName) + { + var driveItem = new DriveItem + { + Name = newName, + }; + + await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().UpdateAsync(driveItem); + } + /// /// Ensure a folder exists by name. /// diff --git a/CommunityToolkit.Graph/Helpers/RoamingSettings/OneDriveStorageHelper.cs b/CommunityToolkit.Graph/Helpers/RoamingSettings/OneDriveStorageHelper.cs index c9b56fd..d235c38 100644 --- a/CommunityToolkit.Graph/Helpers/RoamingSettings/OneDriveStorageHelper.cs +++ b/CommunityToolkit.Graph/Helpers/RoamingSettings/OneDriveStorageHelper.cs @@ -95,10 +95,35 @@ public Task CreateFolderAsync(string folderName, string folderPath) } /// - public Task DeleteItemAsync(string itemPath) + public async Task TryDeleteItemAsync(string itemPath) { - var graph = GetGraphClient(); - return graph.DeleteItemAsync(UserId, itemPath); + try + { + var graph = GetGraphClient(); + await graph.DeleteItemAsync(UserId, itemPath); + + return true; + } + catch + { + return false; + } + } + + /// + public async Task TryRenameItemAsync(string itemPath, string newName) + { + try + { + var graph = GetGraphClient(); + await graph.RenameItemAsync(UserId, itemPath, newName); + + return true; + } + catch + { + return false; + } } private static GraphServiceClient GetGraphClient() diff --git a/SampleTest/SampleTest.csproj b/SampleTest/SampleTest.csproj index fedf21a..d7d99f6 100644 --- a/SampleTest/SampleTest.csproj +++ b/SampleTest/SampleTest.csproj @@ -181,7 +181,7 @@ - 4.2.0 + 4.3.0 6.2.12 diff --git a/UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs b/UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs index 5683778..50b6c26 100644 --- a/UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs +++ b/UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using CommunityToolkit.Authentication; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Net.Http; using System.Threading.Tasks; +using CommunityToolkit.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.UWP.Authentication { diff --git a/UnitTests/UnitTests.UWP/Providers/Test_WindowsProvider.cs b/UnitTests/UnitTests.UWP/Providers/Test_WindowsProvider.cs index 200c530..e0d6bb5 100644 --- a/UnitTests/UnitTests.UWP/Providers/Test_WindowsProvider.cs +++ b/UnitTests/UnitTests.UWP/Providers/Test_WindowsProvider.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Threading.Tasks; using CommunityToolkit.Authentication; using Microsoft.Toolkit.Uwp; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Threading.Tasks; namespace UnitTests.UWP.Authentication { diff --git a/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs b/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs index 432ec27..f2145be 100644 --- a/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs +++ b/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs @@ -2,15 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Linq; +using System.Threading.Tasks; using CommunityToolkit.Authentication; using CommunityToolkit.Graph.Helpers.RoamingSettings; using Microsoft.Toolkit.Helpers; using Microsoft.Toolkit.Uwp; using Microsoft.Toolkit.Uwp.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Linq; -using System.Threading.Tasks; namespace UnitTests.UWP.Helpers { @@ -77,7 +77,8 @@ async void test() Assert.AreEqual(fileContents2, readContents2); // Delete a file - await storageHelper.DeleteItemAsync(filePath); + var itemDeleted = await storageHelper.TryDeleteItemAsync(filePath); + Assert.IsTrue(itemDeleted); tcs.SetResult(true); } @@ -111,7 +112,7 @@ async void test() // Create a folder await storageHelper.CreateFolderAsync(folderName); - + // Create a subfolder await storageHelper.CreateFolderAsync(subfolderName, folderName); @@ -132,7 +133,8 @@ async void test() Assert.AreEqual(DirectoryItemType.File, folderItemsList[1].ItemType); // Delete a folder - await storageHelper.DeleteItemAsync(folderName); + var itemDeleted = await storageHelper.TryDeleteItemAsync(folderName); + Assert.IsTrue(itemDeleted); tcs.SetResult(true); } diff --git a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs index 7f9d070..019669a 100644 --- a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs +++ b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs @@ -2,14 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Threading.Tasks; using CommunityToolkit.Authentication; using CommunityToolkit.Graph.Helpers.RoamingSettings; using Microsoft.Toolkit.Extensions; using Microsoft.Toolkit.Helpers; using Microsoft.Toolkit.Uwp; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Threading.Tasks; namespace UnitTests.UWP.Helpers { diff --git a/UnitTests/UnitTests.UWP/VisualUITestBase.cs b/UnitTests/UnitTests.UWP/VisualUITestBase.cs index c4a0fa9..e4a5e07 100644 --- a/UnitTests/UnitTests.UWP/VisualUITestBase.cs +++ b/UnitTests/UnitTests.UWP/VisualUITestBase.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Threading.Tasks; using Microsoft.Toolkit.Uwp; using Microsoft.Toolkit.Uwp.UI.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Threading.Tasks; using Windows.UI.Xaml; namespace UnitTests.UWP