diff --git a/Binaries/SharePointPnP.Modernization.Framework.dll b/Binaries/SharePointPnP.Modernization.Framework.dll index 071348c1b..fc5f60f04 100644 Binary files a/Binaries/SharePointPnP.Modernization.Framework.dll and b/Binaries/SharePointPnP.Modernization.Framework.dll differ diff --git a/Binaries/release/SharePointPnP.Modernization.Framework.dll b/Binaries/release/SharePointPnP.Modernization.Framework.dll index a2a16bf55..afb5cfb0e 100644 Binary files a/Binaries/release/SharePointPnP.Modernization.Framework.dll and b/Binaries/release/SharePointPnP.Modernization.Framework.dll differ diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c3f1998..31ce022aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,42 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). -## [3.23.2007.0] (not yet released) +## [3.24.2008.0] + +## [3.23.2007.0] ### Added +- Added `-WithRightsAssignedDetailed` parameter to `Get-PnPUser` when used against SharePoint Online allowing for fine grained (broken) permissions on item, list and site level to be shown [PR #2754](https://github.com/pnp/PnP-PowerShell/pull/2754) +- Added a `-RowLimit` parameter to `Clear-PnPRecycleBinItem` and `Restore-PnPRecycleBinItem` so that it can be used on recycle bins which hold more than 5000 items [PR #2760](https://github.com/pnp/PnP-PowerShell/pull/2760) +- Added connection option to `Connect-PnPOnline` taking `-Scopes` and `-Credentials` to allow setting up a delegated permission token for use with Microsoft Graph and the Office 365 Management API. See [this wiki page](https://github.com/pnp/PnP-PowerShell/wiki/Connect-options#connect-using-scopes-and-credentials) for more details. [PR #2746](https://github.com/pnp/PnP-PowerShell/pull/2746) +- Added support for enabling and disabling fields using `Set-PnPField -Identity FieldName -Values @{AllowDeletion=$false}` [PR #2766](https://github.com/pnp/PnP-PowerShell/pull/2766) +- Added the following cmdlets to add/remove/clear owners and members of Microsoft 365 Groups: `Add-PnPMicrosoft365GroupMember`, `Add-PnPMicrosoft365GroupOwner`, `Remove-PnPMicrosoft365GroupMember`, `Remove-PnPMicrosoft365GroupOwner`, `Clear-PnPMicrosoft365GroupMember`, `Clear-PnPMicrosoft365GroupOwner` [PR #2750](https://github.com/pnp/PnP-PowerShell/pull/2750) +- Added Add-PnPTeamsChannel, Add-PnPTeamsTab, Add-PnPTeamsUser, Get-PnPTeamsApp, Get-PnPTeamsChannel, Get-PnPTeamsChannelMessage, Get-PnPTeamsTab, Get-PnPTeamsTeam, Get-PnPTeamsUser, New-PnPTeamsApp, New-PnPTeamsTeam, Remove-PnPTeamsChannel, Remove-PnPTeamsTab, Remove-PnPTeamsTeam, Remove-PnPTeamsUser, Set-PnPTeamsChannel, Set-PnPTeamsTab, Set-PnPTeamsTeam, Set-PnPTeamsPicture, Submit-PnPTeamsChannelMessage, Update-PnPTeamsApp cmdlets +- Added Get-PnPFileVersion, Remove-PnPFileVersion, Restore-PnPFileVersion cmdlets +- Added `-HideFromAddressLists` and `-HideFromOutlookClients` to `Set-PnPUnifiedGroup` to allow for setting the visibility of Microsoft 365 Groups [PR #2717](https://github.com/pnp/PnP-PowerShell/pull/2717) ### Changed +- Updated implementation of `Move-PnPFile` to now also support moving of files and folders accross site collections [PR #2749](https://github.com/pnp/PnP-PowerShell/pull/2749) +- Fixed issue where using `Disconnect-PnPOnline -Connection $variable` after having connected using `$variable = Connect-PnPOnline -CertificatePath -ReturnConnection`, it would not clean up the certificate on that connection instance passed in by $variable, but instead try to do it on the current connection context [PR #2755](https://github.com/pnp/PnP-PowerShell/pull/2755) +- Fixed `Invoke-PnPSPRestMethod -Method Merge` not passing in the `If-Match: *` header and thereby causing failed requests [PR #2764](https://github.com/pnp/PnP-PowerShell/pull/2764) +- If a certain PnP PowerShell cmdlet needs access to the SharePoint Admin Center site in order to function correctly, it will now list this in the Synopsis section of the Get-Help for the cmdlet +- Fixed issue where using `Connect-PnPOnline` using `-Thumbnail` would delete the private key on some devices when running `Disconnect-PnPOnline` [PR #2759](https://github.com/pnp/PnP-PowerShell/pull/2759) +- Fixed timeouts on `Get-PnPSiteCollectionAdmin` when the site has a lot of users [PR #2769](https://github.com/pnp/PnP-PowerShell/pull/2769) +- Updated test project structure [PR #2767](https://github.com/pnp/PnP-PowerShell/pull/2767) +- Updated the Microsoft Authentication Library (MSAL) to 4.16.1 which resolves an [issue in the MSAL library](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/pull/1891) which caused many of the `Connect-PnPOnline` options not to work in Azure Runbooks anymore [PR #2735](https://github.com/pnp/PnP-PowerShell/pull/2735) +- All UnifiedGroup cmdlets have been renamed to Microsoft365Group. I.e. `New-PnPUnifiedGroup` -> `New-PnPMicrosoft365Group`. An alias has been added to provide for backwards compatibility [PR #2771](https://github.com/pnp/PnP-PowerShell/pull/2771) ### Contributors +- Erwin van Hunen [erwinvanhunen] +- Gautam Sheth [gautamdsheth] +- Koen Zomers [koenzomers] +- Maximilian L. [MrTantum] +- Ellie Hussey [Professr] +- Todd Klindt [ToddKlindt] +- Marc D Anderson [sympmarc] +- Jens Otto Hatlevold [jensotto] +- Robin Meure [robinmeure] +- Paul Bullock [pkbullock] ## [3.22.2006.2] @@ -67,6 +96,7 @@ Intermediate release due to a fix in the underlying Core Library. ### Contributors + ## [3.20.2004.0] ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7aa6ab034..fe6e2adb8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,6 @@ Please see following page for additional insights on the model. --- ## Building the source code ## - Once you have downloaded the code, in the folder with the PnP PowerShell source code, open the solution file SharePointPnP.PowerShell.sln. If you have set up the projects and you are ready to build the source code, make sure to build the SharePointPnP.PowerShellModuleFilesGenerator project first. This project will be executed after every build and it will generate the required PSD1 and XML files with cmdlet documentation in them. @@ -23,6 +22,9 @@ When you build the solution a postbuild script will copy the required files to a To debug the cmdlets: launch PowerShell and attach Visual Studio to the powershell.exe process. In case you want to debug methods in PnP Sites Core, make sure that you open the PnP Sites Core project instead, and then attach Visual Studio to the powershell.exe. In case you see strange debug behavior, like it wants to debug PSReadLine.ps1, uninstall the PowerShell extension from Visual Studio. +## Keeping your fork up to date +Before starting on any new submissions, please ensure your fork is up to date with the upstream repository. This avoids frustration and challenges for us to valdate and test your submission. Steps on how to easily keep your fork up to date can be found [on this wiki page](https://github.com/pnp/PnP-PowerShell/wiki/Update-your-fork-with-the-latest-code). + ## Code contributions In order to succesfully compile the PnP PowerShell solution you will _also_ have to download *and build in Visual Studio* the [PnP-Sites-Core](https://github.com/OfficeDev/PnP-Sites-Core) repository and make the dev branch available. The PowerShell solution depends on it. In order to succesfully compile it, make sure that PnP-Sites-Core is located at the same level as PnP-PowerShell and you open the solution file OfficeDevPnP.Core.sln located in the Core subfolder of the sourcecode. diff --git a/Commands/Admin/AddOffice365GroupToSite.cs b/Commands/Admin/AddMicrosoft365GroupToSite.cs similarity index 90% rename from Commands/Admin/AddOffice365GroupToSite.cs rename to Commands/Admin/AddMicrosoft365GroupToSite.cs index 197b086bc..619b37a1c 100644 --- a/Commands/Admin/AddOffice365GroupToSite.cs +++ b/Commands/Admin/AddMicrosoft365GroupToSite.cs @@ -9,15 +9,16 @@ namespace SharePointPnP.PowerShell.Commands.Admin { - [Cmdlet(VerbsCommon.Add, "PnPOffice365GroupToSite")] + [Cmdlet(VerbsCommon.Add, "PnPMicrosoft365GroupToSite")] [CmdletHelp("Groupifies a classic team site by creating a Microsoft 365 group for it and connecting the site with the newly created group", - DetailedDescription = "This command allows you to add a Microsoft 365 Unified group to an existing classic site collection.", + DetailedDescription = "This command allows you to add a Microsoft 365 Unified group to an existing classic site collection, also known as groupifying.", SupportedPlatform = CmdletSupportedPlatform.Online, Category = CmdletHelpCategory.TenantAdmin)] [CmdletExample( Code = @"PS:> Add-PnPOffice365GroupToSite -Url ""https://contoso.sharepoint.com/sites/FinanceTeamsite"" -Alias ""FinanceTeamsite"" -DisplayName = ""My finance team site group""", - Remarks = @"This will add a group called MyGroup to the current site collection", SortOrder = 1)] - public class AddOffice365GroupToSite: PnPAdminCmdlet + Remarks = @"This will groupify the FinanceTeamsite", SortOrder = 1)] + [Alias("Add-PnPOffice365GroupToSite")] + public class AddMicrosoft365GroupToSite: PnPAdminCmdlet { [Parameter(Mandatory = true, HelpMessage = @"Url of the site to be connected to an Microsoft 365 Group")] public string Url; @@ -43,7 +44,7 @@ public class AddOffice365GroupToSite: PnPAdminCmdlet [Parameter(Mandatory = false, HelpMessage = "If specified the site will be associated to the hubsite as identified by this id")] public GuidPipeBind HubSiteId; - [Parameter(Mandatory = false, HelpMessage = "The array UPN values of the group's owners.")] + [Parameter(Mandatory = false, HelpMessage = "The array UPN values of the group's owners")] public string[] Owners; protected override void ExecuteCmdlet() { diff --git a/Commands/Admin/AddSiteCollectionAppCatalog.cs b/Commands/Admin/AddSiteCollectionAppCatalog.cs index 1012224e5..230104d22 100644 --- a/Commands/Admin/AddSiteCollectionAppCatalog.cs +++ b/Commands/Admin/AddSiteCollectionAppCatalog.cs @@ -4,9 +4,7 @@ using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base; using System.Management.Automation; -using OfficeDevPnP.Core.Sites; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; -using System; namespace SharePointPnP.PowerShell.Commands.Admin { @@ -17,7 +15,8 @@ namespace SharePointPnP.PowerShell.Commands.Admin [CmdletExample( Code = @"PS:> Add-PnPSiteCollectionAppCatalog -Site ""https://contoso.sharepoint.com/sites/FinanceTeamsite""", Remarks = @"This will add a SiteCollection app catalog to the specified site", SortOrder = 1)] - public class AddSiteCollectionAppCatalog: PnPAdminCmdlet + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/sharepoint/dev/general-development/site-collection-app-catalog#configure-and-manage-site-collection-app-catalogs")] + public class AddSiteCollectionAppCatalog : PnPAdminCmdlet { [Parameter(Mandatory = true, HelpMessage = @"Url of the site to add the app catalog to.")] public SitePipeBind Site; diff --git a/Commands/Base/ConnectOnline.cs b/Commands/Base/ConnectOnline.cs index cd7b56781..aba9193e2 100644 --- a/Commands/Base/ConnectOnline.cs +++ b/Commands/Base/ConnectOnline.cs @@ -18,9 +18,10 @@ #endif using SharePointPnP.PowerShell.Commands.Model; using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; +using System.Collections.Generic; #if !NETSTANDARD2_1 using System.Security.Cryptography; -#endif +#endif using System.Reflection; #if !ONPREMISES #endif @@ -85,11 +86,11 @@ namespace SharePointPnP.PowerShell.Commands.Base #endif #if !ONPREMISES [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPO365ManagementShell", + Code = @"PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPManagementShell", Remarks = @"This will authenticate you using the PnP O365 Management Shell Multi-Tenant application. A browser window will have to be opened where you have to enter a code that is shown in your PowerShell window.", SortOrder = 12)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPO365ManagementShell -LaunchBrowser", + Code = @"PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPManagementShell -LaunchBrowser", Remarks = @"This will authenticate you using the PnP O365 Management Shell Multi-Tenant application. A browser window will automatically open and the code you need to enter will be automatically copied to your clipboard.", SortOrder = 13)] #endif @@ -100,34 +101,36 @@ namespace SharePointPnP.PowerShell.Commands.Base SortOrder = 14)] #endif #if !ONPREMISES -#if !NETSTANDARD2_1 [CmdletExample( Code = "PS:> Connect-PnPOnline -Scopes \"Mail.Read\",\"Files.Read\",\"ActivityFeed.Read\"", - Remarks = "Connects to Azure Active Directory interactively and gets an OAuth 2.0 Access Token to consume the resources of the declared permission scopes. It will utilize the Azure Active Directory enterprise application named PnP.PowerShell with application id bb0c5778-9d5c-41ea-a4a8-8cd417b3ab71 registered by the PnP PowerShell team. If you want to connect using your own Azure Active Directory application registration, use one of the Connect-PnPOnline cmdlets using a -ClientId attribute instead and pre-assign the required permissions/scopes/roles in your application registration in Azure Active Directory. The available permission scopes for Microsoft Graph are defined at the following URL: https://docs.microsoft.com/graph/permissions-reference . If the requested scope(s) have been used with this connect cmdlet before, they will not be asked for consent again. You can request scopes from different APIs in one Connect, i.e. from Microsoft Graph and the Microsoft Office Management API. It will ask you to authenticate for each of the APIs you have listed scopes for.", + Remarks = "Connects to Azure Active Directory interactively and gets an OAuth 2.0 Access Token to consume the resources of the declared permission scopes. It will utilize the Azure Active Directory enterprise application named PnP Management Shell with application id 31359c7f-bd7e-475c-86db-fdb8c937548e registered by the PnP team. If you want to connect using your own Azure Active Directory application registration, use one of the Connect-PnPOnline cmdlets using a -ClientId attribute instead and pre-assign the required permissions/scopes/roles in your application registration in Azure Active Directory. The available permission scopes for Microsoft Graph are defined at the following URL: https://docs.microsoft.com/graph/permissions-reference . If the requested scope(s) have been used with this connect cmdlet before, they will not be asked for consent again. You can request scopes from different APIs in one Connect, i.e. from Microsoft Graph and the Microsoft Office Management API. It will ask you to authenticate for each of the APIs you have listed scopes for.", SortOrder = 15)] -#endif + [CmdletExample( + Code = "PS:> Connect-PnPOnline -Scopes \"Mail.Read\",\"Files.Read\",\"ActivityFeed.Read\" -Credentials (New-Object System.Management.Automation.PSCredential (\"johndoe@contoso.onmicrosoft.com\", (ConvertTo-SecureString \"password\" -AsPlainText -Force)))", + Remarks = "Connects to Azure Active Directory using delegated permissions and gets an OAuth 2.0 Access Token to consume the resources of the declared permission scopes. It will utilize the Azure Active Directory enterprise application named PnP Management Shell with application id 31359c7f-bd7e-475c-86db-fdb8c937548e registered by the PnP team. If you want to connect using your own Azure Active Directory application registration, use one of the Connect-PnPOnline cmdlets using a -ClientId attribute instead and pre-assign the required permissions/scopes/roles in your application registration in Azure Active Directory. The available permission scopes for Microsoft Graph are defined at the following URL: https://docs.microsoft.com/graph/permissions-reference . If the requested scope(s) have been used with this connect cmdlet before, they will not be asked for consent again. You can request scopes from different APIs in one Connect, i.e. from Microsoft Graph and the Microsoft Office Management API. You must have logged on interactively with the same scopes at least once without using -Credentials to allow for the permission grant dialog to show and allow constent for the user account you would like to use. You can provide this consent by logging in once with Connect-PnPOnline -Url -PnPManagementShell -LaunchBrowser, and provide consent. This is a one-time action. From that moment on you will be able to use the cmdlet as stated here.", + SortOrder = 16)] #endif #if !ONPREMISES [CmdletExample( Code = "PS:> Connect-PnPOnline -ClientId '' -ClientSecret '' -AADDomain 'contoso.onmicrosoft.com'", Remarks = "Connects to the Microsoft Graph API using application permissions via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/Graph.ConnectUsingAppPermissions for a sample on how to get started.", - SortOrder = 16)] + SortOrder = 17)] [CmdletExample( Code = "PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -ClientId '' -Tenant 'contoso.onmicrosoft.com' -CertificatePath c:\\absolute-path\\to\\pnp.pfx -CertificatePassword ", Remarks = "Connects to SharePoint using app-only tokens via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/SharePoint.ConnectUsingAppPermissions for a sample on how to get started.", - SortOrder = 17)] + SortOrder = 18)] [CmdletExample( Code = "PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -ClientId '' -Tenant 'contoso.onmicrosoft.com' -Thumbprint 34CFAA860E5FB8C44335A38A097C1E41EEA206AA", - Remarks = "Connects to SharePoint using app-only tokens via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/SharePoint.ConnectUsingAppPermissions for a sample on how to get started.", - SortOrder = 18)] + Remarks = "Connects to SharePoint using app-only tokens via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/SharePoint.ConnectUsingAppPermissions for a sample on how to get started. Ensure you have imported the private key certificate, typically the .pfx file, into the Windows Certificate Store for the certificate with the provided thumbprint.", + SortOrder = 19)] [CmdletExample( Code = "PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -ClientId '' -Tenant 'contoso.onmicrosoft.com' -PEMCertificate -PEMPrivateKey -CertificatePassword ", Remarks = "Connects to SharePoint using app-only tokens via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/SharePoint.ConnectUsingAppPermissions for a sample on how to get started.", - SortOrder = 19)] + SortOrder = 20)] [CmdletExample( Code = "PS:> Connect-PnPOnline -Url https://contoso.sharepoint.com -ClientId '' -Tenant 'contoso.onmicrosoft.com' -Certificate ", Remarks = "Connects to SharePoint using app-only auth in combination with a certificate. See https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread#using-this-principal-in-your-powershell-script-using-the-pnp-sites-core-library for a sample on how to get started.", - SortOrder = 20)] + SortOrder = 21)] #endif #if ONPREMISES [CmdletExample( @@ -173,13 +176,10 @@ public class ConnectOnline : BasePSCmdlet private const string ParameterSet_SPOMANAGEMENT = "SPO Management Shell Credentials"; private const string ParameterSet_DEVICELOGIN = "PnP O365 Management Shell / DeviceLogin"; private const string ParameterSet_GRAPHDEVICELOGIN = "PnP Office 365 Management Shell to the Microsoft Graph"; -#if !NETSTANDARD2_1 - private const string ParameterSet_GRAPHWITHSCOPE = "Microsoft Graph using Scopes"; -#endif + private const string ParameterSet_AADWITHSCOPE = "Azure Active Directory using Scopes"; private const string ParameterSet_GRAPHWITHAAD = "Microsoft Graph using Azure Active Directory"; private const string SPOManagementClientId = "9bc3ab49-b65d-410a-85ad-de819febfddc"; private const string SPOManagementRedirectUri = "https://oauth.spops.microsoft.com/"; - private const string MSALPnPPowerShellClientId = "bb0c5778-9d5c-41ea-a4a8-8cd417b3ab71"; private const string GraphRedirectUri = "urn:ietf:wg:oauth:2.0:oob"; private const string ParameterSet_ACCESSTOKEN = "Access Token"; private static readonly Uri GraphAADLogin = new Uri("https://login.microsoftonline.com/"); @@ -239,6 +239,10 @@ public class ConnectOnline : BasePSCmdlet [Parameter(Mandatory = false, ParameterSetName = ParameterSet_MAIN, HelpMessage = "Credentials of the user to connect with. Either specify a PSCredential object or a string. In case of a string value a lookup will be done to the Generic Credentials section of the Windows Credentials in the Windows Credential Manager for the correct credentials.")] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_ADFSCREDENTIALS, HelpMessage = "Credentials of the user to connect with. Either specify a PSCredential object or a string. In case of a string value a lookup will be done to the Generic Credentials section of the Windows Credentials in the Windows Credential Manager for the correct credentials.")] +#if !ONPREMISES + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_AADWITHSCOPE, HelpMessage = "Credentials of the user to connect with. Either specify a PSCredential object or a string. In case of a string value a lookup will be done to the Generic Credentials section of the Windows Credentials in the Windows " + + "Credential Manager for the correct credentials.")] +#endif public CredentialPipeBind Credentials; [Parameter(Mandatory = false, ParameterSetName = ParameterSet_MAIN, HelpMessage = "If you want to connect with the current user credentials")] @@ -440,7 +444,8 @@ public class ConnectOnline : BasePSCmdlet * Read and write directory data * Read and write identity providers * Access the directory as you")] - public SwitchParameter PnPO365ManagementShell; + [Alias("PnPO365ManagementShell")] + public SwitchParameter PnPManagementShell; [Parameter(Mandatory = false, ParameterSetName = ParameterSet_DEVICELOGIN, HelpMessage = "Launch a browser automatically and copy the code to enter to the clipboard")] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_GRAPHDEVICELOGIN, HelpMessage = "Launch a browser automatically and copy the code to enter to the clipboard")] @@ -502,7 +507,7 @@ public class ConnectOnline : BasePSCmdlet [Parameter(Mandatory = true, ParameterSetName = ParameterSet_APPONLYAADPEM, HelpMessage = "PEM encoded private key for the certificate")] public string PEMPrivateKey; - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_APPONLYAADThumb, HelpMessage = "Certificate thumbprint")] + [Parameter(Mandatory = true, ParameterSetName = ParameterSet_APPONLYAADThumb, HelpMessage = "The thumbprint of the certificate containing the private key registered with the application in Azure Active Directory")] public string Thumbprint; [Parameter(Mandatory = false, ParameterSetName = ParameterSet_NATIVEAAD, HelpMessage = "Clears the token cache.")] @@ -518,10 +523,8 @@ public class ConnectOnline : BasePSCmdlet [Parameter(Mandatory = false, ParameterSetName = ParameterSet_APPONLYCLIENTIDCLIENTSECRETURL, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")] public AzureEnvironment AzureEnvironment = AzureEnvironment.Production; -#if !NETSTANDARD2_1 - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_GRAPHWITHSCOPE, HelpMessage = "The array of permission scopes for the Microsoft Graph API.")] + [Parameter(Mandatory = true, ParameterSetName = ParameterSet_AADWITHSCOPE, HelpMessage = "The array of permission scopes to request from Azure Active Directory")] public string[] Scopes; -#endif [Parameter(Mandatory = true, ParameterSetName = ParameterSet_GRAPHWITHAAD, HelpMessage = "The AAD where the O365 app is registered. Eg.: contoso.com, or contoso.onmicrosoft.com.")] [Parameter(Mandatory = true, ParameterSetName = ParameterSet_APPONLYCLIENTIDCLIENTSECRETAADDOMAIN, HelpMessage = "The AAD where the O365 app is registered. Eg.: contoso.com, or contoso.onmicrosoft.com.")] @@ -585,7 +588,7 @@ public class ConnectOnline : BasePSCmdlet [Parameter(Mandatory = false, ParameterSetName = ParameterSet_APPONLYAADCER, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting to a SharePoint farm using self signed certificates or using a certificate authority not trusted by this machine.")] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_GRAPHWITHAAD, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting through a proxy to the Microsoft Graph API which has SSL interception enabled.")] #if !NETSTANDARD2_1 - [Parameter(Mandatory = false, ParameterSetName = ParameterSet_GRAPHWITHSCOPE, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting through a proxy to the Microsoft Graph API which has SSL interception enabled.")] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_AADWITHSCOPE, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting through a proxy to the Microsoft Graph API which has SSL interception enabled.")] #endif [Parameter(Mandatory = false, ParameterSetName = ParameterSet_GRAPHDEVICELOGIN, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting through a proxy to the Microsoft Graph API which has SSL interception enabled.")] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPOMANAGEMENT, HelpMessage = "Ignores any SSL errors. To be used i.e. when connecting to a SharePoint farm using self signed certificates or using a certificate authority not trusted by this machine.")] @@ -656,6 +659,8 @@ protected void Connect() credentials = Credentials.Credential; } + WriteVerbose($"Using parameter set '{ParameterSetName}'"); + // Connect using the used set parameters switch (ParameterSetName) { @@ -696,11 +701,9 @@ protected void Connect() connection = ConnectAppOnlyAadCer(); break; -#if !NETSTANDARD2_1 - case ParameterSet_GRAPHWITHSCOPE: - connection = ConnectGraphWithScope(); + case ParameterSet_AADWITHSCOPE: + connection = ConnectAadWithScope(credentials); break; -#endif case ParameterSet_ACCESSTOKEN: connection = ConnectAccessToken(); break; @@ -786,7 +789,7 @@ protected void Connect() } } -#region Connect Types + #region Connect Types /// /// Connect using the paramater set TOKEN @@ -1074,7 +1077,7 @@ private PnPConnection ConnectAppOnlyAadCer() #if !NETSTANDARD2_1 return PnPConnectionHelper.InitiateAzureADAppOnlyConnection(new Uri(Url), ClientId, Tenant, Certificate, MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, TenantAdminUrl, Host, NoTelemetry, SkipTenantAdminCheck, AzureEnvironment); #else - throw new NotImplementedException(); + throw new NotImplementedException(); #endif #else return null; @@ -1082,13 +1085,13 @@ private PnPConnection ConnectAppOnlyAadCer() } /// - /// Connect using the parameter set GRAPHWITHSCOPE + /// Connect using the parameter set AADWITHSCOPE /// + /// Credentials to authenticate with for delegated access or NULL for application permissions /// PnPConnection based on the parameters provided in the parameter set - private PnPConnection ConnectGraphWithScope() + private PnPConnection ConnectAadWithScope(PSCredential credentials) { #if !ONPREMISES -#if !NETSTANDARD2_1 // Filter out the scopes for the Microsoft Office 365 Management API var officeManagementApiScopes = Enum.GetNames(typeof(OfficeManagementApiPermission)).Select(s => s.Replace("_", ".")).Intersect(Scopes).ToArray(); @@ -1100,29 +1103,27 @@ private PnPConnection ConnectGraphWithScope() // If we have Office 365 scopes, get a token for those first if (officeManagementApiScopes.Length > 0) { - var officeManagementApiToken = OfficeManagementApiToken.AcquireTokenInteractive(MSALPnPPowerShellClientId, officeManagementApiScopes); - connection = PnPConnection.GetConnectionWithToken(officeManagementApiToken, TokenAudience.OfficeManagementApi, Host, InitializationType.InteractiveLogin, disableTelemetry: NoTelemetry.ToBool()); + var officeManagementApiToken = credentials == null ? OfficeManagementApiToken.AcquireApplicationTokenInteractive(PnPConnection.DeviceLoginClientId, officeManagementApiScopes) : OfficeManagementApiToken.AcquireDelegatedTokenWithCredentials(PnPConnection.DeviceLoginClientId, graphScopes, credentials.UserName, credentials.Password); + connection = PnPConnection.GetConnectionWithToken(officeManagementApiToken, TokenAudience.OfficeManagementApi, Host, InitializationType.InteractiveLogin, credentials, disableTelemetry: NoTelemetry.ToBool()); } // If we have Graph scopes, get a token for it if (graphScopes.Length > 0) { - var graphToken = GraphToken.AcquireTokenInteractive(MSALPnPPowerShellClientId, graphScopes); + var graphToken = credentials == null ? GraphToken.AcquireApplicationTokenInteractive(PnPConnection.DeviceLoginClientId, graphScopes) : GraphToken.AcquireDelegatedTokenWithCredentials(PnPConnection.DeviceLoginClientId, graphScopes, credentials.UserName, credentials.Password); - // If there's a connection already, add the Graph token to it, otherwise set up a new connection with it + // If there's a connection already, add the AAD token to it, otherwise set up a new connection with it if (connection != null) { - connection.AddToken(TokenAudience.MicrosoftGraph, graphToken); + //connection.AddToken(TokenAudience.MicrosoftGraph, graphToken); } else { - connection = PnPConnection.GetConnectionWithToken(graphToken, TokenAudience.MicrosoftGraph, Host, InitializationType.InteractiveLogin, disableTelemetry: NoTelemetry.ToBool()); + connection = PnPConnection.GetConnectionWithToken(graphToken, TokenAudience.MicrosoftGraph, Host, InitializationType.InteractiveLogin, credentials, disableTelemetry: NoTelemetry.ToBool()); } + connection.Scopes = graphScopes; } return connection; -#else - throw new NotImplementedException(); -#endif #else return null; #endif @@ -1143,13 +1144,13 @@ private PnPConnection ConnectAccessToken() switch (url.ToLower()) { case GraphToken.ResourceIdentifier: - return PnPConnection.GetConnectionWithToken(new GraphToken(AccessToken), TokenAudience.MicrosoftGraph, Host, InitializationType.Token, disableTelemetry: NoTelemetry.ToBool()); + return PnPConnection.GetConnectionWithToken(new GraphToken(AccessToken), TokenAudience.MicrosoftGraph, Host, InitializationType.Token, null, disableTelemetry: NoTelemetry.ToBool()); case OfficeManagementApiToken.ResourceIdentifier: - return PnPConnection.GetConnectionWithToken(new OfficeManagementApiToken(AccessToken), TokenAudience.OfficeManagementApi, Host, InitializationType.Token, disableTelemetry: NoTelemetry.ToBool()); + return PnPConnection.GetConnectionWithToken(new OfficeManagementApiToken(AccessToken), TokenAudience.OfficeManagementApi, Host, InitializationType.Token, null, disableTelemetry: NoTelemetry.ToBool()); default: - return PnPConnection.GetConnectionWithToken(new SharePointToken(AccessToken), TokenAudience.SharePointOnline, Host, InitializationType.Token, Url, disableTelemetry: NoTelemetry.ToBool()); + return PnPConnection.GetConnectionWithToken(new SharePointToken(AccessToken), TokenAudience.SharePointOnline, Host, InitializationType.Token, null, Url, disableTelemetry: NoTelemetry.ToBool()); } #else return null; @@ -1242,7 +1243,7 @@ private PnPConnection ConnectAdfsCredentials(PSCredential credentials) SkipTenantAdminCheck, LoginProviderName); #else - throw new NotImplementedException(); + throw new NotImplementedException(); #endif } @@ -1354,9 +1355,9 @@ private PnPConnection ConnectCredentials(PSCredential credentials) #endif } -#endregion + #endregion -#region Helper methods + #region Helper methods private PSCredential GetCredentials() { var connectionUri = new Uri(Url); @@ -1429,6 +1430,6 @@ private void WriteUpdateMessage(string message) WriteWarning(message); } } -#endregion + #endregion } } diff --git a/Commands/Base/DisconnectOnline.cs b/Commands/Base/DisconnectOnline.cs index 75e000612..c48e41837 100644 --- a/Commands/Base/DisconnectOnline.cs +++ b/Commands/Base/DisconnectOnline.cs @@ -4,12 +4,14 @@ using System.Management.Automation; using System.Reflection; using SharePointPnP.PowerShell.Commands.Provider; +using SharePointPnP.PowerShell.Commands.Model; namespace SharePointPnP.PowerShell.Commands.Base { [Cmdlet(VerbsCommunications.Disconnect, "PnPOnline")] [CmdletHelp("Disconnects the context", - "Disconnects the current context and requires you to build up a new connection in order to use the Cmdlets again. Using Connect-PnPOnline to connect to a different site has the same effect.", + DetailedDescription = "Disconnects the current context and requires you to build up a new connection in order to use the Cmdlets again. Using Connect-PnPOnline to connect to a different site has the same effect.", + SupportedPlatform = CmdletSupportedPlatform.All, Category = CmdletHelpCategory.Base)] [CmdletExample( Code = @"PS:> Disconnect-PnPOnline", @@ -22,16 +24,24 @@ public class DisconnectOnline : PSCmdlet protected override void ProcessRecord() { + // If no specific connection has been passed in, take the connection from the current context + if(Connection == null) + { + Connection = PnPConnection.CurrentConnection; + } #if !ONPREMISES - if(PnPConnection.CurrentConnection?.Certificate != null) + if(Connection?.Certificate != null) { #if !NETSTANDARD2_1 - PnPConnectionHelper.CleanupCryptoMachineKey(PnPConnection.CurrentConnection.Certificate); + if (Connection != null && Connection.DeleteCertificateFromCacheOnDisconnect) + { + PnPConnectionHelper.CleanupCryptoMachineKey(Connection.Certificate); + } #endif - PnPConnection.CurrentConnection.Certificate = null; + Connection.Certificate = null; } #endif - var success = false; + var success = false; if (Connection != null) { success = DisconnectProvidedService(Connection); @@ -63,14 +73,14 @@ protected override void ProcessRecord() internal static bool DisconnectProvidedService(PnPConnection connection) { - connection.ClearTokens(); + //connection.ClearTokens(); Environment.SetEnvironmentVariable("PNPPSHOST", string.Empty); Environment.SetEnvironmentVariable("PNPPSSITE", string.Empty); if (connection == null) { return false; } - + GraphToken.ClearCaches(); connection.Context = null; connection = null; return true; @@ -90,6 +100,8 @@ internal static bool DisconnectCurrentService() PnPConnection.CurrentConnection.ClearTokens(); PnPConnection.CurrentConnection.Context = null; PnPConnection.CurrentConnection = null; + + return true; } } diff --git a/Commands/Base/InitializePowerShellAuthentication.cs b/Commands/Base/InitializePowerShellAuthentication.cs index 8ac256a4c..4620a6ca6 100644 --- a/Commands/Base/InitializePowerShellAuthentication.cs +++ b/Commands/Base/InitializePowerShellAuthentication.cs @@ -9,8 +9,11 @@ using System.IO; using System.Linq; using System.Management.Automation; +using System.Management.Automation.Host; using System.Security; +using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; namespace SharePointPnP.PowerShell.Commands.Base { @@ -23,9 +26,22 @@ namespace SharePointPnP.PowerShell.Commands.Base [CmdletAdditionalParameter(ParameterType = typeof(string[]), ParameterName = "Scopes", HelpMessage = "Specify which permissions scopes to request.", ParameterSetName = ParameterSet_EXISTINGCERT)] [CmdletExample( - Code = @"PS:> Initialize-PnPPowerShellAuthentication -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -StoreLocation CurrentUser", + Code = @"PS:> Initialize-PnPPowerShellAuthentication -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -Store CurrentUser", Remarks = "Creates a new Azure AD Application registration, creates a new self signed certificate, and adds it to the local certificate store. It will upload the certificate to the azure app registration and it will request the following permissions: Sites.FullControl.All, Group.ReadWrite.All, User.Read.All", SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Initialize-PnPPowerShellAuthentication -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -CertificatePath c:\certificate.pfx -CertificatePassword (ConvertTo-SecureString -String ""password"" -AsPlainText -Force)", + Remarks = "Creates a new Azure AD Application registration which will use the existing private key certificate at the provided path to allow access. It will upload the provided private key certificate to the azure app registration and it will request the following permissions: Sites.FullControl.All, Group.ReadWrite.All, User.Read.All", + SortOrder = 2)] + [CmdletExample( + Code = @"PS:> Initialize-PnPPowerShellAuthentication -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -Store CurrentUser -Scopes ""MSGraph.User.Read.All"",""SPO.Sites.Read.All""", + Remarks = "Creates a new Azure AD Application registration, creates a new self signed certificate, and adds it to the local certificate store. It will upload the certificate to the azure app registration and it will request the following permissions: Sites.Read.All, User.Read.All", + SortOrder = 3)] + [CmdletExample( + Code = @"PS:> Initialize-PnPPowerShellAuthentication -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -OutPath c:\ -CertificatePassword (ConvertTo-SecureString -String ""password"" -AsPlainText -Force)", + Remarks = @"Creates a new Azure AD Application registration, creates a new self signed certificate, and stores the public and private key certificates in c:\. The private key certificate will be locked with the password ""password"". It will upload the certificate to the azure app registration and it will request the following permissions: Sites.FullControl.All, Group.ReadWrite.All, User.Read.All", + SortOrder = 4)] + public class InitializePowerShellAuthentication : BasePSCmdlet, IDynamicParameters { private const string ParameterSet_EXISTINGCERT = "Existing Certificate"; @@ -79,13 +95,39 @@ protected override void ProcessRecord() var cert = new X509Certificate2(); if (ParameterSetName == ParameterSet_EXISTINGCERT) { + // Ensure a file exists at the provided CertificatePath + if (!File.Exists(CertificatePath)) + { + throw new PSArgumentException(string.Format(Resources.CertificateNotFoundAtPath, CertificatePath), nameof(CertificatePath)); + } + if (ParameterSpecified(nameof(CertificatePassword))) { - cert.Import(CertificatePath, CertificatePassword, X509KeyStorageFlags.Exportable); + try + { + cert.Import(CertificatePath, CertificatePassword, X509KeyStorageFlags.Exportable); + } + catch (CryptographicException e) when (e.Message.Contains("The specified network password is not correct")) + { + throw new PSArgumentNullException(nameof(CertificatePassword), string.Format(Resources.PrivateKeyCertificateImportFailedPasswordIncorrect, nameof(CertificatePassword))); + } } else { - cert.Import(CertificatePath); + try + { + cert.Import(CertificatePath); + } + catch(CryptographicException e) when (e.Message.Contains("The specified network password is not correct")) + { + throw new PSArgumentNullException(nameof(CertificatePassword), string.Format(Resources.PrivateKeyCertificateImportFailedPasswordMissing, nameof(CertificatePassword))); + } + } + + // Ensure the certificate at the provided CertificatePath holds a private key + if (!cert.HasPrivateKey) + { + throw new PSArgumentException(string.Format(Resources.CertificateAtPathHasNoPrivateKey, CertificatePath), nameof(CertificatePath)); } } else @@ -197,20 +239,36 @@ protected override void ProcessRecord() var waitTime = 60; Host.UI.Write(ConsoleColor.Yellow, Host.UI.RawUI.BackgroundColor, $"Waiting {waitTime} seconds to launch consent flow in a browser window. This wait is required to make sure that Azure AD is able to initialize all required artifacts."); + + Console.TreatControlCAsInput = true; + for (var i = 0; i < waitTime; i++) { Host.UI.Write(ConsoleColor.Yellow, Host.UI.RawUI.BackgroundColor, "."); System.Threading.Thread.Sleep(1000); + + // Check if CTRL+C has been pressed and if so, abort the wait + if (Host.UI.RawUI.KeyAvailable) + { + var key = Host.UI.RawUI.ReadKey(ReadKeyOptions.AllowCtrlC | ReadKeyOptions.NoEcho | ReadKeyOptions.IncludeKeyUp); + if((key.ControlKeyState.HasFlag(ControlKeyStates.LeftCtrlPressed) || key.ControlKeyState.HasFlag(ControlKeyStates.RightCtrlPressed)) && key.VirtualKeyCode == 67) + { + + break; + } + } } Host.UI.WriteLine(); + var consentUrl = $"https://login.microsoftonline.com/{Tenant}/v2.0/adminconsent?client_id={azureApp.AppId}&scope=https://microsoft.sharepoint-df.com/.default"; record.Properties.Add(new PSVariableProperty(new PSVariable("Certificate Thumbprint", cert.GetCertHashString()))); + WriteObject(record); + AzureAuthHelper.OpenConsentFlow(consentUrl, (message) => { Host.UI.WriteLine(ConsoleColor.Red, Host.UI.RawUI.BackgroundColor, message); - }); - WriteObject(record); + }); } } diff --git a/Commands/Base/InvokeSPRestMethod.cs b/Commands/Base/InvokeSPRestMethod.cs index 06ce08c1a..dc6e0f0f2 100644 --- a/Commands/Base/InvokeSPRestMethod.cs +++ b/Commands/Base/InvokeSPRestMethod.cs @@ -49,18 +49,17 @@ public class InvokeSPRestMethod : PnPSharePointCmdlet [Parameter(Mandatory = false, Position = 0, HelpMessage = "The Http method to execute. Defaults to GET.")] public HttpRequestMethod Method = HttpRequestMethod.Get; - [Parameter(Mandatory = true, Position = 0, HelpMessage = "The url to execute.")] + [Parameter(Mandatory = true, Position = 0, HelpMessage = "The url to execute")] public string Url; [Parameter(Mandatory = false, HelpMessage = "A string or object to send")] public object Content; - [Parameter(Mandatory = false, HelpMessage = "The content type of the object to send. Defaults to 'application/json'")] + [Parameter(Mandatory = false, HelpMessage = "The content type of the object to send. Defaults to 'application/json'.")] public string ContentType = "application/json"; protected override void ExecuteCmdlet() { - if (Url.StartsWith("/")) { // prefix the url with the current web url @@ -70,16 +69,14 @@ protected override void ExecuteCmdlet() var accessToken = this.ClientContext.GetAccessToken(); var method = new HttpMethod(Method.ToString()); - //var method = new HttpMethod(Method.ToString().ToUpper()); - using (var handler = new System.Net.Http.HttpClientHandler()) + using (var handler = new HttpClientHandler()) { // we're not in app-only or user + app context, so let's fall back to cookie based auth - if (String.IsNullOrEmpty(accessToken)) + if (string.IsNullOrEmpty(accessToken)) { SetAuthenticationCookies(handler, ClientContext); } - using (var httpClient = new PnPHttpProvider(handler)) { var requestUrl = Url; @@ -94,9 +91,14 @@ protected override void ExecuteCmdlet() request.Headers.Add("X-HTTP-Method", "MERGE"); } + if (Method == HttpRequestMethod.Merge || Method == HttpRequestMethod.Delete) + { + request.Headers.Add("IF-MATCH", "*"); + } + if (!string.IsNullOrEmpty(accessToken)) { - request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); } else { @@ -105,7 +107,7 @@ protected override void ExecuteCmdlet() handler.Credentials = networkCredential; } } - request.Headers.Add("X-RequestDigest", (ClientContext as ClientContext).GetRequestDigest().GetAwaiter().GetResult()); + request.Headers.Add("X-RequestDigest", ClientContext.GetRequestDigest().GetAwaiter().GetResult()); if (Method == HttpRequestMethod.Post) { @@ -140,7 +142,6 @@ protected override void ExecuteCmdlet() } } } - } private void SetAuthenticationCookies(HttpClientHandler handler, ClientContext context) @@ -175,7 +176,6 @@ private void SetAuthenticationCookies(HttpClientHandler handler, ClientContext c } } - //Taken from "Remote Authentication in SharePoint Online Using the Client Object Model" //https://code.msdn.microsoft.com/Remote-Authentication-in-b7b6f43c @@ -202,7 +202,6 @@ internal static class CookieReader /// Returns Cookie contents as a string public static string GetCookie(string url) { - int size = 512; StringBuilder sb = new StringBuilder(size); if (!NativeMethods.InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero)) @@ -222,7 +221,6 @@ public static string GetCookie(string url) private static class NativeMethods { - [DllImport("wininet.dll", EntryPoint = "InternetGetCookieEx", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool InternetGetCookieEx( string url, diff --git a/Commands/Base/PipeBinds/FileVersionPipeBind.cs b/Commands/Base/PipeBinds/FileVersionPipeBind.cs new file mode 100644 index 000000000..aa8a5e4eb --- /dev/null +++ b/Commands/Base/PipeBinds/FileVersionPipeBind.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds +{ + public class FileVersionPipeBind + { + + private int _id = -1; + private string _label; + + + public FileVersionPipeBind(string label) + { + if (int.TryParse(label, out int id)) + { + _id = id; + } + else + { + _label = label; + } + } + + public FileVersionPipeBind(int id) + { + _id = id; + } + + public int Id => _id; + public string Label => _label; + } +} diff --git a/Commands/Base/PipeBinds/UnifiedGroupPipeBind.cs b/Commands/Base/PipeBinds/Microsoft365GroupPipeBind.cs similarity index 80% rename from Commands/Base/PipeBinds/UnifiedGroupPipeBind.cs rename to Commands/Base/PipeBinds/Microsoft365GroupPipeBind.cs index 6e9092f1b..a4aa9d021 100644 --- a/Commands/Base/PipeBinds/UnifiedGroupPipeBind.cs +++ b/Commands/Base/PipeBinds/Microsoft365GroupPipeBind.cs @@ -5,22 +5,22 @@ namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds { - public class UnifiedGroupPipeBind + public class Microsoft365GroupPipeBind { private readonly UnifiedGroupEntity _group; private readonly String _groupId; private readonly String _displayName; - public UnifiedGroupPipeBind() + public Microsoft365GroupPipeBind() { } - public UnifiedGroupPipeBind(UnifiedGroupEntity group) + public Microsoft365GroupPipeBind(UnifiedGroupEntity group) { _group = group; } - public UnifiedGroupPipeBind(String input) + public Microsoft365GroupPipeBind(String input) { Guid idValue; if (Guid.TryParse(input, out idValue)) @@ -52,10 +52,10 @@ public UnifiedGroupEntity GetGroup(string accessToken, bool includeClassificatio } else if (!string.IsNullOrEmpty(DisplayName)) { - var groups = UnifiedGroupsUtility.ListUnifiedGroups(accessToken, DisplayName, includeSite: true, includeClassification:includeClassification); + var groups = UnifiedGroupsUtility.GetUnifiedGroups(accessToken, DisplayName, includeSite: true, includeClassification:includeClassification); if (groups == null || groups.Count == 0) { - groups = UnifiedGroupsUtility.ListUnifiedGroups(accessToken, mailNickname: DisplayName, includeSite: true, includeClassification:includeClassification); + groups = UnifiedGroupsUtility.GetUnifiedGroups(accessToken, mailNickname: DisplayName, includeSite: true, includeClassification:includeClassification); } if (groups != null && groups.Any()) { diff --git a/Commands/Base/PipeBinds/TeamPipeBind.cs b/Commands/Base/PipeBinds/TeamPipeBind.cs deleted file mode 100644 index 07eaa9270..000000000 --- a/Commands/Base/PipeBinds/TeamPipeBind.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Microsoft.SharePoint.Client; -using OfficeDevPnP.Core.Framework.Provisioning.Model.Teams; -using System; - -namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds -{ - public sealed class TeamPipeBind - { - private Team team; - private string groupId; - - public TeamPipeBind(Guid id) - { - groupId = id.ToString(); - } - - public TeamPipeBind(string stringId) - { - if(Guid.TryParse(stringId, out Guid guidId)) - { - groupId = guidId.ToString(); - } else - { - throw new ArgumentException("ID is not in correct format, needs to be a GUID"); - } - } - - public TeamPipeBind(Team team) - { - this.team = team; - } - - internal string GetTeamId() - { - if (team != null) - { - return team.GroupId; - } - else - { - return groupId; - } - } - } -} diff --git a/Commands/Base/PipeBinds/TeamsAppPipeBind.cs b/Commands/Base/PipeBinds/TeamsAppPipeBind.cs new file mode 100644 index 000000000..731e50392 --- /dev/null +++ b/Commands/Base/PipeBinds/TeamsAppPipeBind.cs @@ -0,0 +1,77 @@ +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Linq; +using System.Management.Automation; +using System.Net.Http; + +namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds +{ + public sealed class TeamsAppPipeBind + { + private readonly Guid _id; + private readonly string _stringValue; + + public TeamsAppPipeBind() + + { + _id = Guid.Empty; + } + + public TeamsAppPipeBind(string input) + { + if (string.IsNullOrEmpty(input)) + { + throw new ArgumentException(nameof(input)); + } + if (Guid.TryParse(input, out Guid tabId)) + { + _id = tabId; + } + else + { + _stringValue = input; + } + } + + public Guid Id => _id; + + public string StringValue => _stringValue; + + public TeamApp GetApp(HttpClient httpClient, string accessToken) + { + if (Id != Guid.Empty) + { + var collection = GraphHelper.GetAsync>(httpClient, $"v1.0/appCatalogs/teamsApps?$filter=id eq '{_id}'", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Any()) + { + return collection.Items.First(); + } + else + { + collection = GraphHelper.GetAsync>(httpClient, $"v1.0/appCatalogs/teamsApps?$filter=externalId eq '{_id}'", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Any()) + { + return collection.Items.First(); + } + } + } + else + { + var collection = GraphHelper.GetAsync>(httpClient, $"v1.0/appCatalogs/teamsApps?$filter=displayName eq '{_stringValue}'", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Any()) + { + if (collection.Items.Count() == 1) + { + return collection.Items.First(); + } + else + { + throw new PSArgumentException("Multiple apps found with the same display name. Specify id instead to reference to the app."); + } + } + } + return null; + } + } +} diff --git a/Commands/Base/PipeBinds/TeamsChannelPipeBind.cs b/Commands/Base/PipeBinds/TeamsChannelPipeBind.cs new file mode 100644 index 000000000..0b36684e5 --- /dev/null +++ b/Commands/Base/PipeBinds/TeamsChannelPipeBind.cs @@ -0,0 +1,71 @@ +using Microsoft.Graph; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System; +using System.Linq; +using System.Net.Http; +using System.Threading; + +namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds +{ + public sealed class TeamsChannelPipeBind + { + private readonly string _id; + private readonly string _displayName; + public TeamsChannelPipeBind() + { + + } + + public TeamsChannelPipeBind(string input) + { + // check if it's a channel id + if (input.EndsWith("@tread.skype") && input.Substring(2, 1) == ":") + { + _id = input; + } + else + { + _displayName = input; + } + } + + public TeamsChannelPipeBind(Model.Teams.TeamChannel channel) + { + _id = channel.Id; + } + + + public string Id => _id; + + public string GetId(HttpClient httpClient, string accessToken, string groupId) + { + if (!string.IsNullOrEmpty(_id)) + { + return _id; + } + else + { + var channels = TeamsUtility.GetChannels(accessToken, httpClient, groupId); + return channels.FirstOrDefault(c => c.DisplayName.Equals(_displayName, StringComparison.OrdinalIgnoreCase)).Id; + } + } + + public TeamChannel GetChannel(HttpClient httpClient, string accessToken, string groupId) + { + var channels = TeamsUtility.GetChannels(accessToken, httpClient, groupId); + if(channels != null && channels.Any()) + { + if(!string.IsNullOrEmpty(_id)) + { + return channels.FirstOrDefault(c => c.Id.Equals(_id, StringComparison.OrdinalIgnoreCase)); + } else + { + return channels.FirstOrDefault(c => c.DisplayName.Equals(_displayName, StringComparison.OrdinalIgnoreCase)); + } + } + return null; + } + + } +} diff --git a/Commands/Base/PipeBinds/TeamsTabPipeBind.cs b/Commands/Base/PipeBinds/TeamsTabPipeBind.cs new file mode 100644 index 000000000..93d5f022a --- /dev/null +++ b/Commands/Base/PipeBinds/TeamsTabPipeBind.cs @@ -0,0 +1,65 @@ +using Microsoft.SharePoint.Client; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System; +using System.Linq; +using System.Management.Automation; +using System.Net; +using System.Net.Http; +using System.Web; + +namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds +{ + public sealed class TeamsTabPipeBind + { + private readonly string _id; + private readonly string _displayName; + + public TeamsTabPipeBind() + { + } + + public TeamsTabPipeBind(string input) + { + if (string.IsNullOrEmpty(input)) + { + throw new ArgumentException(nameof(input)); + } + if (Guid.TryParse(input, out Guid tabId)) + { + _id = input; + } + else + { + _displayName = input; + } + } + + public string Id => _id; + + public TeamTab GetTab(HttpClient httpClient, string accessToken, string groupId, string channelId) + { + // find the tab by the displayName + var tabs = TeamsUtility.GetTabs(accessToken, httpClient, groupId, channelId); + if (tabs != null) + { + var tab = tabs.FirstOrDefault(t => t.DisplayName.Equals(_displayName, System.StringComparison.OrdinalIgnoreCase)); + if (tab != null) + { + return tab; + } + else + { + throw new PSArgumentException("Cannot find tab"); + } + } + return null; + } + + public TeamTab GetTabById(HttpClient httpClient, string accessToken, string groupId, string channelId) + { + return TeamsUtility.GetTab(accessToken, httpClient, groupId, channelId, _id); + } + } +} + diff --git a/Commands/Base/PipeBinds/TeamsTeamPipeBind.cs b/Commands/Base/PipeBinds/TeamsTeamPipeBind.cs new file mode 100644 index 000000000..c62dacfde --- /dev/null +++ b/Commands/Base/PipeBinds/TeamsTeamPipeBind.cs @@ -0,0 +1,116 @@ +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Linq; +using System.Management.Automation; +using System.Net.Http; + +namespace SharePointPnP.PowerShell.Commands.Base.PipeBinds +{ + public sealed class TeamsTeamPipeBind + { + private readonly string _id; + private readonly string _stringValue; + + public TeamsTeamPipeBind() + + { + _id = string.Empty; + _stringValue = string.Empty; + } + + public TeamsTeamPipeBind(string input) + { + if (string.IsNullOrEmpty(input)) + { + throw new ArgumentException(nameof(input)); + } + if (Guid.TryParse(input, out Guid tabId)) + { + _id = input; + } + else + { + _stringValue = input; + } + } + + public TeamsTeamPipeBind(Team team) + { + _id = team.GroupId; + } + + public string GetGroupId(HttpClient httpClient, string accessToken) + { + if (!string.IsNullOrEmpty(_id)) + { + return _id.ToString(); + } + else + { + var collection = GraphHelper.GetAsync>(httpClient, $"beta/groups?$filter=(resourceProvisioningOptions/Any(x:x eq 'Team') and mailNickname eq '{_stringValue}')&$select=Id", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Any()) + { + return collection.Items.First().Id; + } + else + { + // find the team by displayName + var byDisplayNamecollection = GraphHelper.GetAsync>(httpClient, $"beta/groups?$filter=(resourceProvisioningOptions/Any(x:x eq 'Team') and displayName eq '{_stringValue}')&$select=Id", accessToken).GetAwaiter().GetResult(); + if (byDisplayNamecollection != null && byDisplayNamecollection.Items.Any()) + { + if (byDisplayNamecollection.Items.Count() == 1) + { + return byDisplayNamecollection.Items.First().Id; + } + else + { + throw new PSArgumentException("We found more matches based on the identity value you entered. Use Get-PnPTeamsTeam to find the correct instance and use the GroupId from a team to select the correct team instead."); + } + } + return null; + } + } + } + + public Team GetTeam(HttpClient httpClient, string accessToken) + { + try + { + if (!string.IsNullOrEmpty(_id)) + { + return GraphHelper.GetAsync(httpClient, $"v1.0/teams/{_id}", accessToken).GetAwaiter().GetResult(); + } + else + { + var collection = GraphHelper.GetAsync>(httpClient, $"beta/groups?$filter=(resourceProvisioningOptions/Any(x:x eq 'Team') and displayName eq '{_stringValue}')&$select=Id", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Any()) + { + if (collection.Items.Count() == 1) + { + return GraphHelper.GetAsync(httpClient, $"v1.0/teams/{collection.Items.First().Id}", accessToken).GetAwaiter().GetResult(); + } + else + { + throw new PSArgumentException("We found more matches based on the identity value you entered. Use Get-PnPTeamsTeam to find the correct instance and use the GroupId from a team to select the correct team instead."); + } + } + else + { + collection = GraphHelper.GetAsync>(httpClient, $"beta/groups?$filter=(resourceProvisioningOptions/Any(x:x eq 'Team') and mailNickname eq '{_stringValue}')&$select=Id", accessToken).GetAwaiter().GetResult(); + if (collection != null && collection.Items.Count() == 1) + { + return GraphHelper.GetAsync(httpClient, $"v1.0/teams/{collection.Items.First().Id}", accessToken).GetAwaiter().GetResult(); + } + } + } + } + catch (GraphException ex) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + return null; + } + + } +} diff --git a/Commands/Base/PnPConnection.cs b/Commands/Base/PnPConnection.cs index 37f8a8dc9..650f2fc79 100644 --- a/Commands/Base/PnPConnection.cs +++ b/Commands/Base/PnPConnection.cs @@ -1,14 +1,18 @@ using Microsoft.ApplicationInsights; +using Microsoft.Identity.Client; using Microsoft.SharePoint.Client; using OfficeDevPnP.Core.Extensions; using SharePointPnP.PowerShell.Commands.Enums; using SharePointPnP.PowerShell.Commands.Model; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Core.Attributes; using System; using System.Collections.Generic; using System.Linq; using System.Management.Automation; using System.Management.Automation.Host; using System.Net; +using System.Net.Http; using System.Reflection; using System.Security.Cryptography.X509Certificates; using System.Web; @@ -23,16 +27,31 @@ public class PnPConnection /// ClientId of the application registered in Azure Active Directory which should be used for the device oAuth flow /// internal const string DeviceLoginClientId = "31359c7f-bd7e-475c-86db-fdb8c937548e"; - + //private const string MSALPnPPowerShellClientId = "bb0c5778-9d5c-41ea-a4a8-8cd417b3ab71"; + //private const string MSALPnPPowerShellClientId = DeviceLoginClientId; #endregion #region Properties + private HttpClient httpClient; + + public HttpClient HttpClient + { + get + { + if (httpClient == null) + { + httpClient = new HttpClient(); + } + return httpClient; + } + } /// /// User Agent identifier to use on all connections being made to the APIs /// internal string UserAgent { get; set; } + internal ConnectionMethod ConnectionMethod { get; set; } /// @@ -50,6 +69,11 @@ public class PnPConnection /// public InitializationType InitializationType { get; protected set; } + /// + /// used to retrieve a new token in case the current token expires + /// + public string[] Scopes { get; internal set; } + /// /// If provided, it defines the minimal health score the SharePoint server should return back before executing requests on it. Use scale 0 - 10 where 0 is most health and 10 is least healthy. If set to NULL, no health score check will take place. /// @@ -80,6 +104,11 @@ public class PnPConnection /// public X509Certificate2 Certificate { get; internal set; } + /// + /// Boolean indicating if when using Disconnect-PnPOnline to destruct this PnPConnection instance, if the certificate file should be deleted from C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys + /// + public bool DeleteCertificateFromCacheOnDisconnect { get; internal set; } + public ClientContext Context { get; set; } /// @@ -111,53 +140,94 @@ internal string TryGetAccessToken(TokenAudience tokenAudience, string[] roles = return TryGetToken(tokenAudience, roles)?.AccessToken; } + internal static Action DeviceLoginCallback(PSHost host, bool launchBrowser) + { + return deviceCodeResult => + { + if (launchBrowser) + { + Utilities.Clipboard.CopyNew(deviceCodeResult.UserCode); + host?.UI.WriteLine($"Code {deviceCodeResult.UserCode} has been copied to clipboard"); +#if !NETSTANDARD2_1 + BrowserHelper.LaunchBrowser(deviceCodeResult.VerificationUrl, (success) => + { + }); +#else + OpenBrowser(returnData["verification_url"]); + messageCallback(returnData["message"]); + + var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); + + if (tokenResult != null) + { + progressCallback("Token received"); + spoConnection = new PnPConnection(tokenResult, ConnectionMethod.GraphDeviceLogin, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, PnPPSVersionTag, host, disableTelemetry, InitializationType.GraphDeviceLogin); + } + else + { + progressCallback("No token received."); + } +#endif + } + else + { + host?.UI.WriteLine(deviceCodeResult.Message); + } + }; + } /// /// Tries to get a token for the provided audience /// /// Audience to try to get a token for - /// The specific roles to request access to (i.e. Group.ReadWrite.All). Optional, will use default groups assigned to clientId if not specified. + /// The specific roles to request access to (i.e. Group.ReadWrite.All). Optional, will use default groups assigned to clientId if not specified. /// for the audience or NULL if unable to retrieve a token for the audience on the current connection - internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = null) + internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] orRoles = null, string[] andRoles = null, TokenType tokenType = TokenType.All) { GenericToken token = null; - // Validate if we have a token already - if (AccessTokens.ContainsKey(tokenAudience)) - { - // We have a token already, ensure it is still valid - token = AccessTokens[tokenAudience]; - - if (token.ExpiresOn > DateTime.Now) - { - // Token is still valid, ensure we dont have specific roles to check for or the requested roles to execute the command are present in the token - if (roles == null || roles.Length == 0 || roles.Any(r => token.Roles.Contains(r))) - { - return token; - } - - if (roles != null) - { - // Requested role was not part of the access token, throw an exception explaining which application registration is missing which role - throw new PSSecurityException($"Access to {tokenAudience} failed because the app registration {ClientId} in tenant {Tenant} is not granted {(roles.Length != 1 ? "any of " : string.Empty)}the permission{(roles.Length != 1 ? "s" : string.Empty)} {string.Join(", ", roles).TrimEnd(new[] { ',', ' ' })}"); - } - } - - // Token was no longer valid, proceed with trying to create a new token - } + //Validate if we have a token already + //if (AccessTokens.ContainsKey(tokenAudience)) + //{ + // // We have a token already, ensure it is still valid + // token = AccessTokens[tokenAudience]; + + // if (token.ExpiresOn > DateTime.Now) + // { + // var validationResults = ValidateTokenForPermissions(token, tokenAudience, orRoles, andRoles, tokenType); + // if (validationResults.valid) + // { + // return token; + // } + // throw new PSSecurityException($"Access to {tokenAudience} failed because the app registration {ClientId} in tenant {Tenant} is not granted {validationResults.message}"); + // } + + // // Token was no longer valid, proceed with trying to create a new token + //} // We do not have a token for the requested audience yet or it was no longer valid, try to create (a new) one switch (tokenAudience) { case TokenAudience.MicrosoftGraph: - if (!string.IsNullOrEmpty(Tenant)) + if (ConnectionMethod == ConnectionMethod.DeviceLogin || ConnectionMethod == ConnectionMethod.GraphDeviceLogin) { - if (Certificate != null) - { - token = GraphToken.AcquireToken(Tenant, ClientId, Certificate); - } - else if (ClientSecret != null) + token = GraphToken.AcquireApplicationTokenDeviceLogin(PnPConnection.DeviceLoginClientId, Scopes, DeviceLoginCallback(null, false)); + } + else + { + if (!string.IsNullOrEmpty(Tenant)) { - token = GraphToken.AcquireToken(Tenant, ClientId, ClientSecret); + if (Certificate != null) + { + token = GraphToken.AcquireApplicationToken(Tenant, ClientId, Certificate); + } + else if (ClientSecret != null) + { + token = GraphToken.AcquireApplicationToken(Tenant, ClientId, ClientSecret); + } + else if (Scopes != null) + { + token = PSCredential == null ? GraphToken.AcquireApplicationTokenInteractive(DeviceLoginClientId, Scopes) : GraphToken.AcquireDelegatedTokenWithCredentials(DeviceLoginClientId, Scopes, PSCredential.UserName, PSCredential.Password); + } } } break; @@ -167,11 +237,11 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = { if (Certificate != null) { - token = OfficeManagementApiToken.AcquireToken(Tenant, ClientId, Certificate); + token = OfficeManagementApiToken.AcquireApplicationToken(Tenant, ClientId, Certificate); } else if (ClientSecret != null) { - token = OfficeManagementApiToken.AcquireToken(Tenant, ClientId, ClientSecret); + token = OfficeManagementApiToken.AcquireApplicationToken(Tenant, ClientId, ClientSecret); } } break; @@ -183,8 +253,13 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = if (token != null) { + var validationResults = ValidateTokenForPermissions(token, tokenAudience, orRoles, andRoles, tokenType); + if (!validationResults.valid) + { + throw new PSSecurityException($"Access to {tokenAudience} failed because the app registration {ClientId} in tenant {Tenant} is not granted {validationResults.message}"); + } // Managed to create a token for the requested audience, add it to our collection with tokens - AccessTokens[tokenAudience] = token; + //AccessTokens[tokenAudience] = token; return token; } @@ -210,6 +285,58 @@ internal void ClearTokens() AccessTokens.Clear(); } + private (bool valid, string message) ValidateTokenForPermissions(GenericToken token, TokenAudience tokenAudience, string[] orRoles = null, string[] andRoles = null, TokenType tokenType = TokenType.All) + { + bool valid = false; + var message = string.Empty; + if (tokenType != TokenType.All && token.TokenType != tokenType) + { + throw new PSSecurityException($"Access to {tokenAudience} failed because the API requires {(tokenType == TokenType.Application ? "an" : "a")} {tokenType} token while you currently use {(token.TokenType == TokenType.Application ? "an" : "a")} {token.TokenType} token."); + } + var andRolesMatched = false; + if (andRoles != null && andRoles.Length != 0) + { + // we have explicitely required roles + andRolesMatched = andRoles.All(r => token.Roles.Contains(r)); + } + else + { + andRolesMatched = true; + } + + var orRolesMatched = false; + if (orRoles != null && orRoles.Length != 0) + { + orRolesMatched = orRoles.Any(r => token.Roles.Contains(r)); + } + else + { + orRolesMatched = true; + } + + if (orRolesMatched && andRolesMatched) + { + valid = true; + } + + if (orRoles != null || andRoles != null) + { + if (!valid) + { // Requested role was not part of the access token, throw an exception explaining which application registration is missing which role + if (!orRolesMatched) + { + message += "for one of the following roles: " + string.Join(", ", orRoles); + } + if (!andRolesMatched) + { + message += (message != string.Empty ? ", and " : ", ") + "for all of the following roles: " + string.Join(", ", andRoles); + } + throw new PSSecurityException($"Access to {tokenAudience} failed because the app registration {ClientId} in tenant {Tenant} is not granted {message}"); + } + } + return (valid, message); + } + #endregion #region Constructors @@ -394,6 +521,7 @@ public static PnPConnection GetConnectionWithToken(GenericToken token, TokenAudience tokenAudience, PSHost host, InitializationType initializationType, + PSCredential credentials, string url = null, ClientContext clientContext = null, int? minimalHealthScore = null, @@ -406,14 +534,14 @@ public static PnPConnection GetConnectionWithToken(GenericToken token, Tenant = token.ParsedToken.Claims.FirstOrDefault(c => c.Type.Equals("tid", StringComparison.InvariantCultureIgnoreCase))?.Value, ClientId = token.ParsedToken.Claims.FirstOrDefault(c => c.Type.Equals("appid", StringComparison.InvariantCultureIgnoreCase))?.Value }; - + connection.PSCredential = credentials; return connection; } #endregion internal PnPConnection(ClientContext context, ConnectionType connectionType, int minimalHealthScore, int retryCount, int retryWait, PSCredential credential, string clientId, string clientSecret, string url, string tenantAdminUrl, string pnpVersionTag, PSHost host, bool disableTelemetry, InitializationType initializationType) - : this(context, connectionType, minimalHealthScore, retryCount, retryWait, credential, url, tenantAdminUrl, pnpVersionTag, host, disableTelemetry, initializationType) + : this(context, connectionType, minimalHealthScore, retryCount, retryWait, credential, url, tenantAdminUrl, pnpVersionTag, host, disableTelemetry, initializationType) { ClientId = clientId; ClientSecret = clientSecret; diff --git a/Commands/Base/PnPConnectionHelper.cs b/Commands/Base/PnPConnectionHelper.cs index 729347674..cedd0f225 100644 --- a/Commands/Base/PnPConnectionHelper.cs +++ b/Commands/Base/PnPConnectionHelper.cs @@ -155,65 +155,13 @@ private static PnPConnection InstantiateHighTrustConnection(ClientContext contex internal static PnPConnection InstantiateDeviceLoginConnection(string url, bool launchBrowser, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, Action messageCallback, Action progressCallback, Func cancelRequest, PSHost host, bool disableTelemetry) { - PnPConnection spoConnection = null; var connectionUri = new Uri(url); - HttpClient client = new HttpClient(); - var result = client.GetStringAsync($"https://login.microsoftonline.com/common/oauth2/devicecode?resource={connectionUri.Scheme}://{connectionUri.Host}&client_id={PnPConnection.DeviceLoginClientId}").GetAwaiter().GetResult(); - var returnData = JsonConvert.DeserializeObject>(result); + var scopes = new[] { $"{connectionUri.Scheme}://{connectionUri.Host}//.default" }; // the second double slash is not a typo. var context = new ClientContext(url); - messageCallback(returnData["message"]); - if (launchBrowser) - { - Utilities.Clipboard.Copy(returnData["user_code"]); - messageCallback("Code has been copied to clipboard"); -#if !NETSTANDARD2_1 - BrowserHelper.OpenBrowser(returnData["verification_url"], (success) => - { - if (success) - { - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = new PnPConnection(context, tokenResult, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, null, url.ToString(), tenantAdminUrl, PnPPSVersionTag, host, disableTelemetry, InitializationType.DeviceLogin); - } - else - { - progressCallback("No token received."); - } - } - }); -#else - OpenBrowser(returnData["verification_url"]); - messageCallback(returnData["message"]); - - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = new PnPConnection(context, tokenResult, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, null, url.ToString(), tenantAdminUrl, PnPPSVersionTag, host, disableTelemetry, InitializationType.DeviceLogin); - } - else - { - progressCallback("No token received."); - } -#endif - } - else - { - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = PnPConnection.GetConnectionWithToken(tokenResult, TokenAudience.SharePointOnline, host, InitializationType.DeviceLogin, url, context, minimalHealthScore, PnPPSVersionTag, disableTelemetry); - } - else - { - progressCallback("No token received."); - } - } + var tokenResult = GraphToken.AcquireApplicationTokenDeviceLogin(PnPConnection.DeviceLoginClientId, scopes, PnPConnection.DeviceLoginCallback(host, launchBrowser)); + var spoConnection = new PnPConnection(context, tokenResult, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, null, url.ToString(), tenantAdminUrl, PnPPSVersionTag, host, disableTelemetry, InitializationType.DeviceLogin); + spoConnection.Scopes = scopes; if (spoConnection != null) { @@ -232,73 +180,12 @@ internal static PnPConnection InstantiateGraphAccessTokenConnection(string acces internal static PnPConnection InstantiateGraphDeviceLoginConnection(bool launchBrowser, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, Action messageCallback, Action progressCallback, Func cancelRequest, PSHost host, bool disableTelemetry) { - var connectionUri = new Uri("https://graph.microsoft.com"); - HttpClient client = new HttpClient(); - var result = client.GetStringAsync($"https://login.microsoftonline.com/common/oauth2/devicecode?resource={connectionUri.Scheme}://{connectionUri.Host}&client_id={PnPConnection.DeviceLoginClientId}").GetAwaiter().GetResult(); - var returnData = JsonConvert.DeserializeObject>(result); - - PnPConnection spoConnection = null; - - if (launchBrowser) - { - Utilities.Clipboard.Copy(returnData["user_code"]); - messageCallback("Code has been copied to clipboard"); -#if !NETSTANDARD2_1 - BrowserHelper.OpenBrowser(returnData["verification_url"], (success) => - { - if (success) - { - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = new PnPConnection(tokenResult, ConnectionMethod.GraphDeviceLogin, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, PnPPSVersionTag, host, disableTelemetry, InitializationType.GraphDeviceLogin); - } - else - { - progressCallback("No token received."); - } - } - }); -#else - OpenBrowser(returnData["verification_url"]); - messageCallback(returnData["message"]); - - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = new PnPConnection(tokenResult, ConnectionMethod.GraphDeviceLogin, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, PnPPSVersionTag, host, disableTelemetry, InitializationType.GraphDeviceLogin); - } - else - { - progressCallback("No token received."); - } -#endif - } - else - { - messageCallback(returnData["message"]); - - var tokenResult = GetTokenResult(connectionUri, returnData, messageCallback, progressCallback, cancelRequest); - - if (tokenResult != null) - { - progressCallback("Token received"); - spoConnection = new PnPConnection(tokenResult, ConnectionMethod.GraphDeviceLogin, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, PnPPSVersionTag, host, disableTelemetry, InitializationType.GraphDeviceLogin); - spoConnection.ConnectionMethod = ConnectionMethod.GraphDeviceLogin; - } - else - { - progressCallback("No token received."); - } - } + var tokenResult = GraphToken.AcquireApplicationTokenDeviceLogin(PnPConnection.DeviceLoginClientId, new[] { "Group.Read.All", "openid", "email", "profile", "Group.ReadWrite.All", "User.Read.All", "Directory.ReadWrite.All" }, PnPConnection.DeviceLoginCallback(host, launchBrowser)); + var spoConnection = new PnPConnection(tokenResult, ConnectionMethod.GraphDeviceLogin, ConnectionType.O365, minimalHealthScore, retryCount, retryWait, PnPPSVersionTag, host, disableTelemetry, InitializationType.GraphDeviceLogin); + spoConnection.Scopes = new[] { "Group.Read.All", "openid", "email", "profile", "Group.ReadWrite.All", "User.Read.All", "Directory.ReadWrite.All" }; return spoConnection; } - - private static GenericToken GetTokenResult(Uri connectionUri, Dictionary returnData, Action messageCallback, Action progressCallback, Func cancelRequest) { HttpClient client = new HttpClient(); @@ -445,6 +332,12 @@ internal static PnPConnection InitiateAzureADAppOnlyConnection(Uri url, string c throw new PSArgumentOutOfRangeException(nameof(thumbprint), null, string.Format(Resources.CertificateWithThumbprintNotFound, thumbprint)); } + // Ensure the private key of the certificate is available + if (!certificate.HasPrivateKey) + { + throw new PSArgumentOutOfRangeException(nameof(thumbprint), null, string.Format(Resources.CertificateWithThumbprintDoesNotHavePrivateKey, thumbprint)); + } + return InitiateAzureAdAppOnlyConnectionWithCert(url, clientId, tenant, minimalHealthScore, retryCount, retryWait, requestTimeout, tenantAdminUrl, host, disableTelemetry, skipAdminCheck, azureEnvironment, certificate, false); } @@ -453,7 +346,7 @@ internal static PnPConnection InitiateAzureADAppOnlyConnection(Uri url, string c string password = new System.Net.NetworkCredential(string.Empty, certificatePassword).Password; X509Certificate2 certificate = CertificateHelper.GetCertificateFromPEMstring(certificatePEM, privateKeyPEM, password); - return InitiateAzureAdAppOnlyConnectionWithCert(url, clientId, tenant, minimalHealthScore, retryCount, retryWait, requestTimeout, tenantAdminUrl, host, disableTelemetry, skipAdminCheck, azureEnvironment, certificate, true); + return InitiateAzureAdAppOnlyConnectionWithCert(url, clientId, tenant, minimalHealthScore, retryCount, retryWait, requestTimeout, tenantAdminUrl, host, disableTelemetry, skipAdminCheck, azureEnvironment, certificate, false); } /// @@ -534,7 +427,8 @@ private static PnPConnection InitiateAzureAdAppOnlyConnectionWithCert(Uri url, s { ConnectionMethod = ConnectionMethod.AzureADAppOnly, Certificate = certificate, - Tenant = tenant + Tenant = tenant, + DeleteCertificateFromCacheOnDisconnect = certificateFromFile }; return spoConnection; } @@ -562,16 +456,34 @@ internal static PnPConnection InitiateAzureAdAppOnlyConnectionWithClientIdClient return spoConnection; } + /// + /// Tries to remove the local cached machine copy of the private key + /// + /// Certificate to try to clean up the local cached copy of the private key of internal static void CleanupCryptoMachineKey(X509Certificate2 certificate) { + if (!certificate.HasPrivateKey) + { + // If somehow a public key certificate was passed in, we can't clean it up, thus we have nothing to do here + return; + } + var privateKey = (RSACryptoServiceProvider)certificate.PrivateKey; string uniqueKeyContainerName = privateKey.CspKeyContainerInfo.UniqueKeyContainerName; certificate.Reset(); - var path = Environment.GetEnvironmentVariable("ProgramData"); - if (string.IsNullOrEmpty(path)) path = @"C:\ProgramData"; + + var programDataPath = Environment.GetEnvironmentVariable("ProgramData"); + if (string.IsNullOrEmpty(programDataPath)) + { + programDataPath = @"C:\ProgramData"; + } try { - System.IO.File.Delete(string.Format(@"{0}\Microsoft\Crypto\RSA\MachineKeys\{1}", path, uniqueKeyContainerName)); + var temporaryCertificateFilePath = $@"{programDataPath}\Microsoft\Crypto\RSA\MachineKeys\{uniqueKeyContainerName}"; + if (System.IO.File.Exists(temporaryCertificateFilePath)) + { + System.IO.File.Delete(temporaryCertificateFilePath); + } } catch (Exception) { @@ -640,9 +552,6 @@ internal static PnPConnection InstantiateWebloginConnection(Uri url, int minimal #if !NETSTANDARD2_1 internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredential credentials, PSHost host, bool currentCredentials, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, bool disableTelemetry, bool skipAdminCheck = false, ClientAuthenticationMode authenticationMode = ClientAuthenticationMode.Default) -#else - internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredential credentials, PSHost host, bool currentCredentials, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, bool disableTelemetry, bool skipAdminCheck = false) -#endif { var context = new PnPClientContext(url.AbsoluteUri); @@ -654,7 +563,6 @@ internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredentia #endif context.RequestTimeout = requestTimeout; -#if !NETSTANDARD2_1 context.AuthenticationMode = authenticationMode; if (authenticationMode == ClientAuthenticationMode.FormsAuthentication) @@ -662,16 +570,11 @@ internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredentia var formsAuthInfo = new FormsAuthenticationLoginInfo(credentials.UserName, EncryptionUtility.ToInsecureString(credentials.Password)); context.FormsAuthenticationLoginInfo = formsAuthInfo; } -#endif if (!currentCredentials) { try { -#if !NETSTANDARD2_1 SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(credentials.UserName, credentials.Password); -#else - var onlineCredentials = new System.Net.NetworkCredential(credentials.UserName, credentials.Password); -#endif context.Credentials = onlineCredentials; try { @@ -680,17 +583,12 @@ internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredentia #if !ONPREMISES catch (NotSupportedException) { -#if NETSTANDARD2_1 - // Legacy auth is not supported with .NET Standard - throw new Exception("Legacy auth is not supported with .NET Standard"); -#else // legacy auth? using (var authManager = new OfficeDevPnP.Core.AuthenticationManager()) { context = PnPClientContext.ConvertFrom(authManager.GetAzureADCredentialsContext(url.ToString(), credentials.UserName, credentials.Password)); context.ExecuteQueryRetry(); } -#endif } #endif catch (ClientRequestException) @@ -762,6 +660,53 @@ internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredentia spoConnection.ConnectionMethod = Model.ConnectionMethod.Credentials; return spoConnection; } +#endif + +#if NETSTANDARD2_1 + internal static PnPConnection InstantiateSPOnlineConnection(Uri url, PSCredential credentials, PSHost host, bool currentCredentials, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, bool disableTelemetry, bool skipAdminCheck = false) + { + var context = new PnPClientContext(url.AbsoluteUri); + + context.RetryCount = retryCount; + context.Delay = retryWait * 1000; + context.ApplicationName = Resources.ApplicationName; + context.DisableReturnValueCache = true; + context.RequestTimeout = requestTimeout; + + try + { + using (var authManager = new OfficeDevPnP.Core.AuthenticationManager()) + { + context = PnPClientContext.ConvertFrom(authManager.GetAzureADCredentialsContext(url.ToString(), credentials.UserName, credentials.Password)); + context.ExecuteQueryRetry(); + } + } + catch (ClientRequestException) + { + context.Credentials = new NetworkCredential(credentials.UserName, credentials.Password); + } + catch (ServerException) + { + context.Credentials = new NetworkCredential(credentials.UserName, credentials.Password); + } + var connectionType = ConnectionType.O365; + if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM")) + { + connectionType = ConnectionType.O365; + } + + if (skipAdminCheck == false) + { + if (IsTenantAdminSite(context)) + { + connectionType = ConnectionType.TenantAdmin; + } + } + var spoConnection = new PnPConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, credentials, url.ToString(), tenantAdminUrl, PnPPSVersionTag, host, disableTelemetry, InitializationType.Credentials); + spoConnection.ConnectionMethod = Model.ConnectionMethod.Credentials; + return spoConnection; + } +#endif #if !NETSTANDARD2_1 internal static PnPConnection InstantiateAdfsConnection(Uri url, bool useKerberos, PSCredential credentials, PSHost host, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, bool disableTelemetry, bool skipAdminCheck = false, string loginProviderName = null) diff --git a/Commands/Base/PnPGraphCmdlet.cs b/Commands/Base/PnPGraphCmdlet.cs index 2fd3c5b9b..f02b000d7 100644 --- a/Commands/Base/PnPGraphCmdlet.cs +++ b/Commands/Base/PnPGraphCmdlet.cs @@ -2,9 +2,11 @@ using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Model; using SharePointPnP.PowerShell.Commands.Properties; +using SharePointPnP.PowerShell.Core.Attributes; using System; using System.Collections.Generic; using System.Management.Automation; +using System.Net.Http; namespace SharePointPnP.PowerShell.Commands.Base { @@ -23,16 +25,33 @@ public GraphToken Token { get { + var tokenType = TokenType.All; + + // Collect, if present, the token type attribute + var tokenTypeAttribute = (CmdletTokenTypeAttribute)Attribute.GetCustomAttribute(GetType(), typeof(CmdletTokenTypeAttribute)); + if(tokenTypeAttribute != null) + { + tokenType = tokenTypeAttribute.TokenType; + } // Collect the permission attributes to discover required roles var requiredRoleAttributes = (CmdletMicrosoftGraphApiPermission[])Attribute.GetCustomAttributes(GetType(), typeof(CmdletMicrosoftGraphApiPermission)); - var requiredRoles = new List(requiredRoleAttributes.Length); + var orRequiredRoles = new List(requiredRoleAttributes.Length); + var andRequiredRoles = new List(requiredRoleAttributes.Length); foreach (var requiredRoleAttribute in requiredRoleAttributes) { + foreach (MicrosoftGraphApiPermission role in Enum.GetValues(typeof(MicrosoftGraphApiPermission))) { - if(requiredRoleAttribute.ApiPermission.HasFlag(role)) + if (role != MicrosoftGraphApiPermission.None) { - requiredRoles.Add(role.ToString().Replace("_", ".")); + if (requiredRoleAttribute.OrApiPermissions.HasFlag(role)) + { + orRequiredRoles.Add(role.ToString().Replace("_", ".")); + } + if (requiredRoleAttribute.AndApiPermissions.HasFlag(role)) + { + andRequiredRoles.Add(role.ToString().Replace("_", ".")); + } } } } @@ -41,10 +60,10 @@ public GraphToken Token if (PnPConnection.CurrentConnection != null) { // There is an active connection, try to get a Microsoft Graph Token on the active connection - if (PnPConnection.CurrentConnection.TryGetToken(Enums.TokenAudience.MicrosoftGraph, ByPassPermissionCheck.ToBool() ? null : requiredRoles.ToArray()) is GraphToken token) + if (PnPConnection.CurrentConnection.TryGetToken(Enums.TokenAudience.MicrosoftGraph, ByPassPermissionCheck.ToBool() ? null : orRequiredRoles.ToArray(), ByPassPermissionCheck.ToBool() ? null : andRequiredRoles.ToArray(), tokenType) is GraphToken token) { // Microsoft Graph Access Token available, return it - return token; + return (GraphToken)token; } } @@ -59,6 +78,8 @@ public GraphToken Token /// Returns an Access Token for Microsoft Graph, if available, otherwise NULL /// public string AccessToken => Token?.AccessToken; + + public HttpClient HttpClient => PnPConnection.CurrentConnection.HttpClient; } } #endif \ No newline at end of file diff --git a/Commands/Base/PnPOfficeManagementApiCmdlet.cs b/Commands/Base/PnPOfficeManagementApiCmdlet.cs index 2030a655c..7a855c599 100644 --- a/Commands/Base/PnPOfficeManagementApiCmdlet.cs +++ b/Commands/Base/PnPOfficeManagementApiCmdlet.cs @@ -2,6 +2,7 @@ using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Model; using SharePointPnP.PowerShell.Commands.Properties; +using SharePointPnP.PowerShell.Core.Attributes; using System; using System.Collections.Generic; using System.Management.Automation; @@ -23,19 +24,43 @@ public OfficeManagementApiToken Token { get { + var tokenType = TokenType.All; + + // Collect, if present, the token type attribute + var tokenTypeAttribute = (CmdletTokenTypeAttribute)Attribute.GetCustomAttribute(GetType(), typeof(CmdletTokenTypeAttribute)); + if (tokenTypeAttribute != null) + { + tokenType = tokenTypeAttribute.TokenType; + } + // Collect the permission attributes to discover required roles var requiredRoleAttributes = (CmdletOfficeManagementApiPermissionAttribute[])Attribute.GetCustomAttributes(GetType(), typeof(CmdletOfficeManagementApiPermissionAttribute)); - var requiredRoles = new List(requiredRoleAttributes.Length); - foreach(var requiredRoleAttribute in requiredRoleAttributes) + var orRequiredRoles = new List(requiredRoleAttributes.Length); + var andRequiredRoles = new List(requiredRoleAttributes.Length); + + foreach (var requiredRoleAttribute in requiredRoleAttributes) { - requiredRoles.Add(requiredRoleAttribute.ApiPermission.ToString().Replace("_", ".")); + foreach (OfficeManagementApiPermission role in Enum.GetValues(typeof(OfficeManagementApiPermission))) + { + if (role != OfficeManagementApiPermission.None) + { + if (requiredRoleAttribute.OrApiPermissions.HasFlag(role)) + { + orRequiredRoles.Add(role.ToString().Replace("_", ".")); + } + if (requiredRoleAttribute.AndApiPermissions.HasFlag(role)) + { + andRequiredRoles.Add(role.ToString().Replace("_", ".")); + } + } + } } // Ensure we have an active connection if (PnPConnection.CurrentConnection != null) { // There is an active connection, try to get a Microsoft Office Management API Token on the active connection - if (PnPConnection.CurrentConnection.TryGetToken(Enums.TokenAudience.OfficeManagementApi, ByPassPermissionCheck.ToBool() ? null : requiredRoles.ToArray()) is OfficeManagementApiToken token) + if (PnPConnection.CurrentConnection.TryGetToken(Enums.TokenAudience.OfficeManagementApi, ByPassPermissionCheck.ToBool() ? null : orRequiredRoles.ToArray(), ByPassPermissionCheck.ToBool() ? null : andRequiredRoles.ToArray(), tokenType) is OfficeManagementApiToken token) { // Microsoft Office Management API Access Token available, return it return token; diff --git a/Commands/Base/RequestAccessToken.cs b/Commands/Base/RequestAccessToken.cs index 1b47f1d03..fd0064220 100644 --- a/Commands/Base/RequestAccessToken.cs +++ b/Commands/Base/RequestAccessToken.cs @@ -39,7 +39,7 @@ public class RequestAccessToken : BasePSCmdlet { [Parameter(Mandatory = false, HelpMessage = "The Azure Application Client Id to use to retrieve the token. Defaults to the PnP Office 365 Management Shell")] - public string ClientId = PnPConnection.DeviceLoginClientId; // defaults to PnPO365ManagementShell + public string ClientId = PnPConnection.DeviceLoginClientId; // defaults to PnPManagementShell [Parameter(Mandatory = false, HelpMessage = "The scopes to retrieve the token for. Defaults to AllSites.FullControl")] public string Resource; diff --git a/Commands/ClientSidePages/RemoveClientSideComponent.cs b/Commands/ClientSidePages/RemoveClientSideComponent.cs index 583b4964c..c1b79004e 100644 --- a/Commands/ClientSidePages/RemoveClientSideComponent.cs +++ b/Commands/ClientSidePages/RemoveClientSideComponent.cs @@ -14,6 +14,10 @@ namespace SharePointPnP.PowerShell.Commands.ClientSidePages [CmdletExample( Code = @"PS:> Remove-PnPClientSideComponent -Page Home -InstanceId a2875399-d6ff-43a0-96da-be6ae5875f82", Remarks = @"Removes the control specified from the page.", SortOrder = 1)] + [CmdletExample( + Code = @"PS:> $webpart = Get-PnPClientSideComponent -Page ""Home"" | Where-Object { $_.Title -eq ""Site activity"" } +PS:> Remove-PnPClientSideComponent -Page ""Home"" -InstanceId $webpart.InstanceId -Force", + Remarks = @"Finds a web part with the Title ""Site activity"" on the Home.aspx page, then removes it from the page", SortOrder = 2)] public class RemoveClientSideComponent : PnPWebCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The name of the page")] @@ -48,4 +52,4 @@ protected override void ExecuteCmdlet() } } } -#endif \ No newline at end of file +#endif diff --git a/Commands/Diagnostic/MeasurePnPList.cs b/Commands/Diagnostic/MeasurePnPList.cs index e991c57de..93bca3142 100644 --- a/Commands/Diagnostic/MeasurePnPList.cs +++ b/Commands/Diagnostic/MeasurePnPList.cs @@ -12,7 +12,7 @@ namespace SharePointPnP.PowerShell.Commands.Diagnostic { [Cmdlet(VerbsDiagnostic.Measure, "PnPList")] - [CmdletHelp("Returns statistics on the list object", + [CmdletHelp("Returns statistics on the list object. This may fail on lists larger than the list view threshold", Category = CmdletHelpCategory.Diagnostic, SupportedPlatform = CmdletSupportedPlatform.Online | CmdletSupportedPlatform.SP2016 | CmdletSupportedPlatform.SP2019)] [CmdletExample( diff --git a/Commands/Fields/SetField.cs b/Commands/Fields/SetField.cs index c9838241f..cedc6ecd3 100644 --- a/Commands/Fields/SetField.cs +++ b/Commands/Fields/SetField.cs @@ -11,7 +11,7 @@ namespace SharePointPnP.PowerShell.Commands.Fields [CmdletHelp("Changes one or more properties of a field in a specific list or for the whole web", Category = CmdletHelpCategory.Fields, OutputType = typeof(Field), - OutputTypeLink = "https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.field.aspx")] + OutputTypeLink = "https://docs.microsoft.com/previous-versions/office/sharepoint-server/ee545882(v=office.15)")] [CmdletExample( Code = @"PS:> Set-PnPField -Identity AssignedTo -Values @{JSLink=""customrendering.js"";Group=""My fields""}", Remarks = @"Updates the AssignedTo field on the current web to use customrendering.js for the JSLink and sets the group name the field is categorized in to ""My Fields"". Lists that are already using the AssignedTo field will not be updated.", @@ -40,6 +40,7 @@ public class SetField : PnPWebCmdlet protected override void ExecuteCmdlet() { + const string allowDeletionPropertyKey = "AllowDeletion"; Field field = null; if (List != null) { @@ -84,7 +85,14 @@ protected override void ExecuteCmdlet() } } - ClientContext.Load(field); + if (Values.ContainsKey(allowDeletionPropertyKey)) + { + ClientContext.Load(field, f => f.SchemaXmlWithResourceTokens); + } + else + { + ClientContext.Load(field); + } ClientContext.ExecuteQueryRetry(); // Get a reference to the type-specific object to allow setting type-specific properties, i.e. LookupList and LookupField for Microsoft.SharePoint.Client.FieldLookup @@ -95,7 +103,10 @@ protected override void ExecuteCmdlet() var value = Values[key]; var property = typeSpecificField.GetType().GetProperty(key); - if (property == null) + + bool isAllowDeletionProperty = string.Equals(key, allowDeletionPropertyKey, StringComparison.Ordinal); + + if (property == null && !isAllowDeletionProperty) { WriteWarning($"No property '{key}' found on this field. Value will be ignored."); } @@ -103,7 +114,14 @@ protected override void ExecuteCmdlet() { try { - property.SetValue(typeSpecificField, value); + if (isAllowDeletionProperty) + { + field.SetAllowDeletion(value as bool?); + } + else + { + property.SetValue(typeSpecificField, value); + } } catch (Exception e) { diff --git a/Commands/Files/CopyFile.cs b/Commands/Files/CopyFile.cs index 062ad6980..af11c8e9a 100644 --- a/Commands/Files/CopyFile.cs +++ b/Commands/Files/CopyFile.cs @@ -11,53 +11,59 @@ namespace SharePointPnP.PowerShell.Commands.Files { - [Cmdlet(VerbsCommon.Copy, "PnPFile", SupportsShouldProcess = true, DefaultParameterSetName = "SOURCEURL")] - [CmdletHelp("Copies a file or folder to a different location, currently there is a 200MB file size limit for the file to be copied.", + [Cmdlet(VerbsCommon.Copy, "PnPFile", SupportsShouldProcess = true)] + [CmdletHelp("Copies a file or folder to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Currently there is a 200MB file size limit for the file or folder to be copied.", Category = CmdletHelpCategory.Files)] +#if !ONPREMISES [CmdletExample( - Remarks = "Copies a file named company.docx located in a document library called Documents in the current site to the site collection otherproject. If a file named company.docx already exists, it won't perform the copy.", - Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx", + Remarks = "Copies a file named company.docx located in a document library called Shared Documents in the site collection project to the Shared Documents library in the site collection otherproject. If a file named company.docx already exists, it won't perform the copy.", + Code = @"PS:>Copy-PnPFile -ServerRelativeUrl ""/sites/project/Shared Documents/company.docx"" -TargetServerRelativeLibrary ""/sites/otherproject/Shared Documents""", SortOrder = 1)] + [CmdletExample( + Remarks = "Copies a folder named Archive located in a document library called Shared Documents in the site collection project to the Shared Documents library in the site collection otherproject. If a folder named Archive already exists, it will overwrite it.", + Code = @"PS:>Copy-PnPFile -ServerRelativeUrl ""/sites/project/Shared Documents/Archive"" -TargetServerRelativeLibrary ""/sites/otherproject/Shared Documents"" -OverwriteIfAlreadyExists", + SortOrder = 2)] +#endif [CmdletExample( Remarks = "Copies a file named company.docx located in a document library called Documents to a new document named company2.docx in the same library.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Documents/company2.docx", - SortOrder = 2)] + SortOrder = 3)] [CmdletExample( Remarks = "Copies a file named company.docx located in a document library called Documents to a document library called Documents2 in the same site. ", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Documents2/company.docx", - SortOrder = 3)] + SortOrder = 4)] [CmdletExample( Remarks = "Copies a file named company.docx located in a document library called Documents to the document library named Document in a subsite named Subsite as a new document named company2.docx.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Subsite/Documents/company2.docx", - SortOrder = 4)] + SortOrder = 5)] [CmdletExample( Remarks = "Copies a file named company.docx located in a document library called Documents to the document library named Document in a subsite named Subsite keeping the file name.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl Subsite/Documents", - SortOrder = 5)] + SortOrder = 6)] [CmdletExample( Remarks = "Copies a file named company.docx located in a document library called Documents in the current site to the site collection otherproject. If a file named company.docx already exists, it will still perform the copy and replace the original company.docx file.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/company.docx -TargetUrl /sites/otherproject/Documents/company.docx -OverwriteIfAlreadyExists", - SortOrder = 6)] + SortOrder = 7)] [CmdletExample( Remarks = "Copies a folder named MyDocs in the document library called Documents located in the current site to the site collection otherproject. If the MyDocs folder exist it will copy into it, if not it will be created.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents -OverwriteIfAlreadyExists", - SortOrder = 7)] + SortOrder = 8)] [CmdletExample( Remarks = "Copies a folder named MyDocs in the document library called Documents located in the current site to the root folder of the library named Documents in the site collection otherproject.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents -SkipSourceFolderName -OverwriteIfAlreadyExists", - SortOrder = 8)] + SortOrder = 0)] [CmdletExample( Remarks = "Copies a folder named MyDocs in the MyDocs folder of the library named Documents. If the MyDocs folder does not exists, it will be created.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents/MyDocs -SkipSourceFolderName -OverwriteIfAlreadyExists", - SortOrder = 9)] + SortOrder = 10)] [CmdletExample( Remarks = "Copies a folder named MyDocs in the root of the library named Documents. If the MyDocs folder exists in the target, a subfolder also named MyDocs is created.", Code = @"PS:>Copy-PnPFile -SourceUrl Documents/MyDocs -TargetUrl /sites/otherproject/Documents/MyDocs -OverwriteIfAlreadyExists", - SortOrder = 10)] + SortOrder = 11)] [CmdletExample( Remarks = "Copies a file named company.docx in the library named Documents in SubSite1 to the library named Documents in SubSite2.", Code = @"PS:>Copy-PnPFile -SourceUrl SubSite1/Documents/company.docx -TargetUrl SubSite2/Documents", - SortOrder = 10)] + SortOrder = 12)] public class CopyFile : PnPWebCmdlet { @@ -66,15 +72,14 @@ public class CopyFile : PnPWebCmdlet private ClientContext _sourceContext; private ClientContext _targetContext; - [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = "SERVER", HelpMessage = "Server relative Url specifying the file or folder to copy.")] - [Obsolete("Use SourceUrl instead.")] - public string ServerRelativeUrl = string.Empty; - - [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = "SOURCEURL", HelpMessage = "Site relative Url specifying the file or folder to copy.")] - [Alias("SiteRelativeUrl")] + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, HelpMessage = "Site or server relative Url specifying the file or folder to copy. Must include the file name if it's a file or the entire path to the folder if it's a folder.")] + [Alias("SiteRelativeUrl", "ServerRelativeUrl")] // Aliases are present to allow for switching between Move-PnPFile and Copy-PnPFile keeping the same parameters. public string SourceUrl = string.Empty; - [Parameter(Mandatory = true, Position = 1, HelpMessage = "Server relative Url where to copy the file or folder to.")] + [Parameter(Mandatory = true, Position = 1, HelpMessage = "Server relative Url where to copy the file or folder to. Must not include the file name.")] +#if !ONPREMISES + [Alias(nameof(MoveFile.TargetServerRelativeLibrary))] // Aliases is present to allow for switching between Move-PnPFile and Copy-PnPFile keeping the same parameters. +#endif public string TargetUrl = string.Empty; [Parameter(Mandatory = false, HelpMessage = "If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the copy operation will be canceled if the file already exists at the TargetUrl location.")] @@ -83,14 +88,16 @@ public class CopyFile : PnPWebCmdlet [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be requested and the action will be performed")] public SwitchParameter Force; - [Parameter(Mandatory = false, HelpMessage = "If the source is a folder, the source folder name will not be created, only the contents within it.")] + [Parameter(Mandatory = false, HelpMessage = "If the source is a folder, the source folder name will not be created, only the contents within it")] public SwitchParameter SkipSourceFolderName; +#if !ONPREMISES + [Parameter(Mandatory = false, HelpMessage = "If provided, only the latest version of the document will be copied and its history will be discared. If not provided, all historical versions will be copied along.")] + public SwitchParameter IgnoreVersionHistory; +#endif + protected override void ExecuteCmdlet() { -#pragma warning disable CS0618 // Type or member is obsolete - SourceUrl = SourceUrl ?? ServerRelativeUrl; -#pragma warning restore CS0618 // Type or member is obsolete var webServerRelativeUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl); if (!SourceUrl.StartsWith("/")) @@ -108,6 +115,28 @@ protected override void ExecuteCmdlet() Uri targetUri = new Uri(currentContextUri, TargetUrl); Uri targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + if (Force || ShouldContinue(string.Format(Resources.CopyFile0To1, SourceUrl, TargetUrl), Resources.Confirm)) + { +#if !ONPREMISES + if (sourceWebUri != targetWebUri) + { + CopyToOtherSiteCollection(sourceUri, targetUri); + } + else + { +#endif + CopyWithinSameSiteCollection(currentContextUri, sourceWebUri, targetWebUri); +#if !ONPREMISES + } +#endif + } + } + + /// + /// Allows copying to within the same site collection + /// + private void CopyWithinSameSiteCollection(Uri currentContextUri, Uri sourceWebUri, Uri targetWebUri) + { _sourceContext = ClientContext; if (!currentContextUri.AbsoluteUri.Equals(sourceWebUri.AbsoluteUri, StringComparison.InvariantCultureIgnoreCase)) { @@ -158,54 +187,51 @@ protected override void ExecuteCmdlet() { srcIsFolder = false; } - #endif } - if (Force || ShouldContinue(string.Format(Resources.CopyFile0To1, SourceUrl, TargetUrl), Resources.Confirm)) - { - var srcWeb = _sourceContext.Web; - srcWeb.EnsureProperty(s => s.Url); + var srcWeb = _sourceContext.Web; + srcWeb.EnsureProperty(s => s.Url); - _targetContext = ClientContext.Clone(targetWebUri.AbsoluteUri); - var dstWeb = _targetContext.Web; - dstWeb.EnsureProperties(s => s.Url, s => s.ServerRelativeUrl); - if (srcWeb.Url == dstWeb.Url) + _targetContext = ClientContext.Clone(targetWebUri.AbsoluteUri); + var dstWeb = _targetContext.Web; + dstWeb.EnsureProperties(s => s.Url, s => s.ServerRelativeUrl); + if (srcWeb.Url == dstWeb.Url) + { + try { - try - { - var targetFile = UrlUtility.Combine(TargetUrl, file?.Name); - // If src/dst are on the same Web, then try using CopyTo - backwards compability + var targetFile = UrlUtility.Combine(TargetUrl, file?.Name); + // If src/dst are on the same Web, then try using CopyTo - backwards compability #if ONPREMISES file?.CopyTo(targetFile, OverwriteIfAlreadyExists); #else - file?.CopyToUsingPath(ResourcePath.FromDecodedUrl(targetFile), OverwriteIfAlreadyExists); + file?.CopyToUsingPath(ResourcePath.FromDecodedUrl(targetFile), OverwriteIfAlreadyExists); #endif - _sourceContext.ExecuteQueryRetry(); - return; - } - catch - { - SkipSourceFolderName = true; // target folder exist - //swallow exception, in case target was a lib/folder which exists - } + _sourceContext.ExecuteQueryRetry(); + return; } - - //different site/site collection - Folder targetFolder = null; - string fileOrFolderName = null; - bool targetFolderExists = false; - try + catch { + SkipSourceFolderName = true; // target folder exist + //swallow exception, in case target was a lib/folder which exists + } + } + + //different site/site collection + Folder targetFolder = null; + string fileOrFolderName = null; + bool targetFolderExists = false; + try + { #if ONPREMISES targetFolder = _targetContext.Web.GetFolderByServerRelativeUrl(TargetUrl); #else - targetFolder = _targetContext.Web.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(TargetUrl)); + targetFolder = _targetContext.Web.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(TargetUrl)); #endif #if !SP2013 - targetFolder.EnsureProperties(f => f.Name, f => f.Exists); - if (!targetFolder.Exists) throw new Exception("TargetUrl is an existing file, not folder"); - targetFolderExists = true; + targetFolder.EnsureProperties(f => f.Name, f => f.Exists); + if (!targetFolder.Exists) throw new Exception("TargetUrl is an existing file, not folder"); + targetFolderExists = true; #else targetFolder.EnsureProperties(f => f.Name); try @@ -219,43 +245,56 @@ protected override void ExecuteCmdlet() } if (!targetFolderExists) throw new Exception("TargetUrl is an existing file, not folder"); #endif - } - catch (Exception) - { - targetFolder = null; - Expression> expressionRelativeUrl = l => l.RootFolder.ServerRelativeUrl; - var query = _targetContext.Web.Lists.IncludeWithDefaultProperties(expressionRelativeUrl); - var lists = _targetContext.LoadQuery(query); - _targetContext.ExecuteQueryRetry(); - lists = lists.OrderByDescending(l => l.RootFolder.ServerRelativeUrl); // order descending in case more lists start with the same - foreach (List targetList in lists) - { - if (!TargetUrl.StartsWith(targetList.RootFolder.ServerRelativeUrl, StringComparison.InvariantCultureIgnoreCase)) continue; - fileOrFolderName = Regex.Replace(TargetUrl, _targetContext.Web.ServerRelativeUrl, "", RegexOptions.IgnoreCase).Trim('/'); - targetFolder = srcIsFolder - ? _targetContext.Web.EnsureFolderPath(fileOrFolderName) - : targetList.RootFolder; - //fileOrFolderName = Regex.Replace(TargetUrl, targetList.RootFolder.ServerRelativeUrl, "", RegexOptions.IgnoreCase).Trim('/'); - //targetFolder = srcIsFolder ? targetList.RootFolder.EnsureFolder(fileOrFolderName) : targetList.RootFolder; - break; - } - } - if (targetFolder == null) throw new Exception("Target does not exist"); - if (srcIsFolder) + } + catch (Exception) + { + targetFolder = null; + Expression> expressionRelativeUrl = l => l.RootFolder.ServerRelativeUrl; + var query = _targetContext.Web.Lists.IncludeWithDefaultProperties(expressionRelativeUrl); + var lists = _targetContext.LoadQuery(query); + _targetContext.ExecuteQueryRetry(); + lists = lists.OrderByDescending(l => l.RootFolder.ServerRelativeUrl); // order descending in case more lists start with the same + foreach (List targetList in lists) { - if (!SkipSourceFolderName && targetFolderExists) - { - targetFolder = targetFolder.EnsureFolder(folder.Name); - } - CopyFolder(folder, targetFolder); + if (!TargetUrl.StartsWith(targetList.RootFolder.ServerRelativeUrl, StringComparison.InvariantCultureIgnoreCase)) continue; + fileOrFolderName = Regex.Replace(TargetUrl, _targetContext.Web.ServerRelativeUrl, "", RegexOptions.IgnoreCase).Trim('/'); + targetFolder = srcIsFolder + ? _targetContext.Web.EnsureFolderPath(fileOrFolderName) + : targetList.RootFolder; + break; } - else + } + if (targetFolder == null) throw new Exception("Target does not exist"); + if (srcIsFolder) + { + if (!SkipSourceFolderName && targetFolderExists) { - UploadFile(file, targetFolder, fileOrFolderName); + targetFolder = targetFolder.EnsureFolder(folder.Name); } + CopyFolder(folder, targetFolder); + } + else + { + UploadFile(file, targetFolder, fileOrFolderName); } } +#if !ONPREMISES + /// + /// Allows copying to another site collection + /// + private void CopyToOtherSiteCollection(Uri source, Uri destination) + { + ClientContext.Site.CreateCopyJobs(new[] { source.ToString() }, destination.ToString(), new CopyMigrationOptions + { + IsMoveMode = false, + IgnoreVersionHistory = IgnoreVersionHistory.ToBool(), + NameConflictBehavior = OverwriteIfAlreadyExists.ToBool() ? MigrationNameConflictBehavior.Replace : MigrationNameConflictBehavior.Fail + }); + ClientContext.ExecuteQueryRetry(); + } +#endif + private void CopyFolder(Folder sourceFolder, Folder targetFolder) { sourceFolder.EnsureProperties(f => f.ServerRelativeUrl, f => f.Files, f => f.Folders, folder => folder.Files.Include(f => f.ServerRelativeUrl)); @@ -302,7 +341,6 @@ private void UploadFile(File srcFile, Folder targetFolder, string filename = "") _targetContext.ExecuteQueryRetry(); } - private File UploadFileWithSpecialCharacters(Folder folder, string fileName, System.IO.Stream stream, bool overwriteIfExists) { if (fileName == null) diff --git a/Commands/Files/GetFileVersion.cs b/Commands/Files/GetFileVersion.cs new file mode 100644 index 000000000..2481e72b3 --- /dev/null +++ b/Commands/Files/GetFileVersion.cs @@ -0,0 +1,59 @@ +using Microsoft.SharePoint.Client; +using OfficeDevPnP.Core.Utilities; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using System; +using System.IO; +using System.Management.Automation; +using File = Microsoft.SharePoint.Client.File; + +namespace SharePointPnP.PowerShell.Commands.Files +{ + [Cmdlet(VerbsCommon.Get, "PnPFileVersion", DefaultParameterSetName = "Return as file object")] + [CmdletHelp("Retrieves all versions of a file.", + Category = CmdletHelpCategory.Files, + OutputType = typeof(FileVersion), + OutputTypeLink = "https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee543660(v=office.15)")] + [CmdletExample( + Code = @"PS:> Get-PnPFileVersion -Url Documents/MyDocument.docx", + Remarks = "Retrieves the file version information for the specified file.", + SortOrder = 1)] + public class GetFileVersion : PnPWebCmdlet + { + [Parameter(Mandatory = true)] + public string Url; + + protected override void ExecuteCmdlet() + { + var serverRelativeUrl = string.Empty; + + var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl); + + if (!Url.ToLower().StartsWith(webUrl.ToLower())) + { + serverRelativeUrl = UrlUtility.Combine(webUrl, Url); + } + else + { + serverRelativeUrl = Url; + } + + File file; + +#if ONPREMISES + file = SelectedWeb.GetFileByServerRelativeUrl(serverRelativeUrl); +#else + file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl)); +#endif + + ClientContext.Load(file, f => f.Exists, f => f.Versions.IncludeWithDefaultProperties(i => i.CreatedBy)); + ClientContext.ExecuteQueryRetry(); + + if (file.Exists) + { + var versions = file.Versions; + ClientContext.ExecuteQueryRetry(); + WriteObject(versions); + } + } + } +} diff --git a/Commands/Files/MoveFile.cs b/Commands/Files/MoveFile.cs index 910a90bd5..f1479f774 100644 --- a/Commands/Files/MoveFile.cs +++ b/Commands/Files/MoveFile.cs @@ -6,10 +6,10 @@ namespace SharePointPnP.PowerShell.Commands.Files { - [Cmdlet(VerbsCommon.Move, "PnPFile", SupportsShouldProcess = true)] - [CmdletHelp("Moves a file to a different location", + [Cmdlet(VerbsCommon.Move, "PnPFile", SupportsShouldProcess = true, DefaultParameterSetName = ParameterSet_SITE)] + [CmdletHelp("Moves a file or folder to a different location", #if !ONPREMISES - DetailedDescription = "Allows moving a file to a different location inside the same document library, such as in a subfolder, to a different document library on the same site collection or to a document library on another site collection", + DetailedDescription = "Allows moving a file or folder to a different location inside the same document library, such as in a subfolder, to a different document library on the same site collection or to a document library on another site collection", #else DetailedDescription = "Allows moving a file to a different location inside the same document library, such as in a subfolder or to a different document library on the same site collection. It is not possible to move files between site collections.", #endif @@ -27,6 +27,10 @@ namespace SharePointPnP.PowerShell.Commands.Files Remarks = @"Moves a file named Document.docx located in the document library named ""Shared Documents"" in the current site to the document library named ""Shared Documents"" in another site collection ""otherproject"" allowing it to overwrite an existing file Document.docx in the destination, allowing the fields to be different on the destination document library from the source document library and allowing a lower document version limit on the destination compared to the source.", Code = @"PS:>Move-PnPFile -ServerRelativeUrl ""/sites/project/Shared Documents/Document.docx"" -TargetServerRelativeLibrary ""/sites/otherproject/Shared Documents"" -OverwriteIfAlreadyExists -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination", SortOrder = 3)] + [CmdletExample( + Remarks = @"Moves a folder named Archive located in the document library named ""Shared Documents"" in the current site to the document library named ""Project"" in another site collection ""archive"" not allowing it to overwrite an existing folder named ""Archive"" in the destination, allowing the fields to be different on the destination document library from the source document library and allowing a lower document version limit on the destination compared to the source.", + Code = @"PS:>Move-PnPFile -ServerRelativeUrl ""/sites/project/Shared Documents/Archive"" -TargetServerRelativeLibrary ""/sites/archive/Project"" -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination", + SortOrder = 4)] #endif public class MoveFile : PnPWebCmdlet @@ -39,29 +43,29 @@ public class MoveFile : PnPWebCmdlet [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_SERVER, HelpMessage = "Server relative Url specifying the file to move. Must include the file name.")] #if !ONPREMISES - [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Server relative Url specifying the file to move. Must include the file name.")] + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Server relative Url specifying the file or folder to move. Must include the file name if it regards a file or the folder name if it regards a folder.")] #endif public string ServerRelativeUrl = string.Empty; - [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_SITE, HelpMessage = "Site relative Url specifying the file to move. Must include the file name.")] + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_SITE, HelpMessage = "Site relative Url specifying the file or folder to move. Must include the file or folder name.")] #if !ONPREMISES - [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Site relative Url specifying the file to move. Must include the file name.")] + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Site relative Url specifying the file or folder to move. Must include the file or folder name.")] #endif public string SiteRelativeUrl = string.Empty; - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_SITE, Position = 1, HelpMessage = "Server relative Url where to move the file to. Must include the file name.")] - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_SERVER, Position = 1, HelpMessage = "Server relative Url where to move the file to. Must include the file name.")] + [Parameter(Mandatory = true, ParameterSetName = ParameterSet_SITE, Position = 1, HelpMessage = "Server relative Url where to move the file or folder to. Must include the file or folder name.")] + [Parameter(Mandatory = true, ParameterSetName = ParameterSet_SERVER, Position = 1, HelpMessage = "Server relative Url where to move the file or folder to. Must include the file or folder name.")] public string TargetUrl = string.Empty; #if !ONPREMISES - [Parameter(Mandatory = true, Position = 1, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Server relative url of a document library where to move the file to. Must not include the file name.")] + [Parameter(Mandatory = true, Position = 1, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "Server relative url of a document library where to move the fileor folder to. Must not include the file or folder name.")] public string TargetServerRelativeLibrary = string.Empty; #endif - [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SERVER, HelpMessage = "If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the move operation will be canceled if the file already exists at the TargetUrl location.")] - [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SITE, HelpMessage = "If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the move operation will be canceled if the file already exists at the TargetUrl location.")] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SERVER, HelpMessage = "If provided, if a file or folder already exists at the TargetUrl, it will be overwritten. If omitted, the move operation will be canceled if the file or folder already exists at the TargetUrl location.")] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SITE, HelpMessage = "If provided, if a file or folder already exists at the TargetUrl, it will be overwritten. If omitted, the move operation will be canceled if the file or folder already exists at the TargetUrl location.")] #if !ONPREMISES - [Parameter(Mandatory = false, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "If provided, if a file already exists at the TargetServerRelativeLibrary, it will be overwritten. If omitted, the move operation will be canceled if the file already exists at the TargetServerRelativeLibrary location.")] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_OTHERSITE, HelpMessage = "If provided, if a file or folder already exists at the TargetServerRelativeLibrary, it will be overwritten. If omitted, the move operation will be canceled if the file or folder already exists at the TargetServerRelativeLibrary location.")] #endif public SwitchParameter OverwriteIfAlreadyExists; diff --git a/Commands/Files/MoveFolder.cs b/Commands/Files/MoveFolder.cs index 6eee40c2e..f0c2de22f 100644 --- a/Commands/Files/MoveFolder.cs +++ b/Commands/Files/MoveFolder.cs @@ -7,10 +7,10 @@ namespace SharePointPnP.PowerShell.Commands.Files { [Cmdlet(VerbsCommon.Move, "PnPFolder")] - [CmdletHelp("Move a folder to another location in the current web", + [CmdletHelp("Move a folder to another location in the current web. If you want to move a folder to a different site collection, use the Move-PnPFile cmdlet instead, which also supports moving folders and also accross site collections.", Category = CmdletHelpCategory.Files, OutputType = typeof(Folder), - OutputTypeLink = "https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.folder.aspx" + OutputTypeLink = "https://docs.microsoft.com/previous-versions/office/sharepoint-server/ee538057(v=office.15)" )] [CmdletExample( Code = @"PS:> Move-PnPFolder -Folder Documents/Reports -TargetFolder 'Archived Reports'", diff --git a/Commands/Files/RemoveFileVersion.cs b/Commands/Files/RemoveFileVersion.cs new file mode 100644 index 000000000..7acb03aca --- /dev/null +++ b/Commands/Files/RemoveFileVersion.cs @@ -0,0 +1,116 @@ +using Microsoft.SharePoint.Client; +using OfficeDevPnP.Core.Utilities; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; +using File = Microsoft.SharePoint.Client.File; +using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; + +namespace SharePointPnP.PowerShell.Commands.Files +{ + [Cmdlet(VerbsCommon.Remove, "PnPFileVersion", DefaultParameterSetName = "Return as file object")] + [CmdletHelp("Removes all or a specific file version.", + Category = CmdletHelpCategory.Files)] + [CmdletExample( + Code = @"PS:> Remove-PnPFileVersion -Url Documents/MyDocument.docx -Identity 512", + Remarks = "Removes the file version with Id 512", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Remove-PnPFileVersion -Url Documents/MyDocument.docx -Identity ""Version 1.0""", + Remarks = "Removes the file version with label \"Version 1.0\"", + SortOrder = 2)] + [CmdletExample( + Code = @"PS:> Remove-PnPFileVersion -Url Documents/MyDocument.docx -All", + Remarks = "Removes all file versions", + SortOrder = 2)] + public class RemoveFileVersion : PnPWebCmdlet + { + private const string ParameterSetName_BYID = "By Id"; + private const string ParameterSetName_ALL = "All"; + + [Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)] + public string Url; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSetName_ALL)] + public SwitchParameter All; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSetName_BYID)] + public FileVersionPipeBind Identity; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)] + public SwitchParameter Recycle; + + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be requested and the action will be performed", ParameterSetName = ParameterAttribute.AllParameterSets)] + public SwitchParameter Force; + + + + protected override void ExecuteCmdlet() + { + var serverRelativeUrl = string.Empty; + + var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl); + + if (!Url.ToLower().StartsWith(webUrl.ToLower())) + { + serverRelativeUrl = UrlUtility.Combine(webUrl, Url); + } + else + { + serverRelativeUrl = Url; + } + + File file; + +#if ONPREMISES + file = SelectedWeb.GetFileByServerRelativeUrl(serverRelativeUrl); +#else + file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl)); +#endif + + ClientContext.Load(file, f => f.Exists, f => f.Versions.IncludeWithDefaultProperties(i => i.CreatedBy)); + ClientContext.ExecuteQueryRetry(); + + if (file.Exists) + { + var versions = file.Versions; + + switch (ParameterSetName) + { + case ParameterSetName_ALL: + { + if (Force || ShouldContinue("Remove all versions?", Resources.Confirm)) + { + versions.DeleteAll(); + ClientContext.ExecuteQueryRetry(); + } + break; + } + case ParameterSetName_BYID: + { + if (Force || ShouldContinue("Remove a version?", Resources.Confirm)) + { + if (!string.IsNullOrEmpty(Identity.Label)) + { + versions.DeleteByLabel(Identity.Label); + ClientContext.ExecuteQueryRetry(); + } + else if (Identity.Id != -1) + { + versions.DeleteByID(Identity.Id); + ClientContext.ExecuteQueryRetry(); + } + } + break; + } + } + } + else + { + throw new PSArgumentException("File not found", nameof(Url)); + } + } + } +} + + diff --git a/Commands/Files/RestoreFileVersion.cs b/Commands/Files/RestoreFileVersion.cs new file mode 100644 index 000000000..08e1e7766 --- /dev/null +++ b/Commands/Files/RestoreFileVersion.cs @@ -0,0 +1,91 @@ +using Microsoft.SharePoint.Client; +using OfficeDevPnP.Core.Utilities; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; +using System.Management.Automation; +using File = Microsoft.SharePoint.Client.File; + +namespace SharePointPnP.PowerShell.Commands.Files +{ + [Cmdlet(VerbsData.Restore, "PnPFileVersion", DefaultParameterSetName = "Return as file object")] + [CmdletHelp("Restores a specific file version.", + Category = CmdletHelpCategory.Files)] + [CmdletExample( + Code = @"PS:> Restore-PnPFileVersion -Url Documents/MyDocument.docx -Identity 512", + Remarks = "Restores the file version with Id 512", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Restore-PnPFileVersion -Url Documents/MyDocument.docx -Identity ""Version 1.0""", + Remarks = "Restores the file version with label \"Version 1.0\"", + SortOrder = 2)] + public class RestoreFileVersion : PnPWebCmdlet + { + [Parameter(Mandatory = true)] + public string Url; + + [Parameter(Mandatory = false)] + public FileVersionPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be requested and the action will be performed")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + var serverRelativeUrl = string.Empty; + + var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl); + + if (!Url.ToLower().StartsWith(webUrl.ToLower())) + { + serverRelativeUrl = UrlUtility.Combine(webUrl, Url); + } + else + { + serverRelativeUrl = Url; + } + + File file; + +#if ONPREMISES + file = SelectedWeb.GetFileByServerRelativeUrl(serverRelativeUrl); +#else + file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl)); +#endif + + ClientContext.Load(file, f => f.Exists, f => f.Versions.IncludeWithDefaultProperties(i => i.CreatedBy)); + ClientContext.ExecuteQueryRetry(); + + if (file.Exists) + { + var versions = file.Versions; + + if (Force || ShouldContinue("Restoring a previous version will overwrite the current version.", Resources.Confirm)) + { + if (!string.IsNullOrEmpty(Identity.Label)) + { + versions.RestoreByLabel(Identity.Label); + ClientContext.ExecuteQueryRetry(); + WriteObject("Version restored"); + } + else if (Identity.Id != -1) + { + var version = versions.GetById(Identity.Id); + ClientContext.Load(version); + ClientContext.ExecuteQueryRetry(); + + versions.RestoreByLabel(version.VersionLabel); + ClientContext.ExecuteQueryRetry(); + WriteObject("Version restored"); + } + } + } + else + { + throw new PSArgumentException("File not found", nameof(Url)); + } + } + } +} + + diff --git a/Commands/Graph/AddMicrosoft365GroupMember.cs b/Commands/Graph/AddMicrosoft365GroupMember.cs new file mode 100644 index 000000000..ed38053ea --- /dev/null +++ b/Commands/Graph/AddMicrosoft365GroupMember.cs @@ -0,0 +1,53 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Add, "PnPMicrosoft365GroupMember")] + [Alias("Add-PnPUnifiedGroupMember")] + [CmdletHelp("Adds members to a particular Microsoft 365 Group", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Add-PnPMicrosoft365GroupMember -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com""", + Remarks = @"Adds the provided two users as additional members to the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Add-PnPMicrosoft365GroupMember -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com"" -RemoveExisting", + Remarks = @"Sets the provided two users as the only members of the Microsoft 365 Group named ""Project Team"" by removing any current existing members first", + SortOrder = 2)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-post-members")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.None, MicrosoftGraphApiPermission.User_ReadWrite_All | MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class AddMicrosoft365GroupMember : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to add members to")] + public Microsoft365GroupPipeBind Identity; + + [Parameter(Mandatory = true, HelpMessage = "The UPN(s) of the user(s) to add to the Microsoft 365 Group as a member")] + public string[] Users; + + [Parameter(Mandatory = false, HelpMessage = "If provided, all existing members will be removed and only those provided through Users will become members")] + public SwitchParameter RemoveExisting; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.AddUnifiedGroupMembers(group.GroupId, Users, AccessToken, RemoveExisting.ToBool()); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/AddMicrosoft365GroupOwner.cs b/Commands/Graph/AddMicrosoft365GroupOwner.cs new file mode 100644 index 000000000..8646f7eba --- /dev/null +++ b/Commands/Graph/AddMicrosoft365GroupOwner.cs @@ -0,0 +1,54 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Add, "PnPMicrosoft365GroupOwner")] + [Alias("Add-PnPUnifiedGroupOwner")] + [CmdletHelp("Adds owners to a particular Microsoft 365 Group", + Category = CmdletHelpCategory.Graph, + OutputTypeLink = "https://docs.microsoft.com/graph/api/group-post-owners", + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Add-PnPMicrosoft365GroupOwner -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com""", + Remarks = @"Adds the provided two users as additional owners to the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Add-PnPMicrosoft365GroupOwner -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com"" -RemoveExisting", + Remarks = @"Sets the provided two users as the only owners of the Microsoft 365 Group named ""Project Team"" by removing any current existing owners first", + SortOrder = 2)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-post-owners")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.None, MicrosoftGraphApiPermission.User_ReadWrite_All | MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class AddMicrosoft365GroupOwner : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to add owners to")] + public Microsoft365GroupPipeBind Identity; + + [Parameter(Mandatory = true, HelpMessage = "The UPN(s) of the user(s) to add to the Microsoft 365 Group as an owner")] + public string[] Users; + + [Parameter(Mandatory = false, HelpMessage = "If provided, all existing owners will be removed and only those provided through Users will become owners")] + public SwitchParameter RemoveExisting; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.AddUnifiedGroupOwners(group.GroupId, Users, AccessToken, RemoveExisting.ToBool()); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/AddSiteClassification.cs b/Commands/Graph/AddSiteClassification.cs index c312a75a6..2133790f2 100644 --- a/Commands/Graph/AddSiteClassification.cs +++ b/Commands/Graph/AddSiteClassification.cs @@ -8,17 +8,15 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsCommon.Add, "PnPSiteClassification")] - [CmdletHelp("Adds one ore more site classification values to the list of possible values. Requires a connection to the Microsoft Graph.", + [CmdletHelp("Adds one ore more site classification values to the list of possible values", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Add-PnPSiteClassification -Classifications ""Top Secret""", + Code = @"PS:> Add-PnPSiteClassification -Classifications ""Top Secret""", Remarks = @"Adds the ""Top Secret"" classification to the already existing classification values.", SortOrder = 1)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Add-PnPSiteClassification -Classifications ""Top Secret"",""HBI""", + Code = @"PS:> Add-PnPSiteClassification -Classifications ""Top Secret"",""HBI""", Remarks = @"Adds the ""Top Secret"" and the ""For Your Eyes Only"" classification to the already existing classification values.", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] diff --git a/Commands/Graph/ClearMicrosoft365GroupMember.cs b/Commands/Graph/ClearMicrosoft365GroupMember.cs new file mode 100644 index 000000000..e8db74fbd --- /dev/null +++ b/Commands/Graph/ClearMicrosoft365GroupMember.cs @@ -0,0 +1,43 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Clear, "PnPMicrosoft365GroupMember")] + [Alias("Clear-PnPMicrosoft365GroupMember")] + [CmdletHelp("Removes all current members from a particular Microsoft 365 Group", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Clear-PnPMicrosoft365GroupMember -Identity ""Project Team""", + Remarks = @"Removes all the current members from the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-delete-members")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All | MicrosoftGraphApiPermission.GroupMember_ReadWrite_All)] + public class ClearMicrosoft365GroupMember : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to remove all members from")] + public Microsoft365GroupPipeBind Identity; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.ClearUnifiedGroupMembers(group.GroupId, AccessToken); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/ClearMicrosoft365GroupOwner.cs b/Commands/Graph/ClearMicrosoft365GroupOwner.cs new file mode 100644 index 000000000..be4f0b88a --- /dev/null +++ b/Commands/Graph/ClearMicrosoft365GroupOwner.cs @@ -0,0 +1,43 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Clear, "PnPMicrosoft365GroupOwner")] + [Alias("Clear-PnPUnifiedGroupOwner")] + [CmdletHelp("Removes all current owners from a particular Microsoft 365 Group (aka Unified Group)", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Clear-PnPMicrosoft365GroupOwner -Identity ""Project Team""", + Remarks = @"Removes all the current owners from the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-delete-owners")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + public class ClearMicrosoft365GroupOwner : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to remove all owners from")] + public Microsoft365GroupPipeBind Identity; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.ClearUnifiedGroupOwners(group.GroupId, AccessToken); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/DisableSiteClassification.cs b/Commands/Graph/DisableSiteClassification.cs index e7a39ab7e..5385ca32b 100644 --- a/Commands/Graph/DisableSiteClassification.cs +++ b/Commands/Graph/DisableSiteClassification.cs @@ -7,12 +7,11 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsLifecycle.Disable, "PnPSiteClassification")] - [CmdletHelp("Disables Site Classifications for the tenant. Requires a connection to the Microsoft Graph.", + [CmdletHelp("Disables Site Classifications for the tenant", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Disable-PnPSiteClassification", + Code = @"PS:> Disable-PnPSiteClassification", Remarks = @"Disables Site Classifications for your tenant.", SortOrder = 1)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] diff --git a/Commands/Graph/EnableSiteClassification.cs b/Commands/Graph/EnableSiteClassification.cs index 73749176e..f118e0841 100644 --- a/Commands/Graph/EnableSiteClassification.cs +++ b/Commands/Graph/EnableSiteClassification.cs @@ -7,7 +7,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsLifecycle.Enable, "PnPSiteClassification")] - [CmdletHelp("Enables Site Classifications for the tenant. Requires a connection to the Microsoft Graph.", + [CmdletHelp("Enables Site Classifications for the tenant", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( diff --git a/Commands/Graph/GetAADUser.cs b/Commands/Graph/GetAADUser.cs index a506d81af..92113070c 100644 --- a/Commands/Graph/GetAADUser.cs +++ b/Commands/Graph/GetAADUser.cs @@ -8,8 +8,9 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsCommon.Get, "PnPAADUser", DefaultParameterSetName = ParameterSet_LIST)] - [CmdletHelp("Gets users from Azure Active Directory. Requires the Azure Active Directory application permission 'User.Read.All'.", + [CmdletHelp("Retrieves users from Azure Active Directory", Category = CmdletHelpCategory.Graph, + OutputTypeLink = "https://docs.microsoft.com/graph/api/user-get", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( Code = "PS:> Get-PnPAADUser", @@ -43,6 +44,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph Code = "PS:> Get-PnPAADUser -Delta -DeltaToken abcdef", Remarks = "Retrieves all the users from Azure Active Directory which have had changes since the provided DeltaToken was given out", SortOrder = 8)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.User_Read_All | MicrosoftGraphApiPermission.User_ReadWrite_All | MicrosoftGraphApiPermission.Directory_Read_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All)] public class GetAADUser : PnPGraphCmdlet { const string ParameterSet_BYID = "Return by specific ID"; diff --git a/Commands/Graph/GetDeletedUnifiedGroup.cs b/Commands/Graph/GetDeletedMicrosoft365Group.cs similarity index 77% rename from Commands/Graph/GetDeletedUnifiedGroup.cs rename to Commands/Graph/GetDeletedMicrosoft365Group.cs index 688944165..61e987d97 100644 --- a/Commands/Graph/GetDeletedUnifiedGroup.cs +++ b/Commands/Graph/GetDeletedMicrosoft365Group.cs @@ -9,24 +9,24 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Get, "PnPDeletedUnifiedGroup")] - - [CmdletHelp("Gets one deleted Microsoft 365 Group (aka Unified Group) or a list of deleted Microsoft 365 Groups", + [Cmdlet(VerbsCommon.Get, "PnPDeletedMicrosoft365Group")] + [Alias("Get-PnPDeletedUnifiedGroup")] + [CmdletHelp("Gets one deleted Microsoft 365 Group or a list of deleted Microsoft 365 Groups", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Get-PnPDeletedUnifiedGroup", + Code = "PS:> Get-PnPDeletedMicrosoft365Group", Remarks = "Retrieves all deleted Microsoft 365 Groups", SortOrder = 1)] [CmdletExample( - Code = "PS:> Get-PnPDeletedUnifiedGroup -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", + Code = "PS:> Get-PnPDeletedMicrosoft365Group -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", Remarks = "Retrieves a specific deleted Microsoft 365 Group based on its ID", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.Group_Read_All)] - public class GetDeletedUnifiedGroup : PnPGraphCmdlet + public class GetDeletedMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = false, HelpMessage = "The Identity of the Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { diff --git a/Commands/Graph/GetGraphSubscription.cs b/Commands/Graph/GetGraphSubscription.cs index 93eaffb53..2b93dc6ef 100644 --- a/Commands/Graph/GetGraphSubscription.cs +++ b/Commands/Graph/GetGraphSubscription.cs @@ -9,6 +9,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph [Cmdlet(VerbsCommon.Get, "PnPGraphSubscription", DefaultParameterSetName = ParameterSet_LIST)] [CmdletHelp("Gets subscriptions from Microsoft Graph. Requires the Azure Active Directory application permission 'Subscription.Read.All'.", Category = CmdletHelpCategory.Graph, + OutputTypeLink = "https://docs.microsoft.com/graph/api/subscription-get", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( Code = "PS:> Get-PnPGraphSubscription", @@ -18,6 +19,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph Code = "PS:> Get-PnPGraphSubscription -Identity 328c7693-5524-44ac-a946-73e02d6b0f98", Remarks = "Retrieves the subscription from Microsoft Graph with the id 328c7693-5524-44ac-a946-73e02d6b0f98", SortOrder = 2)] + // Deliberately omitting the CmdletMicrosoftGraphApiPermission attribute as permissions vary largely by the subscription type being used public class GetGraphSubscription : PnPGraphCmdlet { const string ParameterSet_BYID = "Return by specific ID"; diff --git a/Commands/Graph/GetUnifiedGroup.cs b/Commands/Graph/GetMicrosoft365Group.cs similarity index 77% rename from Commands/Graph/GetUnifiedGroup.cs rename to Commands/Graph/GetMicrosoft365Group.cs index cba35d65d..94d78f2e6 100644 --- a/Commands/Graph/GetUnifiedGroup.cs +++ b/Commands/Graph/GetMicrosoft365Group.cs @@ -9,40 +9,41 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Get, "PnPUnifiedGroup")] - [CmdletHelp("Gets one Microsoft 365 Group (aka Unified Group) or a list of Microsoft 365 Groups. Requires the Azure Active Directory application permission 'Group.Read.All'.", + [Cmdlet(VerbsCommon.Get, "PnPMicrosoft365Group")] + [Alias("Get-PnPUnifiedGroup")] + [CmdletHelp("Gets one Microsoft 365 Group or a list of Microsoft 365 Groups", Category = CmdletHelpCategory.Graph, OutputTypeLink = "https://docs.microsoft.com/graph/api/group-list", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup", + Code = "PS:> Get-Microsoft365Group", Remarks = "Retrieves all the Microsoft 365 Groups", SortOrder = 1)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup -Identity $groupId", + Code = "PS:> Get-Microsoft365Group -Identity $groupId", Remarks = "Retrieves a specific Microsoft 365 Group based on its ID", SortOrder = 2)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup -Identity $groupDisplayName", + Code = "PS:> Get-Microsoft365Group -Identity $groupDisplayName", Remarks = "Retrieves a specific or list of Microsoft 365 Groups that start with the given DisplayName", SortOrder = 3)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup -Identity $groupSiteMailNickName", + Code = "PS:> Get-Microsoft365Group -Identity $groupSiteMailNickName", Remarks = "Retrieves a specific or list of Microsoft 365 Groups for which the email starts with the provided mail nickName", SortOrder = 4)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup -Identity $group", + Code = "PS:> Get-Microsoft365Group -Identity $group", Remarks = "Retrieves a specific Microsoft 365 Group based on its object instance", SortOrder = 5)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup -IncludeIfHasTeam", + Code = "PS:> Get-Microsoft365Group -IncludeIfHasTeam", Remarks = "Retrieves all the Microsoft 365 Groups and checks for each of them if it has a Microsoft Team provisioned for it", SortOrder = 6)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All | MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.GroupMember_ReadWrite_All | MicrosoftGraphApiPermission.GroupMember_Read_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All | MicrosoftGraphApiPermission.Directory_Read_All)] - public class GetUnifiedGroup : PnPGraphCmdlet + public class GetMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = false, HelpMessage = "The Identity of the Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; [Parameter(Mandatory = false, HelpMessage = "Exclude fetching the site URL for Microsoft 365 Groups. This speeds up large listings.")] public SwitchParameter ExcludeSiteUrl; @@ -65,7 +66,7 @@ protected override void ExecuteCmdlet() else { // Retrieve all the groups - groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, includeSite: !ExcludeSiteUrl.IsPresent, includeClassification:IncludeClassification.IsPresent, includeHasTeam: IncludeHasTeam.IsPresent); + groups = UnifiedGroupsUtility.GetUnifiedGroups(AccessToken, includeSite: !ExcludeSiteUrl.IsPresent, includeClassification:IncludeClassification.IsPresent, includeHasTeam: IncludeHasTeam.IsPresent); } if (group != null) diff --git a/Commands/Graph/GetUnifiedGroupMembers.cs b/Commands/Graph/GetMicrosoft365GroupMembers.cs similarity index 83% rename from Commands/Graph/GetUnifiedGroupMembers.cs rename to Commands/Graph/GetMicrosoft365GroupMembers.cs index 098ea4d63..4f8ddc944 100644 --- a/Commands/Graph/GetUnifiedGroupMembers.cs +++ b/Commands/Graph/GetMicrosoft365GroupMembers.cs @@ -9,24 +9,25 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Get, "PnPUnifiedGroupMembers")] + [Cmdlet(VerbsCommon.Get, "PnPMicrosoft365GroupMembers")] + [Alias("Get-PnPUnifiedGroupMembers")] [CmdletHelp("Gets members of a particular Microsoft 365 Group (aka Unified Group). Requires the Azure Active Directory application permissions 'Group.Read.All' and 'User.Read.All'.", Category = CmdletHelpCategory.Graph, OutputTypeLink = "https://docs.microsoft.com/graph/api/group-list-members", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroupMembers -Identity $groupId", + Code = "PS:> Get-PnPMicrosoft365GroupMembers -Identity $groupId", Remarks = "Retrieves all the members of a specific Microsoft 365 Group based on its ID", SortOrder = 1)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroupMembers -Identity $group", + Code = "PS:> Get-PnPMicrosoft365GroupMembers -Identity $group", Remarks = "Retrieves all the members of a specific Microsoft 365 Group based on the group's object instance", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All | MicrosoftGraphApiPermission.Directory_Read_All | MicrosoftGraphApiPermission.GroupMember_Read_All | MicrosoftGraphApiPermission.GroupMember_ReadWrite_All | MicrosoftGraphApiPermission.User_Read_All | MicrosoftGraphApiPermission.User_ReadWrite_All | MicrosoftGraphApiPermission.Group_Read_All | MicrosoftGraphApiPermission.Group_ReadWrite_All)] - public class GetUnifiedGroupMembers : PnPGraphCmdlet + public class GetMicrosoft365GroupMembers : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { @@ -39,12 +40,10 @@ protected override void ExecuteCmdlet() if (group != null) { - // Get members of the group. - + // Get members of the group List members = UnifiedGroupsUtility.GetUnifiedGroupMembers(group, AccessToken); WriteObject(members); } - } } } diff --git a/Commands/Graph/GetUnifiedGroupOwners.cs b/Commands/Graph/GetMicrosoft365GroupOwners.cs similarity index 79% rename from Commands/Graph/GetUnifiedGroupOwners.cs rename to Commands/Graph/GetMicrosoft365GroupOwners.cs index a52732b4f..d742f6eac 100644 --- a/Commands/Graph/GetUnifiedGroupOwners.cs +++ b/Commands/Graph/GetMicrosoft365GroupOwners.cs @@ -9,24 +9,25 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Get, "PnPUnifiedGroupOwners")] - [CmdletHelp("Gets owners of a particular Microsoft 365 Group (aka Unified Group). Requires the Azure Active Directory application permissions 'Group.Read.All' and 'User.Read.All'.", + [Cmdlet(VerbsCommon.Get, "PnPMicrosoft365GroupOwners")] + [Alias("Get-PnPUnifiedGroupOwners")] + [CmdletHelp("Gets owners of a particular Microsoft 365 Group", Category = CmdletHelpCategory.Graph, OutputTypeLink = "https://docs.microsoft.com/graph/api/group-list-owners", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroupOwners -Identity $groupId", + Code = "PS:> Get-PnPMicrosoft365GroupOwners -Identity $groupId", Remarks = "Retrieves all the owners of a specific Microsoft 365 Group based on its ID", SortOrder = 1)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroupOwners -Identity $group", + Code = "PS:> Get-PnPMicrosoft365GroupOwners -Identity $group", Remarks = "Retrieves all the owners of a specific Microsoft 365 Group based on the group's object instance", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All | MicrosoftGraphApiPermission.User_Read_All | MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.User_ReadWrite_All)] - public class GetUnifiedGroupOwners : PnPGraphCmdlet + public class GetMicrosoft365GroupOwners : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group.")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { @@ -39,12 +40,10 @@ protected override void ExecuteCmdlet() if (group != null) { - // Get Owners of the group. - + // Get Owners of the group List owners = UnifiedGroupsUtility.GetUnifiedGroupOwners(group, AccessToken); WriteObject(owners); } - } } } diff --git a/Commands/Graph/GetSiteClassification.cs b/Commands/Graph/GetSiteClassification.cs index 60ab5c28c..bff81485a 100644 --- a/Commands/Graph/GetSiteClassification.cs +++ b/Commands/Graph/GetSiteClassification.cs @@ -7,12 +7,11 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsCommon.Get, "PnPSiteClassification")] - [CmdletHelp("Returns the defined Site Classifications for the tenant. Requires a connection to the Microsoft Graph.", + [CmdletHelp("Returns the defined Site Classifications for the tenant", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Get-PnPSiteClassification", + Code = @"PS:> Get-PnPSiteClassification", Remarks = @"Returns the currently set site classifications for the tenant.", SortOrder = 1)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All | MicrosoftGraphApiPermission.Directory_Read_All)] diff --git a/Commands/Graph/NewGraphSubscription.cs b/Commands/Graph/NewGraphSubscription.cs index 855524a52..f8dd598c9 100644 --- a/Commands/Graph/NewGraphSubscription.cs +++ b/Commands/Graph/NewGraphSubscription.cs @@ -21,6 +21,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph Code = "PS:> New-PnPGraphSubscription -ChangeType Updates -NotificationUrl https://mywebapiservice/notifications -Resource \"Users\" -ExpirationDateTime (Get-Date).AddHours(1) -ClientState [Guid]::NewGuid().ToString()", Remarks = "Creates a new Microsoft Graph subscription listening for changes to user objects during the next hour and will signal the URL provided through NotificationUrl when a change has been made", SortOrder = 2)] + // Deliberately omitting the CmdletMicrosoftGraphApiPermission attribute as permissions vary largely by the subscription type being used public class NewGraphSubscription : PnPGraphCmdlet { [Parameter(Mandatory = true, HelpMessage = "The event(s) the subscription should trigger on")] diff --git a/Commands/Graph/NewUnifiedGroup.cs b/Commands/Graph/NewMicrosoft365Group.cs similarity index 79% rename from Commands/Graph/NewUnifiedGroup.cs rename to Commands/Graph/NewMicrosoft365Group.cs index 38c0749f8..17521f1db 100644 --- a/Commands/Graph/NewUnifiedGroup.cs +++ b/Commands/Graph/NewMicrosoft365Group.cs @@ -9,29 +9,30 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.New, "PnPUnifiedGroup")] - [CmdletHelp("Creates a new Microsoft 365 Group (aka Unified Group). Requires the Azure Active Directory application permission 'Group.ReadWrite.All'.", + [Cmdlet(VerbsCommon.New, "PnPMicrosoft365Group")] + [Alias("New-PnPUnifiedGroup")] + [CmdletHelp("Creates a new Microsoft 365 Group", Category = CmdletHelpCategory.Graph, - OutputTypeLink = "https://docs.microsoft.com/graph/api/group-post-groups", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> New-PnPUnifiedGroup -DisplayName $displayName -Description $description -MailNickname $nickname", + Code = "PS:> New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -MailNickname $nickname", Remarks = "Creates a public Microsoft 365 Group with all the required properties", SortOrder = 1)] [CmdletExample( - Code = "PS:> New-PnPUnifiedGroup -DisplayName $displayName -Description $description -MailNickname $nickname -Owners $arrayOfOwners -Members $arrayOfMembers", + Code = "PS:> New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -MailNickname $nickname -Owners $arrayOfOwners -Members $arrayOfMembers", Remarks = "Creates a public Microsoft 365 Group with all the required properties, and with a custom list of Owners and a custom list of Members", SortOrder = 2)] [CmdletExample( - Code = "PS:> New-PnPUnifiedGroup -DisplayName $displayName -Description $description -MailNickname $nickname -IsPrivate", + Code = "PS:> New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -MailNickname $nickname -IsPrivate", Remarks = "Creates a private Microsoft 365 Group with all the required properties", SortOrder = 3)] [CmdletExample( - Code = "PS:> New-PnPUnifiedGroup -DisplayName $displayName -Description $description -MailNickname $nickname -Owners $arrayOfOwners -Members $arrayOfMembers -IsPrivate", + Code = "PS:> New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -MailNickname $nickname -Owners $arrayOfOwners -Members $arrayOfMembers -IsPrivate", Remarks = "Creates a private Microsoft 365 Group with all the required properties, and with a custom list of Owners and a custom list of Members", SortOrder = 4)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-post-groups")] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Create | MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All)] - public class NewPnPUnifiedGroup : PnPGraphCmdlet + public class NewPnPMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = true, HelpMessage = "The Display Name of the Microsoft 365 Group")] public String DisplayName; @@ -70,7 +71,7 @@ protected override void ExecuteCmdlet() if (!Force) { - var candidates = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, + var candidates = UnifiedGroupsUtility.GetUnifiedGroups(AccessToken, mailNickname: MailNickname, endIndex: 1); // ListUnifiedGroups retrieves groups with starts-with, so need another check diff --git a/Commands/Graph/RemoveDeletedUnifiedGroup.cs b/Commands/Graph/RemoveDeletedMicrosoft365Group.cs similarity index 71% rename from Commands/Graph/RemoveDeletedUnifiedGroup.cs rename to Commands/Graph/RemoveDeletedMicrosoft365Group.cs index b5caf3e96..63d93eafc 100644 --- a/Commands/Graph/RemoveDeletedUnifiedGroup.cs +++ b/Commands/Graph/RemoveDeletedMicrosoft365Group.cs @@ -7,25 +7,25 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Remove, "PnPDeletedUnifiedGroup")] - - [CmdletHelp("Permanently removes one deleted Microsoft 365 Group (aka Unified Group)", + [Cmdlet(VerbsCommon.Remove, "PnPDeletedMicrosoft365Group")] + [Alias("Remove-PnPDeletedUnifiedGroup")] + [CmdletHelp("Permanently removes one deleted Microsoft 365 Group", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Remove-PnPDeletedUnifiedGroup -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", + Code = "PS:> Remove-PnPDeletedMicrosoft365Group -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", Remarks = "Permanently removes a deleted Microsoft 365 Group based on its ID", SortOrder = 1)] [CmdletExample( - Code = @"PS:> $group = Get-PnPDeletedUnifiedGroup -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f -PS:> Remove-PnPDeletedUnifiedGroup -Identity $group", + Code = @"PS:> $group = Get-PnPDeletedMicrosoft365Group -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f +PS:> Remove-PnPDeletedMicrosoft365Group -Identity $group", Remarks = "Permanently removes the provided deleted Microsoft 365 Group", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] - public class RemoveDeletedUnifiedGroup : PnPGraphCmdlet + public class RemoveDeletedMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the deleted Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { diff --git a/Commands/Graph/RemoveGraphSubscription.cs b/Commands/Graph/RemoveGraphSubscription.cs index 7359be891..752bb50d3 100644 --- a/Commands/Graph/RemoveGraphSubscription.cs +++ b/Commands/Graph/RemoveGraphSubscription.cs @@ -16,6 +16,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph Code = "PS:> Remove-PnPGraphSubscription -Identity bc204397-1128-4911-9d70-1d8bceee39da", Remarks = "Removes the Microsoft Graph subscription with the id 'bc204397-1128-4911-9d70-1d8bceee39da'", SortOrder = 1)] + // Deliberately omitting the CmdletMicrosoftGraphApiPermission attribute as permissions vary largely by the subscription type being used public class RemoveGraphSubscription : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The unique id or an instance of a Microsoft Graph Subscription")] diff --git a/Commands/Graph/RemoveUnifiedGroup.cs b/Commands/Graph/RemoveMicrosoft365Group.cs similarity index 73% rename from Commands/Graph/RemoveUnifiedGroup.cs rename to Commands/Graph/RemoveMicrosoft365Group.cs index 686d41721..0d9305fbc 100644 --- a/Commands/Graph/RemoveUnifiedGroup.cs +++ b/Commands/Graph/RemoveMicrosoft365Group.cs @@ -8,28 +8,29 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Remove, "PnPUnifiedGroup")] - [CmdletHelp("Removes one Microsoft 365 Group (aka Unified Group). Requires the Azure Active Directory application permission 'Group.ReadWrite.All'.", + [Cmdlet(VerbsCommon.Remove, "PnPMicrosoft365Group")] + [Alias("Remove-PnPUnifiedGroup")] + [CmdletHelp("Removes one Microsoft 365 Group", Category = CmdletHelpCategory.Graph, OutputTypeLink = "https://docs.microsoft.com/graph/api/group-delete", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Remove-PnPUnifiedGroup -Identity $groupId", + Code = "PS:> Remove-PnPMicrosoft365Group -Identity $groupId", Remarks = "Removes an Microsoft 365 Group based on its ID", SortOrder = 1)] [CmdletExample( - Code = "PS:> Remove-PnPUnifiedGroup -Identity $group", + Code = "PS:> Remove-PnPMicrosoft365Group -Identity $group", Remarks = "Removes the provided Microsoft 365 Group", SortOrder = 2)] [CmdletExample( - Code = "PS:> Get-PnPUnifiedGroup | ? Visibility -eq \"Public\" | Remove-PnPUnifiedGroup", + Code = "PS:> Get-PnPMicrosoft365Group | ? Visibility -eq \"Public\" | Remove-PnPMicrosoft365Group", Remarks = "Removes all the public Microsoft 365 Groups", SortOrder = 3)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] - public class RemoveUnifiedGroup : PnPGraphCmdlet + public class RemoveMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { diff --git a/Commands/Graph/RemoveMicrosoft365GroupMember.cs b/Commands/Graph/RemoveMicrosoft365GroupMember.cs new file mode 100644 index 000000000..df1739931 --- /dev/null +++ b/Commands/Graph/RemoveMicrosoft365GroupMember.cs @@ -0,0 +1,46 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPMicrosoft365GroupMember")] + [Alias("Remove-PnPUnifiedGroupMember")] + [CmdletHelp("Removes members from a particular Microsoft 365 Group", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Remove-PnPMicrosoft365GroupMember -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com""", + Remarks = @"Removes the provided two users as members from the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-delete-members")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.GroupMember_ReadWrite_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + public class RemoveMicrosoft365GroupMember : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to remove members from")] + public Microsoft365GroupPipeBind Identity; + + [Parameter(Mandatory = true, HelpMessage = "The UPN(s) of the user(s) to remove as members from the Microsoft 365 Group")] + public string[] Users; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.RemoveUnifiedGroupMembers(group.GroupId, Users, AccessToken); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/RemoveMicrosoft365GroupOwner.cs b/Commands/Graph/RemoveMicrosoft365GroupOwner.cs new file mode 100644 index 000000000..3ea830d59 --- /dev/null +++ b/Commands/Graph/RemoveMicrosoft365GroupOwner.cs @@ -0,0 +1,46 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Entities; +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPMicrosoft365GroupOwner")] + [Alias("Remove-PnPUnifiedGroupOwner")] + [CmdletHelp("Removes owners from a particular Microsoft 365 Group", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = @"PS:> Remove-PnPMicrosoft365GroupOwner -Identity ""Project Team"" -Users ""john@contoso.onmicrosoft.com"",""jane@contoso.onmicrosoft.com""", + Remarks = @"Removes the provided two users as owners from the Microsoft 365 Group named ""Project Team""", + SortOrder = 1)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-delete-owners")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All | MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + public class RemoveMicrosoft365GroupOwner : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group to remove owners from")] + public Microsoft365GroupPipeBind Identity; + + [Parameter(Mandatory = true, HelpMessage = "The UPN(s) of the user(s) to remove as owners from the Microsoft 365 Group")] + public string[] Users; + + protected override void ExecuteCmdlet() + { + UnifiedGroupEntity group = null; + + if (Identity != null) + { + group = Identity.GetGroup(AccessToken); + } + + if (group != null) + { + UnifiedGroupsUtility.RemoveUnifiedGroupOwners(group.GroupId, Users, AccessToken); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/RemoveSiteClassification.cs b/Commands/Graph/RemoveSiteClassification.cs index 491b2aa69..5bd0c14d4 100644 --- a/Commands/Graph/RemoveSiteClassification.cs +++ b/Commands/Graph/RemoveSiteClassification.cs @@ -9,17 +9,15 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsCommon.Remove, "PnPSiteClassification")] - [CmdletHelp("Removes one or more existing site classification values from the list of available values. Requires a connection to the Microsoft Graph", + [CmdletHelp("Removes one or more existing site classification values from the list of available values", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Remove-PnPSiteClassification -Classifications ""HBI""", + Code = @"PS:> Remove-PnPSiteClassification -Classifications ""HBI""", Remarks = @"Removes the ""HBI"" site classification from the list of available values.", SortOrder = 1)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Remove-PnPSiteClassification -Classifications ""HBI"", ""Top Secret""", + Code = @"PS:> Remove-PnPSiteClassification -Classifications ""HBI"", ""Top Secret""", Remarks = @"Removes the ""HBI"" site classification from the list of available values.", SortOrder = 2)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] diff --git a/Commands/Graph/ResetMicrosoft365GroupExpiration.cs b/Commands/Graph/ResetMicrosoft365GroupExpiration.cs new file mode 100644 index 000000000..c25b8fff2 --- /dev/null +++ b/Commands/Graph/ResetMicrosoft365GroupExpiration.cs @@ -0,0 +1,34 @@ +#if !ONPREMISES && !NETSTANDARD2_1 +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Reset, "PnPMicrosoft365GroupExpiration")] + [Alias("Reset-PnPUnifiedGroupExpiration")] + [CmdletHelp("Renews the Microsoft 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory", + DetailedDescription = "Renews the Microsoft 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory", + Category = CmdletHelpCategory.Graph, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Reset-PnPMicrosoft365GroupExpiration", + Remarks = "Renews the Microsoft 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory", + SortOrder = 1)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-renew")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All | MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class ResetMicrosoft365GroupExpiration : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Microsoft 365 Group")] + public Microsoft365GroupPipeBind Identity; + + protected override void ExecuteCmdlet() + { + var group = Identity.GetGroup(AccessToken); + UnifiedGroupsUtility.RenewUnifiedGroup(group.GroupId, AccessToken); + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Graph/ResetUnifiedGroupExpiration.cs b/Commands/Graph/ResetUnifiedGroupExpiration.cs deleted file mode 100644 index f7d528bc0..000000000 --- a/Commands/Graph/ResetUnifiedGroupExpiration.cs +++ /dev/null @@ -1,32 +0,0 @@ -#if !ONPREMISES && !NETSTANDARD2_1 -using OfficeDevPnP.Core.Framework.Graph; -using SharePointPnP.PowerShell.CmdletHelpAttributes; -using SharePointPnP.PowerShell.Commands.Base; -using SharePointPnP.PowerShell.Commands.Base.PipeBinds; -using System.Management.Automation; - -namespace SharePointPnP.PowerShell.Commands.Graph -{ - [Cmdlet(VerbsCommon.Reset, "PnPUnifiedGroupExpiration")] - [CmdletHelp("Renews the Office 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory", - DetailedDescription = "Renews the Office 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory. Requires the Azure Active Directory application permission 'Group.ReadWrite.All' or 'Directory.ReadWrite.All'.", - Category = CmdletHelpCategory.Graph, - OutputTypeLink = "https://docs.microsoft.com/graph/api/group-renew", - SupportedPlatform = CmdletSupportedPlatform.Online)] - [CmdletExample( - Code = "PS:> Reset-PnPUnifiedGroupExpiration", - Remarks = "Renews the Office 365 Group by extending its expiration with the number of days defined in the group expiration policy set on the Azure Active Directory", - SortOrder = 1)] - public class ResetUnifiedGroupExpiration : PnPGraphCmdlet - { - [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the Office 365 Group")] - public UnifiedGroupPipeBind Identity; - - protected override void ExecuteCmdlet() - { - var group = Identity.GetGroup(AccessToken); - UnifiedGroupsUtility.RenewUnifiedGroup(group.GroupId, AccessToken); - } - } -} -#endif \ No newline at end of file diff --git a/Commands/Graph/RestoreDeletedUnifiedGroup.cs b/Commands/Graph/RestoreDeletedMicrosoft365Group.cs similarity index 62% rename from Commands/Graph/RestoreDeletedUnifiedGroup.cs rename to Commands/Graph/RestoreDeletedMicrosoft365Group.cs index 47838688c..80acd930c 100644 --- a/Commands/Graph/RestoreDeletedUnifiedGroup.cs +++ b/Commands/Graph/RestoreDeletedMicrosoft365Group.cs @@ -7,25 +7,26 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsData.Restore, "PnPDeletedUnifiedGroup")] - - [CmdletHelp("Restores one deleted Office 365 Group (aka Unified Group)", + [Cmdlet(VerbsData.Restore, "PnPDeletedMicrosoft365Group")] + [Alias("Restore-PnPDeletedUnifiedGroup")] + [CmdletHelp("Restores one deleted Microsoft 365 Group", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = "PS:> Restore-PnPDeletedUnifiedGroup -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", + Code = "PS:> Restore-PnPDeletedMicrosoft365Group -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f", Remarks = "Restores a deleted Microsoft 365 Group based on its ID", SortOrder = 1)] [CmdletExample( - Code = @"PS:> $group = Get-PnPDeletedUnifiedGroup -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f -PS:> Restore-PnPDeletedUnifiedGroup -Identity $group", + Code = @"PS:> $group = Get-PnPDeletedMicrosoft365Group -Identity 38b32e13-e900-4d95-b860-fb52bc07ca7f +PS:> Restore-PnPDeletedMicrosoft365Group -Identity $group", Remarks = "Restores the provided deleted Microsoft 365 Group", SortOrder = 2)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/directory-deleteditems-restore")] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] - public class RestoreDeletedUnifiedGroup : PnPGraphCmdlet + public class RestoreDeletedMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The Identity of the deleted Microsoft 365 Group")] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; protected override void ExecuteCmdlet() { diff --git a/Commands/Graph/SetGraphSubscription.cs b/Commands/Graph/SetGraphSubscription.cs index 9e30196d0..8da9700fd 100644 --- a/Commands/Graph/SetGraphSubscription.cs +++ b/Commands/Graph/SetGraphSubscription.cs @@ -17,6 +17,7 @@ namespace SharePointPnP.PowerShell.Commands.Graph Code = "PS:> Set-PnPGraphSubscription -Identity bc204397-1128-4911-9d70-1d8bceee39da -ExpirationDate \"2020-11-22T18:23:45.9356913Z\"", Remarks = "Updates the Microsoft Graph subscription with the id 'bc204397-1128-4911-9d70-1d8bceee39da' to expire at the mentioned date", SortOrder = 1)] + // Deliberately omitting the CmdletMicrosoftGraphApiPermission attribute as permissions vary largely by the subscription type being used public class SetGraphSubscription : PnPGraphCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The unique id or an instance of a Microsoft Graph Subscription")] diff --git a/Commands/Graph/SetUnifiedGroup.cs b/Commands/Graph/SetMicrosoft365Group.cs similarity index 53% rename from Commands/Graph/SetUnifiedGroup.cs rename to Commands/Graph/SetMicrosoft365Group.cs index 7730d2395..637a48ad6 100644 --- a/Commands/Graph/SetUnifiedGroup.cs +++ b/Commands/Graph/SetMicrosoft365Group.cs @@ -10,36 +10,41 @@ namespace SharePointPnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Set, "PnPUnifiedGroup")] - [CmdletHelp("Sets Microsoft 365 Group (aka Unified Group) properties. Requires the Azure Active Directory application permission 'Group.ReadWrite.All'.", + [Cmdlet(VerbsCommon.Set, "PnPMicrosoft365Group")] + [Alias("Set-PnPUnifiedGroup")] + [CmdletHelp("Sets Microsoft 365 Group properties", Category = CmdletHelpCategory.Graph, - OutputTypeLink = "https://docs.microsoft.com/graph/api/group-update", SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -DisplayName ""My Displayname""", + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $group -DisplayName ""My Displayname""", Remarks = "Sets the display name of the group where $group is a Group entity", SortOrder = 1)] [CmdletExample( - Code = @"PS:> Set-PnPUnifiedGroup -Identity $groupId -Descriptions ""My Description"" -DisplayName ""My DisplayName""", + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $groupId -Descriptions ""My Description"" -DisplayName ""My DisplayName""", Remarks = "Sets the display name and description of a group based upon its ID", SortOrder = 2)] [CmdletExample( - Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -GroupLogoPath "".\MyLogo.png""", - Remarks = "Sets a specific Microsoft 365 Group logo.", + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $group -GroupLogoPath "".\MyLogo.png""", + Remarks = "Sets a specific Microsoft 365 Group logo", SortOrder = 3)] [CmdletExample( - Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -IsPrivate:$false", - Remarks = "Sets a group to be Public if previously Private.", + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $group -IsPrivate:$false", + Remarks = "Sets a group to be Public if previously Private", SortOrder = 4)] [CmdletExample( - Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -Owners demo@contoso.com", - Remarks = "Sets demo@contoso.com as owner of the group.", + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $group -Owners demo@contoso.com", + Remarks = "Sets demo@contoso.com as owner of the group", SortOrder = 5)] + [CmdletExample( + Code = @"PS:> Set-PnPMicrosoft365Group -Identity $group -HideFromOutlookClients:$false", + Remarks = "Ensures the provided group will be shown in Outlook clients", + SortOrder = 6)] + [CmdletRelatedLink(Text = "Documentation", Url = "https://docs.microsoft.com/graph/api/group-update")] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] - public class SetUnifiedGroup : PnPGraphCmdlet + public class SetMicrosoft365Group : PnPGraphCmdlet { [Parameter(Mandatory = true, HelpMessage = "The Identity of the Microsoft 365 Group", ValueFromPipeline = true)] - public UnifiedGroupPipeBind Identity; + public Microsoft365GroupPipeBind Identity; [Parameter(Mandatory = false, HelpMessage = "The DisplayName of the group to set")] public string DisplayName; @@ -56,12 +61,18 @@ public class SetUnifiedGroup : PnPGraphCmdlet [Parameter(Mandatory = false, HelpMessage = "Makes the group private when selected")] public SwitchParameter IsPrivate; - [Parameter(Mandatory = false, HelpMessage = "The path to the logo file of to set")] + [Parameter(Mandatory = false, HelpMessage = "The path to the logo file of to set. Logo must be at least 48 pixels wide and may be at most 4 MB in size. Requires Site.ReadWrite.All permissions.")] public string GroupLogoPath; [Parameter(Mandatory = false, HelpMessage = "Creates a Microsoft Teams team associated with created group")] public SwitchParameter CreateTeam; + [Parameter(Mandatory = false, HelpMessage = "Hides the group from the Global Address List")] + public bool? HideFromAddressLists; + + [Parameter(Mandatory = false, HelpMessage = "Hides the group from Outlook Clients")] + public bool? HideFromOutlookClients; + protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; @@ -88,16 +99,30 @@ protected override void ExecuteCmdlet() { isPrivateGroup = IsPrivate.ToBool(); } - UnifiedGroupsUtility.UpdateUnifiedGroup( - groupId: group.GroupId, - accessToken: AccessToken, - displayName: DisplayName, - description: Description, - owners: Owners, - members: Members, - groupLogo: groupLogoStream, - isPrivate: isPrivateGroup, - createTeam: CreateTeam); + try + { + UnifiedGroupsUtility.UpdateUnifiedGroup( + groupId: group.GroupId, + accessToken: AccessToken, + displayName: DisplayName, + description: Description, + owners: Owners, + members: Members, + groupLogo: groupLogoStream, + isPrivate: isPrivateGroup, + createTeam: CreateTeam); + + if (ParameterSpecified(nameof(HideFromAddressLists)) || ParameterSpecified(nameof(HideFromOutlookClients))) + { + // For this scenario a separate call needs to be made + UnifiedGroupsUtility.SetUnifiedGroupVisibility(group.GroupId, AccessToken, HideFromAddressLists, HideFromOutlookClients); + } + } + catch(Exception e) + { + while (e.InnerException != null) e = e.InnerException; + WriteError(new ErrorRecord(e, "GROUPUPDATEFAILED", ErrorCategory.InvalidOperation, this)); + } } else { @@ -106,4 +131,4 @@ protected override void ExecuteCmdlet() } } } -#endif \ No newline at end of file +#endif diff --git a/Commands/Graph/UpdateSiteClassification.cs b/Commands/Graph/UpdateSiteClassification.cs index 23cfc09ee..3baa3178f 100644 --- a/Commands/Graph/UpdateSiteClassification.cs +++ b/Commands/Graph/UpdateSiteClassification.cs @@ -9,23 +9,20 @@ namespace SharePointPnP.PowerShell.Commands.Graph { [Cmdlet(VerbsData.Update, "PnPSiteClassification")] - [CmdletHelp("Updates Site Classifications for the tenant. Requires a connection to the Microsoft Graph with the permission 'Directory.ReadWrite.All'.", + [CmdletHelp("Updates Site Classifications for the tenant", Category = CmdletHelpCategory.Graph, SupportedPlatform = CmdletSupportedPlatform.Online)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Update-PnPSiteClassification -Classifications ""HBI"",""Top Secret""", + Code = @"PS:> Update-PnPSiteClassification -Classifications ""HBI"",""Top Secret""", Remarks = @"Replaces the existing values of the site classification settings", SortOrder = 1)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Update-PnPSiteClassification -DefaultClassification ""LBI""", + Code = @"PS:> Update-PnPSiteClassification -DefaultClassification ""LBI""", Remarks = @"Sets the default classification value to ""LBI"". This value needs to be present in the list of classification values.", SortOrder = 2)] [CmdletExample( - Code = @"PS:> Connect-PnPOnline -Scopes ""Directory.ReadWrite.All"" -PS:> Update-PnPSiteClassification -UsageGuidelinesUrl https://aka.ms/sppnp", - Remarks = @"sets the usage guideliness URL to the specified URL.", + Code = @"PS:> Update-PnPSiteClassification -UsageGuidelinesUrl https://aka.ms/sppnp", + Remarks = @"sets the usage guideliness URL to the specified URL", SortOrder = 3)] [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] public class UpdateSiteClassification : PnPGraphCmdlet diff --git a/Commands/Lists/GetList.cs b/Commands/Lists/GetList.cs index 1cb813d44..d3f5232b0 100644 --- a/Commands/Lists/GetList.cs +++ b/Commands/Lists/GetList.cs @@ -25,6 +25,10 @@ namespace SharePointPnP.PowerShell.Commands.Lists Code = "PS:> Get-PnPList -Identity Lists/Announcements", Remarks = "Returns a list with the given url", SortOrder = 3)] + [CmdletExample( + Code = @"PS:> Get-PnPList | Where-Object {$_.RootFolder.ServerRelativeUrl -like ""/lists/*""}", + Remarks = @"This examples shows how to do wildcard searches on the list URL. It returns all lists whose URL starts with ""/lists/"" This could also be used to search for strings inside of the URL.", + SortOrder = 4)] public class GetList : PnPWebRetrievalsCmdlet { [Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID, name or Url (Lists/MyList) of the list")] @@ -58,4 +62,4 @@ protected override void ExecuteCmdlet() } } } -} \ No newline at end of file +} diff --git a/Commands/Lists/GetListItem.cs b/Commands/Lists/GetListItem.cs index 550597b25..c73ba2264 100644 --- a/Commands/Lists/GetListItem.cs +++ b/Commands/Lists/GetListItem.cs @@ -32,20 +32,24 @@ namespace SharePointPnP.PowerShell.Commands.Lists SortOrder = 4)] [CmdletExample( Code = "PS:> Get-PnPListItem -List Tasks -Query \"bd6c5b3b-d960-4ee7-a02c-85dc6cd78cc3\"", - Remarks = "Retrieves all list items based on the CAML query specified", + Remarks = "Retrieves all available fields of list items based on the CAML query specified", SortOrder = 5)] + [CmdletExample( + Code = "PS:> Get-PnPListItem -List Tasks -Query \"\"", + Remarks = "Retrieves all list items modified today, retrieving the columns 'Title' and 'Modified'. When you use -Query, you can add a clause to retrieve specific columns (since you cannot use -Fields)", + SortOrder = 6)] [CmdletExample( Code = "PS:> Get-PnPListItem -List Tasks -PageSize 1000", Remarks = "Retrieves all list items from the Tasks list in pages of 1000 items", - SortOrder = 6)] + SortOrder = 7)] [CmdletExample( Code = "PS:> Get-PnPListItem -List Tasks -PageSize 1000 -ScriptBlock { Param($items) $items.Context.ExecuteQuery() } | % { $_.BreakRoleInheritance($true, $true) }", Remarks = "Retrieves all list items from the Tasks list in pages of 1000 items and breaks permission inheritance on each item", - SortOrder = 7)] + SortOrder = 8)] [CmdletExample( Code = "PS:> Get-PnPListItem -List Samples -FolderServerRelativeUrl \"/sites/contosomarketing/Lists/Samples/Demo\"", Remarks = "Retrieves all list items from the Demo folder in the Samples list located in the contosomarketing site collection", - SortOrder = 8)] + SortOrder = 9)] public class GetListItem : PnPWebCmdlet { private const string ParameterSet_BYID = "By Id"; diff --git a/Commands/Lists/RemoveListItem.cs b/Commands/Lists/RemoveListItem.cs index 4a8d6d749..7696d3f3f 100644 --- a/Commands/Lists/RemoveListItem.cs +++ b/Commands/Lists/RemoveListItem.cs @@ -2,43 +2,47 @@ using Microsoft.SharePoint.Client; using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; namespace SharePointPnP.PowerShell.Commands.Lists { [Cmdlet(VerbsCommon.Remove, "PnPListItem", SupportsShouldProcess = true)] [CmdletHelp("Deletes an item from a list", - Category = CmdletHelpCategory.Lists)] + Category = CmdletHelpCategory.Lists, + SupportedPlatform = CmdletSupportedPlatform.All)] [CmdletExample( Code = @"PS:> Remove-PnPListItem -List ""Demo List"" -Identity ""1"" -Force", SortOrder = 1, - Remarks = @"Removes the listitem with id ""1"" from the ""Demo List"" list.")] + Remarks = @"Removes the listitem with id ""1"" from the ""Demo List"" list")] [CmdletExample( Code = @"PS:> Remove-PnPListItem -List ""Demo List"" -Identity ""1"" -Force -Recycle", SortOrder = 2, - Remarks = @"Removes the listitem with id ""1"" from the ""Demo List"" list and saves it in the Recycle Bin.")] + Remarks = @"Removes the listitem with id ""1"" from the ""Demo List"" list and saves it in the Recycle Bin")] public class RemoveListItem : PnPWebCmdlet { - [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID, Title or Url of the list.")] + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID, Title or Url of the list")] public ListPipeBind List; [Parameter(Mandatory = true, HelpMessage = "The ID of the listitem, or actual ListItem object")] public ListItemPipeBind Identity; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "When provided, items will be sent to the recycle bin. When omitted, items will permanently be deleted.")] public SwitchParameter Recycle; - [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question")] public SwitchParameter Force; protected override void ExecuteCmdlet() { var list = List.GetList(SelectedWeb); if (list == null) - throw new PSArgumentException($"No list found with id, title or url '{List}'", "List"); + { + throw new PSArgumentException(string.Format(Resources.ListNotFound, List.ToString())); + } if (Identity != null) { var item = Identity.GetListItem(list); - if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveListItemWithId0,item.Id), Properties.Resources.Confirm)) + if (Force || ShouldContinue(string.Format(Resources.RemoveListItemWithId0, item.Id), Resources.Confirm)) { if (Recycle) { diff --git a/Commands/ManagementApi/GetManagementApiAccessToken.cs b/Commands/ManagementApi/GetManagementApiAccessToken.cs index cc116ed20..fc5477f32 100644 --- a/Commands/ManagementApi/GetManagementApiAccessToken.cs +++ b/Commands/ManagementApi/GetManagementApiAccessToken.cs @@ -29,7 +29,7 @@ public class GetManagementApiAccessToken : BasePSCmdlet protected override void ExecuteCmdlet() { - var officeManagementApiToken = OfficeManagementApiToken.AcquireToken(TenantId, ClientId, ClientSecret); + var officeManagementApiToken = OfficeManagementApiToken.AcquireApplicationToken(TenantId, ClientId, ClientSecret); WriteObject(officeManagementApiToken.AccessToken); } } diff --git a/Commands/Model/AzureApp.cs b/Commands/Model/AzureApp.cs index 1b4826d58..9a3ca7f7c 100644 --- a/Commands/Model/AzureApp.cs +++ b/Commands/Model/AzureApp.cs @@ -115,6 +115,24 @@ public PermissionScopes() Id = "741f803b-c850-494e-b5df-cde7c675a1ca", Identifier = "MSGraph.User.ReadWrite.All" }); + scopes.Add(new PermissionScope() + { + resourceAppId = "00000003-0000-0000-c000-000000000000", + Id = "88e58d74-d3df-44f3-ad47-e89edf4472e4", + Identifier = "MSGraph.AppCatalog.Read.All" + }); + scopes.Add(new PermissionScope() + { + resourceAppId = "00000003-0000-0000-c000-000000000000", + Id = "1ca167d5-1655-44a1-8adf-1414072e1ef9", + Identifier = "MSGraph.AppCatalog.ReadWrite.All" + }); + scopes.Add(new PermissionScope() + { + resourceAppId = "00000003-0000-0000-c000-000000000000", + Id = "3db89e36-7fa6-4012-b281-85f3d9d9fd2e", + Identifier = "MSGraph.AppCatalog.Submit" + }); #endregion #region SPO // SPO diff --git a/Commands/Model/GenericToken.cs b/Commands/Model/GenericToken.cs index 63e4707fe..13cd28f0a 100644 --- a/Commands/Model/GenericToken.cs +++ b/Commands/Model/GenericToken.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Web; using System.Collections.Generic; +using SharePointPnP.PowerShell.Core.Attributes; namespace SharePointPnP.PowerShell.Commands.Model { @@ -52,6 +53,10 @@ public class GenericToken /// public Guid? TenantId { get; protected set; } + /// + /// The type of the token, e.g. Application or Generic + /// + public TokenType TokenType { get; protected set; } /// /// Instantiates a new token /// @@ -78,6 +83,8 @@ public GenericToken(string accesstoken) rolesList.AddRange(scope.Value.Split(' ')); } Roles = rolesList.ToArray(); + + TokenType = ParsedToken.Claims.FirstOrDefault(c => c.Type == "upn") != null ? TokenType.Delegate : TokenType.Application; } private object List() diff --git a/Commands/Model/GraphToken.cs b/Commands/Model/GraphToken.cs index ce8399249..d3084d3a0 100644 --- a/Commands/Model/GraphToken.cs +++ b/Commands/Model/GraphToken.cs @@ -1,7 +1,15 @@ using Microsoft.Identity.Client; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Utilities; using System; +using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Management.Automation; +using System.Runtime.CompilerServices; +using System.Security; using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; namespace SharePointPnP.PowerShell.Commands.Model { @@ -10,6 +18,8 @@ namespace SharePointPnP.PowerShell.Commands.Model /// public class GraphToken : GenericToken { + private static IPublicClientApplication publicClientApplication; + private static IConfidentialClientApplication confidentialClientApplication; /// /// The resource identifier for Microsoft Graph API tokens /// @@ -35,13 +45,13 @@ public GraphToken(string accesstoken) : base(accesstoken) } /// - /// Tries to acquire a Microsoft Graph Access Token + /// Tries to acquire an application Microsoft Graph Access Token /// /// Name of the tenant to acquire the token for (i.e. contoso.onmicrosoft.com). Required. /// ClientId to use to acquire the token. Required. /// Certificate to use to acquire the token. Required. /// instance with the token - public static GenericToken AcquireToken(string tenant, string clientId, X509Certificate2 certificate) + public static GenericToken AcquireApplicationToken(string tenant, string clientId, X509Certificate2 certificate) { if (string.IsNullOrEmpty(tenant)) { @@ -55,21 +65,35 @@ public static GenericToken AcquireToken(string tenant, string clientId, X509Cert { throw new ArgumentNullException(nameof(certificate)); } + AuthenticationResult tokenResult = null; - var app = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithCertificate(certificate).Build(); - var tokenResult = app.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + if (confidentialClientApplication == null) + { + confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithCertificate(certificate).Build(); + } + + var account = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + try + { + tokenResult = confidentialClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, account.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = confidentialClientApplication.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + } return new GraphToken(tokenResult.AccessToken); } /// - /// Tries to acquire a Microsoft Graph Access Token + /// Tries to acquire an application Microsoft Graph Access Token /// /// Name of the tenant to acquire the token for (i.e. contoso.onmicrosoft.com). Required. /// ClientId to use to acquire the token. Required. /// Client Secret to use to acquire the token. Required. /// instance with the token - public static GenericToken AcquireToken(string tenant, string clientId, string clientSecret) + public static GenericToken AcquireApplicationToken(string tenant, string clientId, string clientSecret) { if (string.IsNullOrEmpty(tenant)) { @@ -84,33 +108,164 @@ public static GenericToken AcquireToken(string tenant, string clientId, string c throw new ArgumentNullException(nameof(clientSecret)); } - var app = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithClientSecret(clientSecret).Build(); - var tokenResult = app.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + AuthenticationResult tokenResult = null; + + if (confidentialClientApplication == null) + { + confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithClientSecret(clientSecret).Build(); + } + + var account = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + try + { + tokenResult = confidentialClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, account.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = confidentialClientApplication.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + } + return new GraphToken(tokenResult.AccessToken); + } + + /// + /// Tries to acquire an application Microsoft Graph Access Token for the provided scopes interactively by allowing the user to log in + /// + /// ClientId to use to acquire the token. Required. + /// Array with scopes that should be requested access to. Required. + /// instance with the token + public static GenericToken AcquireApplicationTokenInteractive(string clientId, string[] scopes) + { + if (string.IsNullOrEmpty(clientId)) + { + throw new ArgumentNullException(nameof(clientId)); + } + if (scopes == null || scopes.Length == 0) + { + throw new ArgumentNullException(nameof(scopes)); + } + + + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId).WithDefaultRedirectUri().Build(); + } + + AuthenticationResult tokenResult = null; + + //if (publicClientApplication == null) + //{ + // publicClientApplication = PublicClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}organizations/").WithDefaultRedirectUri().Build(); + + //} + var account = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + try + { + tokenResult = publicClientApplication.AcquireTokenSilent(scopes, account.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = publicClientApplication.AcquireTokenInteractive(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray()).ExecuteAsync().GetAwaiter().GetResult(); + } return new GraphToken(tokenResult.AccessToken); } + public static GraphToken AcquireApplicationTokenDeviceLogin(string clientId, string[] scopes, Action callBackAction) + { + if (string.IsNullOrEmpty(clientId)) + { + throw new ArgumentNullException(nameof(clientId)); + } + if (scopes == null || scopes.Length == 0) + { + throw new ArgumentNullException(nameof(scopes)); + } + + + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId).Build(); + } + + AuthenticationResult tokenResult = null; + + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}organizations/").Build(); + + } + var account = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + try + { + tokenResult = publicClientApplication.AcquireTokenSilent(scopes, account.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + var builder = publicClientApplication.AcquireTokenWithDeviceCode(scopes, result => + { + if (callBackAction != null) + { + callBackAction(result); + } + return Task.FromResult(0); + }); + tokenResult = builder.ExecuteAsync().GetAwaiter().GetResult(); + } + return new GraphToken(tokenResult.AccessToken); + } /// - /// Tries to acquire a Microsoft Graph Access Token for the provided scopes interactively by allowing the user to log in + /// Tries to acquire a delegated Microsoft Graph Access Token for the provided scopes using the provided credentials /// /// ClientId to use to acquire the token. Required. /// Array with scopes that should be requested access to. Required. + /// The username to authenticate with. Required. + /// The password to authenticate with. Required. /// instance with the token - public static GenericToken AcquireTokenInteractive(string clientId, string[] scopes) + public static GenericToken AcquireDelegatedTokenWithCredentials(string clientId, string[] scopes, string username, SecureString securePassword) { - if(string.IsNullOrEmpty(clientId)) + if (string.IsNullOrEmpty(clientId)) { throw new ArgumentNullException(nameof(clientId)); } - if(scopes == null || scopes.Length == 0) + if (scopes == null || scopes.Length == 0) { throw new ArgumentNullException(nameof(scopes)); } + if (string.IsNullOrEmpty(username)) + { + throw new ArgumentNullException(nameof(username)); + } + if (securePassword == null || securePassword.Length == 0) + { + throw new ArgumentNullException(nameof(securePassword)); + } - var app = PublicClientApplicationBuilder.Create(clientId).Build(); - var tokenResult = app.AcquireTokenInteractive(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray()).ExecuteAsync().GetAwaiter().GetResult(); + AuthenticationResult tokenResult = null; + + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}organizations/").Build(); + + } + var account = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + try + { + tokenResult = publicClientApplication.AcquireTokenSilent(scopes, account.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = publicClientApplication.AcquireTokenByUsernamePassword(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray(), username, securePassword).ExecuteAsync().GetAwaiter().GetResult(); + } return new GraphToken(tokenResult.AccessToken); } + + public static void ClearCaches() + { + GraphToken.publicClientApplication = null; + GraphToken.confidentialClientApplication = null; + } } } diff --git a/Commands/Model/OfficeManagementApiToken.cs b/Commands/Model/OfficeManagementApiToken.cs index 556d23dbc..7869cddb1 100644 --- a/Commands/Model/OfficeManagementApiToken.cs +++ b/Commands/Model/OfficeManagementApiToken.cs @@ -1,6 +1,7 @@ using Microsoft.Identity.Client; using System; using System.Linq; +using System.Security; using System.Security.Cryptography.X509Certificates; namespace SharePointPnP.PowerShell.Commands.Model @@ -10,6 +11,9 @@ namespace SharePointPnP.PowerShell.Commands.Model /// public class OfficeManagementApiToken : GenericToken { + private static IPublicClientApplication publicClientApplication; + private static IConfidentialClientApplication confidentialClientApplication; + /// /// The resource identifier for Microsoft Office 365 Management API tokens /// @@ -35,13 +39,13 @@ public OfficeManagementApiToken(string accesstoken) : base(accesstoken) } /// - /// Tries to acquire an Office 365 Management API Access Token + /// Tries to acquire an application Office 365 Management API Access Token /// /// Name or id of the tenant to acquire the token for (i.e. contoso.onmicrosoft.com). Required. /// ClientId to use to acquire the token. Required. /// Certificate to use to acquire the token. Required. /// instance with the token - public static GenericToken AcquireToken(string tenant, string clientId, X509Certificate2 certificate) + public static GenericToken AcquireApplicationToken(string tenant, string clientId, X509Certificate2 certificate) { if (string.IsNullOrEmpty(tenant)) { @@ -56,20 +60,34 @@ public static GenericToken AcquireToken(string tenant, string clientId, X509Cert throw new ArgumentNullException(nameof(certificate)); } - var app = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithCertificate(certificate).Build(); - var tokenResult = app.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + if (confidentialClientApplication == null) + { + confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithCertificate(certificate).Build(); + } + var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + AuthenticationResult tokenResult = null; + + try + { + tokenResult = confidentialClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, accounts.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = confidentialClientApplication.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + } return new OfficeManagementApiToken(tokenResult.AccessToken); } /// - /// Tries to acquire an Office 365 Management API Access Token + /// Tries to acquire an application Office 365 Management API Access Token /// /// Name or id of the tenant to acquire the token for (i.e. contoso.onmicrosoft.com). Required. /// ClientId to use to acquire the token. Required. /// Client Secret to use to acquire the token. Required. /// instance with the token - public static GenericToken AcquireToken(string tenant, string clientId, string clientSecret) + public static GenericToken AcquireApplicationToken(string tenant, string clientId, string clientSecret) { if (string.IsNullOrEmpty(tenant)) { @@ -84,19 +102,34 @@ public static GenericToken AcquireToken(string tenant, string clientId, string c throw new ArgumentNullException(nameof(clientSecret)); } - var app = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithClientSecret(clientSecret).Build(); - var tokenResult = app.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + if (confidentialClientApplication == null) + { + confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithAuthority($"{OAuthBaseUrl}{tenant}").WithClientSecret(clientSecret).Build(); + } + + var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + AuthenticationResult tokenResult = null; + + try + { + tokenResult = confidentialClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, accounts.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = confidentialClientApplication.AcquireTokenForClient(new[] { $"{ResourceIdentifier}/{DefaultScope}" }).ExecuteAsync().GetAwaiter().GetResult(); + } return new OfficeManagementApiToken(tokenResult.AccessToken); } /// - /// Tries to acquire an Office 365 Management API Access Token for the provided scopes interactively by allowing the user to log in + /// Tries to acquire an application Office 365 Management API Access Token for the provided scopes interactively by allowing the user to log in /// /// ClientId to use to acquire the token. Required. /// Array with scopes that should be requested access to. Required. /// instance with the token - public static GenericToken AcquireTokenInteractive(string clientId, string[] scopes) + public static GenericToken AcquireApplicationTokenInteractive(string clientId, string[] scopes) { if (string.IsNullOrEmpty(clientId)) { @@ -107,10 +140,76 @@ public static GenericToken AcquireTokenInteractive(string clientId, string[] sco throw new ArgumentNullException(nameof(scopes)); } - var app = PublicClientApplicationBuilder.Create(clientId).Build(); - var tokenResult = app.AcquireTokenInteractive(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray()).ExecuteAsync().GetAwaiter().GetResult(); + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId).Build(); + } + + var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + AuthenticationResult tokenResult = null; + + try + { + tokenResult = publicClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, accounts.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = publicClientApplication.AcquireTokenInteractive(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray()).ExecuteAsync().GetAwaiter().GetResult(); + } return new OfficeManagementApiToken(tokenResult.AccessToken); } + + /// + /// Tries to acquire a delegated Office 365 Management API Access Token for the provided scopes using the provided credentials + /// + /// ClientId to use to acquire the token. Required. + /// Array with scopes that should be requested access to. Required. + /// The username to authenticate with. Required. + /// The password to authenticate with. Required. + /// instance with the token + public static GenericToken AcquireDelegatedTokenWithCredentials(string clientId, string[] scopes, string username, SecureString securePassword) + { + if (string.IsNullOrEmpty(clientId)) + { + throw new ArgumentNullException(nameof(clientId)); + } + if (scopes == null || scopes.Length == 0) + { + throw new ArgumentNullException(nameof(scopes)); + } + if (string.IsNullOrEmpty(username)) + { + throw new ArgumentNullException(nameof(username)); + } + if (securePassword == null || securePassword.Length == 0) + { + throw new ArgumentNullException(nameof(securePassword)); + } + + + if (publicClientApplication == null) + { + publicClientApplication = PublicClientApplicationBuilder.Create(clientId) + // Delegated Graph token using credentials is only possible against organizational tenants + .WithAuthority($"{OAuthBaseUrl}organizations/") + .Build(); + } + + var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult(); + + AuthenticationResult tokenResult = null; + + try + { + tokenResult = publicClientApplication.AcquireTokenSilent(new[] { $"{ResourceIdentifier}/{DefaultScope}" }, accounts.First()).ExecuteAsync().GetAwaiter().GetResult(); + } + catch + { + tokenResult = publicClientApplication.AcquireTokenByUsernamePassword(scopes.Select(s => $"{ResourceIdentifier}/{s}").ToArray(), username, securePassword).ExecuteAsync().GetAwaiter().GetResult(); + } + return new GraphToken(tokenResult.AccessToken); + } } } diff --git a/Commands/Model/Teams/GraphException.cs b/Commands/Model/Teams/GraphException.cs new file mode 100644 index 000000000..d4456f868 --- /dev/null +++ b/Commands/Model/Teams/GraphException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public class GraphException : Exception + { + public GraphError Error { get; set; } + } + + public class GraphError + { + public string Code { get; set; } + + public string Message { get; set; } + + public GraphError InnerError { get; set; } + + public Dictionary AdditionalData { get; set; } + + public string ThrowSite { get; set; } + } +} diff --git a/Commands/Model/Teams/Group.cs b/Commands/Model/Teams/Group.cs new file mode 100644 index 000000000..6c1da8b42 --- /dev/null +++ b/Commands/Model/Teams/Group.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public class Group + { + public string Id { get; set; } + public string DisplayName { get; set; } + public string MailNickname { get; set; } + public string Description { get; set; } + + [Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))] + public GroupVisibility Visibility { get; set; } + + [JsonProperty("owners@odata.bind")] + public List Owners { get; set; } + + [JsonProperty("members@odata.bind")] + public List Members { get; set; } + + public string Classification { get; set; } + + public bool MailEnabled { get; set; } + + public List GroupTypes { get; set; } + + public bool? SecurityEnabled { get; set; } + } +} diff --git a/Commands/Model/Teams/Team.cs b/Commands/Model/Teams/Team.cs new file mode 100644 index 000000000..fe01a5d3a --- /dev/null +++ b/Commands/Model/Teams/Team.cs @@ -0,0 +1,127 @@ +using Microsoft.Graph; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + /// + /// Defines Team for automated provisiong/update of Microsoft Teams + /// + public class Team + { + #region Public Members + public string DisplayName { get; set; } + + public string Classification { get; set; } + /// + /// The Fun Settings for the Team + /// + public TeamFunSettings FunSettings { get; set; } + + /// + /// The Guest Settings for the Team + /// + public TeamGuestSettings GuestSettings { get; set; } + + /// + /// The Members Settings for the Team + /// + public TeamMemberSettings MemberSettings { get; set; } + + /// + /// The Messaging Settings for the Team + /// + public TeamMessagingSettings MessagingSettings { get; set; } + + /// + /// The Discovery Settings for the Team + /// + public TeamDiscoverySettings DiscoverySettings { get; set; } + + /// + /// Defines the Security settings for the Team + /// + public TeamSecurity Security { get; set; } + + ///// + ///// Defines the Channels for the Team + ///// + //public List Channels { get; private set; } = new List(); + + /// + /// Defines the Apps to install or update on the Team + /// + public List Apps { get; private set; } = new List(); + + public TeamSpecialization? Specialization { get; set; } + + /// + /// Declares the ID of the targt Group/Team to update, optional attribute. Cannot be used together with CloneFrom. + /// + public string GroupId { get; set; } + + /// + /// Declares the ID of another Team to Clone the current Team from + /// + public string CloneFrom { get; set; } + + /// + /// Declares whether the Team is archived or not + /// + public bool? IsArchived { get; set; } + + /// + /// Declares the nickname for the Team, optional attribute + /// + public string MailNickname { get; set; } + + /// + /// Declares the description for the team + /// + public string Description { get; set; } + + public GroupVisibility? Visibility { get; set; } + + #endregion + + } + + public enum GroupVisibility + { + NotSpecified, + Private, + Public + } + + /// + /// The Specialization for the Team + /// + public enum TeamSpecialization + { + /// + /// Default type for a team which gives the standard team experience + /// + None, + /// + /// Team created by an education user. All teams created by education user are of type Edu. + /// + EducationStandard, + /// + /// Team experience optimized for a class. This enables segmentation of features across O365. + /// + EducationClass, + /// + /// Team experience optimized for a PLC. Learn more about PLC here. + /// + EducationProfessionalLearningCommunity, + /// + /// Team type for an optimized experience for staff in an organization, where a staff leader, like a principal, is the admin and teachers are members in a team that comes with a specialized notebook. + /// + EducationStaff + } +} diff --git a/Commands/Model/Teams/TeamApp.cs b/Commands/Model/Teams/TeamApp.cs new file mode 100644 index 000000000..447158ec8 --- /dev/null +++ b/Commands/Model/Teams/TeamApp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamApp + { + public string DisplayName { get; set; } + public string DistributionMethod { get; set; } + public string ExternalId { get; set; } + public string Id { get; set; } + } +} diff --git a/Commands/Model/Teams/TeamAppInstance.cs b/Commands/Model/Teams/TeamAppInstance.cs new file mode 100644 index 000000000..2e3207cf9 --- /dev/null +++ b/Commands/Model/Teams/TeamAppInstance.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public class TeamAppInstance + { + #region Public Members + + /// + /// Defines the unique ID of the App to install or update on the Team + /// + public string AppId { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamChannel.cs b/Commands/Model/Teams/TeamChannel.cs new file mode 100644 index 000000000..de6946840 --- /dev/null +++ b/Commands/Model/Teams/TeamChannel.cs @@ -0,0 +1,55 @@ +using Microsoft.Graph; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamChannel + { + #region Public Members + + /// + /// Defines a collection of Tabs for a Channel in a Team + /// + public List Tabs { get; private set; } + + /// + /// Defines a collection of Resources for Tabs in a Team Channel + /// + public List TabResources { get; private set; } + + /// + /// Defines a collection of Messages for a Team Channe + /// + public List Messages { get; private set; } + + /// + /// Defines the Display Name of the Channel + /// + public string DisplayName { get; set; } + + /// + /// Defines the type of the Channel + /// + public string MembershipType { get; set; } + /// + /// Defines the Description of the Channel + /// + public string Description { get; set; } + + /// + /// Defines whether the Channel is Favorite by default for all members of the Team + /// + public bool? IsFavoriteByDefault { get; set; } + + /// + /// Declares the ID for the Channel + /// + public string Id { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamChannelMessage.cs b/Commands/Model/Teams/TeamChannelMessage.cs new file mode 100644 index 000000000..075ea9bc3 --- /dev/null +++ b/Commands/Model/Teams/TeamChannelMessage.cs @@ -0,0 +1,65 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamChannelMessage + { + public string Id { get; set; } + + public DateTime? CreatedDateTime { get; set; } + + public DateTime? DeletedDateTime { get; set; } + + public DateTime? LastModifiedDateTime { get; set; } + public string Importance { get; set; } = "normal"; + public TeamChannelMessageBody Body { get; set; } = new TeamChannelMessageBody(); + + public TeamChannelMessageFrom From { get; set; } = new TeamChannelMessageFrom(); + } + + public class TeamChannelMessageFrom + { + public User User { get; set; } = new User(); + } + + public class TeamChannelMessageBody + { + + [JsonProperty("contentType")] + private string contentType { get; set; } + + [JsonIgnore] + public TeamChannelMessageContentType ContentType + { + get + { + if (Enum.TryParse(contentType, out TeamChannelMessageContentType ct)) + { + return ct; + } + else + { + return TeamChannelMessageContentType.Text; + } + } + set + { + contentType = value.ToString().ToLower(); + } + } + + public string Content { get; set; } + + } + + public enum TeamChannelMessageContentType + { + Text, + Html + } +} diff --git a/Commands/Model/Teams/TeamChannelType.cs b/Commands/Model/Teams/TeamChannelType.cs new file mode 100644 index 000000000..e9583848c --- /dev/null +++ b/Commands/Model/Teams/TeamChannelType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public enum TeamChannelType + { + Public, + Private + } +} diff --git a/Commands/Model/Teams/TeamDiscoverySettings.cs b/Commands/Model/Teams/TeamDiscoverySettings.cs new file mode 100644 index 000000000..0d530a625 --- /dev/null +++ b/Commands/Model/Teams/TeamDiscoverySettings.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamDiscoverySettings + { + #region Public Members + + /// + /// Defines whether the Team is visible via search and suggestions from the Teams client + /// + public bool? ShowInTeamsSearchAndSuggestions { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamFunSettings.cs b/Commands/Model/Teams/TeamFunSettings.cs new file mode 100644 index 000000000..4a5f39467 --- /dev/null +++ b/Commands/Model/Teams/TeamFunSettings.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamFunSettings + { + #region Private Members + + private string _giphyContentRating; + + #endregion + + #region Public Members + + /// + /// Defines whether Giphys are consented or not + /// + public bool? AllowGiphy { get; set; } + + /// + /// Defines the Content Rating for Giphys + /// + public TeamGiphyContentRating GiphyContentRating { get; set; } + + /// + /// Defines whether Stickers and Memes are consented or not + /// + public bool? AllowStickersAndMemes { get; set; } + + /// + /// Defines whether Custom Memes are consented or not + /// + public bool? AllowCustomMemes { get; set; } + + #endregion + } + + /// + /// Defines the Content Rating for Giphys + /// + public enum TeamGiphyContentRating + { + moderate, + strict + } +} diff --git a/Commands/Model/Teams/TeamGuestSettings.cs b/Commands/Model/Teams/TeamGuestSettings.cs new file mode 100644 index 000000000..02d94bc75 --- /dev/null +++ b/Commands/Model/Teams/TeamGuestSettings.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamGuestSettings + { + #region Public Members + + /// + /// Defines whether Guests are allowed to create Channels or not + /// + public bool? AllowCreateUpdateChannels { get; set; } + + /// + /// Defines whether Guests are allowed to delete Channels or not + /// + public bool? AllowDeleteChannels { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamMemberSettings.cs b/Commands/Model/Teams/TeamMemberSettings.cs new file mode 100644 index 000000000..066266ab7 --- /dev/null +++ b/Commands/Model/Teams/TeamMemberSettings.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamMemberSettings + { + + #region Public Members + + /// + /// Defines if members can add and update channels + /// + public bool? AllowCreateUpdateChannels { get; set; } + + /// + /// Defines if members can delete channels + /// + public bool? AllowDeleteChannels { get; set; } + + /// + /// Defines if members can add and remove apps + /// + public bool? AllowAddRemoveApps { get; set; } + + /// + /// Defines if members can add, update, and remove tabs + /// + public bool? AllowCreateUpdateRemoveTabs { get; set; } + + /// + /// Defines if members can add, update, and remove connectors + /// + public bool? AllowCreateUpdateRemoveConnectors { get; set; } + + /// + /// Defines if members can create private channels + /// + public bool? AllowCreatePrivateChannels { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamMessagingSettings.cs b/Commands/Model/Teams/TeamMessagingSettings.cs new file mode 100644 index 000000000..0037e3bb7 --- /dev/null +++ b/Commands/Model/Teams/TeamMessagingSettings.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamMessagingSettings + { + #region Public Members + + /// + /// Defines if users can edit their messages + /// + public bool? AllowUserEditMessages { get; set; } + + /// + /// Defines if users can delete their messages + /// + public bool? AllowUserDeleteMessages { get; set; } + + /// + /// Defines if owners can delete any message + /// + public bool? AllowOwnerDeleteMessages { get; set; } + + /// + /// Defines if @team mentions are allowed + /// + public bool? AllowTeamMentions { get; set; } + + /// + /// Defines if @channel mentions are allowed + /// + public bool? AllowChannelMentions { get; set; } + + #endregion + + } +} diff --git a/Commands/Model/Teams/TeamSecurity.cs b/Commands/Model/Teams/TeamSecurity.cs new file mode 100644 index 000000000..7bdf28831 --- /dev/null +++ b/Commands/Model/Teams/TeamSecurity.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamSecurity + { + #region Public Members + + /// + /// Defines the Owners of the Team + /// + public List Owners { get; private set; } = new List(); + + /// + /// Declares whether to clear existing owners before adding new ones + /// + public bool ClearExistingOwners { get; set; } + + /// + /// Defines the Members of the Team + /// + public List Members { get; private set; } = new List(); + + /// + /// Declares whether to clear existing members before adding new ones + /// + public bool ClearExistingMembers { get; set; } + + /// + /// Defines whether guests are allowed in the Team + /// + public bool AllowToAddGuests { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamSecurityUser.cs b/Commands/Model/Teams/TeamSecurityUser.cs new file mode 100644 index 000000000..4d88cb1a3 --- /dev/null +++ b/Commands/Model/Teams/TeamSecurityUser.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamSecurityUser + { + #region Public Members + + /// + /// Defines User Principal Name (UPN) of the target user + /// + public string UserPrincipalName { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamSettings.cs b/Commands/Model/Teams/TeamSettings.cs new file mode 100644 index 000000000..8fafc631e --- /dev/null +++ b/Commands/Model/Teams/TeamSettings.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public class TeamCreationInformation + { + public string GroupId { get; set; } + + public string DisplayName { get; set; } + + public string Description { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public GroupVisibility Visibility { get; set; } + + public string Classification { get; set; } + + public bool? Archived { get; set; } + + public bool? AllowGiphy { get; set; } + + public TeamGiphyContentRating GiphyContentRating { get; set; } + + public bool? AllowStickersAndMemes { get; set; } + + public bool? AllowCustomMemes { get; set; } + + public bool? AllowGuestCreateUpdateChannels { get; set; } + + public bool? AllowGuestDeleteChannels { get; set; } + + public bool? AllowCreateUpdateChannels { get; set; } + + public bool? AllowDeleteChannels { get; set; } + + public bool? AllowAddRemoveApps { get; set; } + + public bool? AllowCreateUpdateRemoveTabs { get; set; } + + public bool? AllowCreateUpdateRemoveConnectors { get; set; } + + public bool? AllowUserEditMessages { get; set; } + + public bool? AllowUserDeleteMessages { get; set; } + + public bool? AllowOwnerDeleteMessages { get; set; } + + public bool? AllowTeamMentions { get; set; } + + public bool? AllowChannelMentions { get; set; } + + public bool? ShowInTeamsSearchAndSuggestions { get; set; } + + public TeamCreationInformation() + { + } + + public TeamCreationInformation(Team team) + { + GroupId = team.GroupId; + DisplayName = team.DisplayName; + Description = team.Description; + Visibility = team.Visibility.Value; + Archived = team.IsArchived; + Classification = team.Classification; + AllowGiphy = team.FunSettings.AllowGiphy; + GiphyContentRating = team.FunSettings.GiphyContentRating; + AllowStickersAndMemes = team.FunSettings.AllowStickersAndMemes; + AllowCustomMemes = team.FunSettings.AllowCustomMemes; + AllowGuestCreateUpdateChannels = team.GuestSettings.AllowCreateUpdateChannels; + AllowGuestDeleteChannels = team.GuestSettings.AllowDeleteChannels; + AllowCreateUpdateChannels = team.MemberSettings.AllowCreateUpdateChannels; + AllowDeleteChannels = team.MemberSettings.AllowDeleteChannels; + AllowAddRemoveApps = team.MemberSettings.AllowAddRemoveApps; + AllowCreateUpdateRemoveTabs = team.MemberSettings.AllowCreateUpdateRemoveTabs; + AllowCreateUpdateRemoveConnectors = team.MemberSettings.AllowCreateUpdateRemoveConnectors; + AllowUserEditMessages = team.MessagingSettings.AllowUserEditMessages; + AllowUserDeleteMessages = team.MessagingSettings.AllowUserDeleteMessages; + AllowOwnerDeleteMessages = team.MessagingSettings.AllowOwnerDeleteMessages; + AllowTeamMentions = team.MessagingSettings.AllowTeamMentions; + AllowChannelMentions = team.MessagingSettings.AllowChannelMentions; + ShowInTeamsSearchAndSuggestions = team.DiscoverySettings.ShowInTeamsSearchAndSuggestions; + } + + public Team ToTeam() + { + return new Team + { + FunSettings = new TeamFunSettings + { + AllowGiphy = AllowGiphy, + AllowCustomMemes = AllowCustomMemes, + GiphyContentRating = GiphyContentRating, + AllowStickersAndMemes = AllowStickersAndMemes + }, + GuestSettings = new TeamGuestSettings + { + AllowCreateUpdateChannels = AllowGuestCreateUpdateChannels, + AllowDeleteChannels = AllowGuestDeleteChannels + }, + MemberSettings = new TeamMemberSettings + { + AllowCreateUpdateChannels = AllowCreateUpdateChannels, + AllowDeleteChannels = AllowDeleteChannels, + AllowAddRemoveApps = AllowAddRemoveApps, + AllowCreateUpdateRemoveTabs = AllowCreateUpdateRemoveTabs, + AllowCreateUpdateRemoveConnectors = AllowCreateUpdateRemoveConnectors + }, + MessagingSettings = new TeamMessagingSettings + { + AllowUserEditMessages = AllowUserEditMessages, + AllowUserDeleteMessages = AllowUserDeleteMessages, + AllowOwnerDeleteMessages = AllowOwnerDeleteMessages, + AllowTeamMentions = AllowTeamMentions, + AllowChannelMentions = AllowChannelMentions + }, + DiscoverySettings = new TeamDiscoverySettings + { + ShowInTeamsSearchAndSuggestions = ShowInTeamsSearchAndSuggestions + } + }; + } + + public string ToJsonString() + { + return JsonConvert.SerializeObject(this, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }); + } + } +} diff --git a/Commands/Model/Teams/TeamTab.cs b/Commands/Model/Teams/TeamTab.cs new file mode 100644 index 000000000..50c3771fe --- /dev/null +++ b/Commands/Model/Teams/TeamTab.cs @@ -0,0 +1,55 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamTab + { + private string _displayName; + #region Public Members + + /// + /// Defines the Display Name of the Channel + /// + public string DisplayName + { + get + { + return _displayName; + } + set + { + _displayName = HttpUtility.UrlDecode(value); + } + } + + [JsonProperty("teamsApp@odata.bind")] + public string TeamsApp { get; set; } + /// + /// App definition identifier of the tab + /// + public string TeamsAppId { get; set; } + + /// + /// Allows to remove an already existing Tab + /// + public bool Remove { get; set; } + + /// + /// Defines the Configuration for the Tab + /// + public TeamTabConfiguration Configuration { get; set; } + + /// + /// Declares the ID for the Tab + /// + public string Id { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamTabConfiguration.cs b/Commands/Model/Teams/TeamTabConfiguration.cs new file mode 100644 index 000000000..b3c4b7c3a --- /dev/null +++ b/Commands/Model/Teams/TeamTabConfiguration.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamTabConfiguration + { + #region Public Members + + /// + /// Identifier for the entity hosted by the Tab provider + /// + public string EntityId { get; set; } + + /// + /// Url used for rendering Tab contents in Teams + /// + public string ContentUrl { get; set; } + + + /// + /// Url called by Teams client when a Tab is removed using the Teams Client + /// + public string RemoveUrl { get; set; } + + /// + /// Url for showing Tab contents outside of Teams + /// + public string WebsiteUrl { get; set; } + + #endregion + } +} diff --git a/Commands/Model/Teams/TeamTabResource.cs b/Commands/Model/Teams/TeamTabResource.cs new file mode 100644 index 000000000..70d77dbeb --- /dev/null +++ b/Commands/Model/Teams/TeamTabResource.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamTabResource + { + #region Public Members + + /// + /// Defines the Configuration for the Tab Resource + /// + public string TabResourceSettings { get; set; } + + /// + /// Defines the Type of Resource for the Tab + /// + public TabResourceType Type { get; set; } + + /// + /// Defines the ID of the target Tab for the Resource + /// + public string TargetTabId { get; set; } + + #endregion + } + + /// + /// Defines the Types of Resources for the Tab + /// + public enum TabResourceType + { + /// + /// Defines a Generic resource type + /// + Generic, + /// + /// Defines a Notebook resource type + /// + Notebook, + /// + /// Defines a Planner resource type + /// + Planner, + /// + /// Defines a Schedule resource type + /// + Schedule, + } +} diff --git a/Commands/Model/Teams/TeamTabType.cs b/Commands/Model/Teams/TeamTabType.cs new file mode 100644 index 000000000..e58d3b91d --- /dev/null +++ b/Commands/Model/Teams/TeamTabType.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public enum TeamTabType + { + WebSite, + DocumentLibrary, + Wiki, + Planner, + MicrosoftStream, + MicrosoftForms, + Word, + Excel, + PowerPoint, + PDF, + OneNote, + PowerBI, + SharePointPageAndList, + Custom + } +} diff --git a/Commands/Model/Teams/User.cs b/Commands/Model/Teams/User.cs new file mode 100644 index 000000000..466462883 --- /dev/null +++ b/Commands/Model/Teams/User.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Commands.Model.Teams +{ + public class User : IEquatable + { + public string Id { get; set; } + public string DisplayName { get; set; } + public string UserPrincipalName { get; set; } + public string UserType { get; set; } + + public bool Equals(User other) + { + return this.UserPrincipalName.Equals(other.UserPrincipalName, StringComparison.OrdinalIgnoreCase); + } + } +} diff --git a/Commands/ModuleFiles/SharePointPnP.PowerShell.Core.Format.ps1xml b/Commands/ModuleFiles/PnP.PowerShell.Core.Format.ps1xml similarity index 87% rename from Commands/ModuleFiles/SharePointPnP.PowerShell.Core.Format.ps1xml rename to Commands/ModuleFiles/PnP.PowerShell.Core.Format.ps1xml index 49ef10b99..52afe4aa2 100644 --- a/Commands/ModuleFiles/SharePointPnP.PowerShell.Core.Format.ps1xml +++ b/Commands/ModuleFiles/PnP.PowerShell.Core.Format.ps1xml @@ -1817,5 +1817,269 @@ + + Team + + SharePointPnP.PowerShell.Commands.Model.Teams.Team + + + + + + + + + + + + + + + + + + + + + + + + GroupId + + + DisplayName + + + Visibility + + + IsArchived + + + MailNickname + + + + + + + + TeamChannel + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamChannel + + + + + + + + + + + + + + + + + + + + + ID + + + DisplayName + + + Description + + + MembershipType + + + + + + + + TeamTab + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamTab + + + + + + + + + + + + + + + ID + + + DisplayName + + + + + + + + TeamApp + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamApp + + + + + + + + + + + + + + + + + + + + + ID + + + DisplayName + + + DistributionMethod + + + ExternalId + + + + + + + + TeamChannelMessage + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamChannelMessage + + + + + + + + + + + + + + + + + + ID + + + + $_.Body.Content + + + + CreatedDateTime + + + + + + + + User + + SharePointPnP.PowerShell.Commands.Model.Teams.User + + + + + + + + + + + + + + + + + + + + + Id + + + UserPrincipalName + + + DisplayName + + + UserType + + + + + + + + FileVersion + + Microsoft.SharePoint.Client.FileVersion + + + + + + + + + + + + + + + + + + Id + + + VersionLabel + + + Created + + + + + + \ No newline at end of file diff --git a/Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml b/Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml index 60d97bab7..935d5ca12 100644 --- a/Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml @@ -1335,5 +1335,39 @@ + + FileVersion + + Microsoft.SharePoint.Client.FileVersion + + + + + + + + + + + + + + + + + + Id + + + VersionLabel + + + Created + + + + + + \ No newline at end of file diff --git a/Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml b/Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml index 60d97bab7..935d5ca12 100644 --- a/Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml @@ -1335,5 +1335,39 @@ + + FileVersion + + Microsoft.SharePoint.Client.FileVersion + + + + + + + + + + + + + + + + + + Id + + + VersionLabel + + + Created + + + + + + \ No newline at end of file diff --git a/Commands/ModuleFiles/SharePointPnP.PowerShell.2019.Commands.Format.ps1xml b/Commands/ModuleFiles/SharePointPnP.PowerShell.2019.Commands.Format.ps1xml index 1eec4e79f..c2f9fb9f6 100644 --- a/Commands/ModuleFiles/SharePointPnP.PowerShell.2019.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/SharePointPnP.PowerShell.2019.Commands.Format.ps1xml @@ -1469,5 +1469,39 @@ + + FileVersion + + Microsoft.SharePoint.Client.FileVersion + + + + + + + + + + + + + + + + + + Id + + + VersionLabel + + + Created + + + + + + \ No newline at end of file diff --git a/Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml b/Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml index 1c915374c..51b7c4de8 100644 --- a/Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml @@ -2021,9 +2021,9 @@ - BaseTeam + Team - OfficeDevPnP.Core.Framework.Provisioning.Model.Teams.BaseTeam + SharePointPnP.PowerShell.Commands.Model.Teams.Team @@ -2037,14 +2037,11 @@ - + - - - @@ -2059,14 +2056,11 @@ Visibility - Archived + IsArchived MailNickname - - Description - @@ -2075,7 +2069,7 @@ TeamChannel - OfficeDevPnP.Core.Framework.Provisioning.Model.Teams.TeamChannel + SharePointPnP.PowerShell.Commands.Model.Teams.TeamChannel @@ -2109,7 +2103,7 @@ TeamTab - OfficeDevPnP.Core.Framework.Provisioning.Model.Teams.TeamTab + SharePointPnP.PowerShell.Commands.Model.Teams.TeamTab @@ -2134,5 +2128,155 @@ + + TeamApp + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamApp + + + + + + + + + + + + + + + + + + + + + ID + + + DisplayName + + + DistributionMethod + + + ExternalId + + + + + + + + TeamChannelMessage + + SharePointPnP.PowerShell.Commands.Model.Teams.TeamChannelMessage + + + + + + + + + + + + + + + + + + ID + + + + $_.Body.Content + + + + CreatedDateTime + + + + + + + + User + + SharePointPnP.PowerShell.Commands.Model.Teams.User + + + + + + + + + + + + + + + + + + + + + Id + + + UserPrincipalName + + + DisplayName + + + UserType + + + + + + + + FileVersion + + Microsoft.SharePoint.Client.FileVersion + + + + + + + + + + + + + + + + + + Id + + + VersionLabel + + + Created + + + + + + diff --git a/Commands/PnPPowerShell.csproj b/Commands/PnPPowerShell.csproj index 45556dcf0..3099189c9 100644 --- a/Commands/PnPPowerShell.csproj +++ b/Commands/PnPPowerShell.csproj @@ -4,13 +4,16 @@ netstandard2.1 false true - SharePointPnP.PowerShell.Core + PnP.PowerShell.Core SharePointPnP.PowerShell.Commands false + PnP.PowerShell.Core + PnP.PowerShell.Core bin\DebugCore\ + TRACE;NETSTANDARD2_1 @@ -26,6 +29,7 @@ + @@ -33,11 +37,12 @@ - + + @@ -111,7 +116,7 @@ - + Always diff --git a/Commands/Principals/AddUserToGroup.cs b/Commands/Principals/AddUserToGroup.cs index 2d53686bb..e34fd417a 100644 --- a/Commands/Principals/AddUserToGroup.cs +++ b/Commands/Principals/AddUserToGroup.cs @@ -6,15 +6,15 @@ namespace SharePointPnP.PowerShell.Commands.Principals { [Cmdlet(VerbsCommon.Add, "PnPUserToGroup")] - [CmdletHelp("Adds a user to a group", + [CmdletHelp("Adds a user to a SharePoint group", Category = CmdletHelpCategory.Principals)] [CmdletExample( Code = @"PS:> Add-PnPUserToGroup -LoginName user@company.com -Identity 'Marketing Site Members'", - Remarks = @"Add the specified user to the group ""Marketing Site Members""", + Remarks = @"Add the specified user to the SharePoint group ""Marketing Site Members""", SortOrder = 1)] [CmdletExample( Code = @"PS:> Add-PnPUserToGroup -LoginName user@company.com -Identity 5", - Remarks = "Add the specified user to the group with Id 5", + Remarks = "Add the specified user to the SharePoint group with Id 5", SortOrder = 2)] public class AddUserToGroup : PnPWebCmdlet { @@ -22,9 +22,9 @@ public class AddUserToGroup : PnPWebCmdlet [Parameter(Mandatory = true, HelpMessage = "The login name of the user", ParameterSetName = "Internal")] public string LoginName; - [Parameter(Mandatory = true, HelpMessage = "The group id, group name or group object to add the user to.", ValueFromPipeline = true, ParameterSetName = "Internal")] + [Parameter(Mandatory = true, HelpMessage = "The SharePoint group id, SharePoint group name or SharePoint group object to add the user to", ValueFromPipeline = true, ParameterSetName = "Internal")] #if !ONPREMISES - [Parameter(Mandatory = true, HelpMessage = "The group id, group name or group object to add the user to.", ValueFromPipeline = true, ParameterSetName = "External")] + [Parameter(Mandatory = true, HelpMessage = "The SharePoint group id, SharePoint group name or SharePoint group object to add the user to", ValueFromPipeline = true, ParameterSetName = "External")] #endif public GroupPipeBind Identity; diff --git a/Commands/Principals/GetUser.cs b/Commands/Principals/GetUser.cs index 8b6a7c745..a6f8770db 100644 --- a/Commands/Principals/GetUser.cs +++ b/Commands/Principals/GetUser.cs @@ -6,15 +6,16 @@ using SharePointPnP.PowerShell.Commands.Base.PipeBinds; using System.Linq; using System.Collections.Generic; +using System.Xml.Linq; +using System.Data; +using System.Text; namespace SharePointPnP.PowerShell.Commands.Principals { - [Cmdlet(VerbsCommon.Get, "PnPUser")] + [Cmdlet(VerbsCommon.Get, "PnPUser", DefaultParameterSetName = PARAMETERSET_IDENTITY)] [CmdletHelp("Returns site users of current web", Category = CmdletHelpCategory.Principals, - DetailedDescription = "This command will return all users that exist in the current site collection's User Information List", - OutputType = typeof(User), - OutputTypeLink = "https://docs.microsoft.com/previous-versions/office/sharepoint-server/ee540236(v=office.15)", + DetailedDescription = "This command will return all users that exist in the current site collection's User Information List, optionally identifying their current permissions to this site", SupportedPlatform = CmdletSupportedPlatform.All)] [CmdletExample( Code = @"PS:> Get-PnPUser", @@ -40,14 +41,42 @@ namespace SharePointPnP.PowerShell.Commands.Principals Code = @"PS:> Get-PnPUser -WithRightsAssigned -Web subsite1", Remarks = "Returns only those users from the User Information List of the current site collection who currently have any kind of access rights given either directly to the user or Active Directory Group or given to the user or Active Directory Group via membership of a SharePoint Group to subsite 'subsite1'", SortOrder = 6)] +#if !ONPREMISES + [CmdletExample( + Code = @"PS:> Get-PnPUser -WithRightsAssignedDetailed", + Remarks = "Returns all users who have been granted explicit access to the current site, lists and listitems", + SortOrder = 7)] +#endif public class GetUser : PnPWebCmdlet { - [Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0, HelpMessage = "User ID or login name")] + private const string PARAMETERSET_IDENTITY = "Identity based request"; + private const string PARAMETERSET_WITHRIGHTSASSIGNED = "With rights assigned"; +#if !ONPREMISES + private const string PARAMETERSET_WITHRIGHTSASSIGNEDDETAILED = "With rights assigned detailed"; +#endif + + [Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = PARAMETERSET_IDENTITY, HelpMessage = "User ID or login name")] public UserPipeBind Identity; - [Parameter(Mandatory = false, Position = 1, HelpMessage = "If provided, only users that currently have any kinds of access rights assigned to the current site collection will be returned. Otherwise all users, even those who previously had rights assigned, but not anymore at the moment, will be returned as the information is pulled from the User Information List. Only works if you don't provide an -Identity.")] + [Parameter(Mandatory = false, ParameterSetName = PARAMETERSET_WITHRIGHTSASSIGNED, HelpMessage = "If provided, only users that currently have any kinds of access rights assigned to the current site collection will be returned. Otherwise all users, even those who previously had rights assigned, but not anymore at the moment, will be returned as the information is pulled from the User Information List. Only works if you don't provide an -Identity.")] public SwitchParameter WithRightsAssigned; +#if !ONPREMISES + [Parameter(Mandatory = false, ParameterSetName = PARAMETERSET_WITHRIGHTSASSIGNEDDETAILED, HelpMessage = "If provided, only users that currently have any specific kind of access rights assigned to the current site, lists or listitems/documents will be returned. Otherwise all users, even those who previously had rights assigned, but not anymore at the moment, will be returned as the information is pulled from the User Information List. Only works if you don't provide an -Identity.")] + public SwitchParameter WithRightsAssignedDetailed; +#endif + + /// + /// Output type used with parameter WithRightsAssignedDetailed + /// + public class DetailedUser + { + public User User { get; set; } + public string Url { get; set; } + public List Permissions { get; set; } + public GroupCollection Groups { get; set; } + } + protected override void ExecuteCmdlet() { var retrievalExpressions = new Expression>[] @@ -78,7 +107,13 @@ protected override void ExecuteCmdlet() { SelectedWeb.Context.Load(SelectedWeb.SiteUsers, u => u.Include(retrievalExpressions)); - if (WithRightsAssigned) + List users = new List(); + + if (WithRightsAssigned +#if !ONPREMISES + || WithRightsAssignedDetailed +#endif + ) { // Get all the role assignments and role definition bindings to be able to see which users have been given rights directly on the site level SelectedWeb.Context.Load(SelectedWeb.RoleAssignments, ac => ac.Include(a => a.RoleDefinitionBindings, a => a.Member)); @@ -100,14 +135,195 @@ protected override void ExecuteCmdlet() allUsersWithPermissions.AddRange(usersWithDirectPermissions); allUsersWithPermissions.AddRange(usersWithGroupPermissions); - // Filter out the users that have been given rights at both places so they will only be returned once - WriteObject(allUsersWithPermissions.GroupBy(u => u.Id).Select(u => u.First()), true); +#if !ONPREMISES + // Add the found users and add them to the custom object + if (WithRightsAssignedDetailed) + { + SelectedWeb.Context.Load(SelectedWeb, s => s.ServerRelativeUrl); + SelectedWeb.Context.ExecuteQueryRetry(); + + WriteWarning("Using the -WithRightsAssignedDetailed parameter will cause the script to take longer than normal because of the all enumerations that take place"); + users.AddRange(GetPermissions(SelectedWeb.RoleAssignments, SelectedWeb.ServerRelativeUrl)); + foreach (var user in allUsersWithPermissions) + { + users.Add(new DetailedUser() + { + Groups = user.Groups, + User = user, + Url = SelectedWeb.ServerRelativeUrl + }); + } + } + else +#endif + { + // Filter out the users that have been given rights at both places so they will only be returned once + WriteObject(allUsersWithPermissions.GroupBy(u => u.Id).Select(u => u.First()), true); + } } else { SelectedWeb.Context.ExecuteQueryRetry(); WriteObject(SelectedWeb.SiteUsers, true); } + +#if !ONPREMISES + if (WithRightsAssignedDetailed) + { + SelectedWeb.Context.Load(SelectedWeb.Lists, l => l.Include(li => li.ItemCount, li => li.IsSystemList, li=>li.IsCatalog, li => li.RootFolder.ServerRelativeUrl, li => li.RoleAssignments, li => li.Title, li => li.HasUniqueRoleAssignments)); + SelectedWeb.Context.ExecuteQueryRetry(); + + var progress = new ProgressRecord(0, $"Getting lists for {SelectedWeb.ServerRelativeUrl}", "Enumerating through lists"); + var progressCounter = 0; + + foreach (var list in SelectedWeb.Lists) + { + WriteProgress(progress, $"Getting list {list.RootFolder.ServerRelativeUrl}", progressCounter++, SelectedWeb.Lists.Count); + + // ignoring the system lists + if (list.IsSystemList || list.IsCatalog) + { + continue; + } + + // if a list or a library has unique permissions then proceed + if (list.HasUniqueRoleAssignments) + { + WriteVerbose(string.Format("List found with HasUniqueRoleAssignments {0}", list.RootFolder.ServerRelativeUrl)); + string url = list.RootFolder.ServerRelativeUrl; + + SelectedWeb.Context.Load(list.RoleAssignments, r => r.Include( + ra => ra.RoleDefinitionBindings, + ra => ra.Member.LoginName, + ra => ra.Member.Title, + ra => ra.Member.PrincipalType)); + SelectedWeb.Context.ExecuteQueryRetry(); + + users.AddRange(GetPermissions(list.RoleAssignments, url)); + + // if the list with unique permissions also has items, check every item which is uniquely permissioned + if (list.ItemCount > 0) + { + WriteVerbose(string.Format("Enumerating through all listitems of {0}", list.RootFolder.ServerRelativeUrl)); + + CamlQuery query = CamlQuery.CreateAllItemsQuery(); + var queryElement = XElement.Parse(query.ViewXml); + + var rowLimit = queryElement.Descendants("RowLimit").FirstOrDefault(); + if (rowLimit != null) + { + rowLimit.RemoveAll(); + } + else + { + rowLimit = new XElement("RowLimit"); + queryElement.Add(rowLimit); + } + + rowLimit.SetAttributeValue("Paged", "TRUE"); + rowLimit.SetValue(1000); + + query.ViewXml = queryElement.ToString(); + + List items = new List(); + + do + { + var listItems = list.GetItems(query); + SelectedWeb.Context.Load(listItems); + SelectedWeb.Context.ExecuteQueryRetry(); + query.ListItemCollectionPosition = listItems.ListItemCollectionPosition; + + items.Add(listItems); + + } while (query.ListItemCollectionPosition != null); + + // Progress bar for item enumerations + var itemProgress = new ProgressRecord(0, $"Getting items for {list.RootFolder.ServerRelativeUrl}", "Enumerating through items"); + var itemProgressCounter = 0; + + foreach (var item in items) + { + WriteProgress(itemProgress, $"Retrieving items", itemProgressCounter++, items.Count); + + WriteVerbose(string.Format("Enumerating though listitemcollections")); + foreach (var listItem in item) + { + WriteVerbose(string.Format("Enumerating though listitems")); + listItem.EnsureProperty(i => i.HasUniqueRoleAssignments); + + if (listItem.HasUniqueRoleAssignments) + { + string listItemUrl = listItem["FileRef"].ToString(); + WriteVerbose(string.Format("List item {0} HasUniqueRoleAssignments", listItemUrl)); + + SelectedWeb.Context.Load(listItem.RoleAssignments, r => r.Include( + ra => ra.RoleDefinitionBindings, + ra => ra.Member.LoginName, + ra => ra.Member.Title, + ra => ra.Member.PrincipalType)); + SelectedWeb.Context.ExecuteQueryRetry(); + + users.AddRange(GetPermissions(listItem.RoleAssignments, listItemUrl)); + } + } + } + itemProgress.RecordType = ProgressRecordType.Completed; + WriteProgress(itemProgress); + } + } + progress.RecordType = ProgressRecordType.Completed; + WriteProgress(progress); + } + + // Fetch all the unique users from everything that has been collected + var uniqueUsers = (from u in users + select u.User.LoginName).Distinct(); + + // Looping through each user, getting all the details like specific permissions and groups an user belongs to + foreach (var uniqueUser in uniqueUsers) + { + // Getting all the assigned permissions per user + var userPermissions = (from u in users + where u.User.LoginName == uniqueUser && u.Permissions != null + select u).ToList(); + + // Making the permissions readable by getting the name of the permission and the URL of the artifact + Dictionary Permissions = new Dictionary(); + foreach (var userPermission in userPermissions) + { + StringBuilder stringBuilder = new StringBuilder(); + foreach (var permissionMask in userPermission.Permissions) + { + stringBuilder.Append(permissionMask); + } + Permissions.Add(userPermission.Url, stringBuilder.ToString()); + } + + // Getting all the groups where the user is added to + var groupsMemberships = (from u in users + where u.User.LoginName == uniqueUser && u.Groups != null + select u.Groups).ToList(); + + // Getting the titles of the all the groups + List Groups = new List(); + foreach (var groupMembership in groupsMemberships) + { + foreach (var group in groupMembership) + { + Groups.Add(group.Title); + } + } + + // Getting the User object of the user so we can get to the title, loginname, etc + var userInformation = (from u in users + where u.User.LoginName == uniqueUser + select u.User).FirstOrDefault(); + + WriteObject(new { userInformation.Title, userInformation.LoginName, userInformation.Email, Groups, Permissions }, true); + } + } +#endif } else { @@ -132,5 +348,46 @@ protected override void ExecuteCmdlet() WriteObject(user); } } + +#if !ONPREMISES + private void WriteProgress(ProgressRecord record, string message, int step, int count) + { + var percentage = Convert.ToInt32((100 / Convert.ToDouble(count)) * Convert.ToDouble(step)); + record.StatusDescription = message; + record.PercentComplete = percentage; + record.RecordType = ProgressRecordType.Processing; + WriteProgress(record); + } + + private static List GetPermissions(RoleAssignmentCollection roleAssignments, string url) + { + List users = new List(); + foreach (var roleAssignment in roleAssignments) + { + if (roleAssignment.Member.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.User) + { + var detailedUser = new DetailedUser(); + detailedUser.Url = url; + detailedUser.User = roleAssignment.Member as User; + detailedUser.Permissions = new List(); + + foreach (var roleDefinition in roleAssignment.RoleDefinitionBindings) + { + if (roleDefinition.Name == "Limited Access") + continue; + + detailedUser.Permissions.Add(roleDefinition.Name); + } + + // if no permissions are recorded (hence, limited access, skip the adding of the permissions) + if (detailedUser.Permissions.Count == 0) + continue; + + users.Add(detailedUser); + } + } + return users; + } +#endif } } diff --git a/Commands/Properties/AssemblyInfo.cs b/Commands/Properties/AssemblyInfo.cs index b65336ad1..86bf9b2f4 100644 --- a/Commands/Properties/AssemblyInfo.cs +++ b/Commands/Properties/AssemblyInfo.cs @@ -23,6 +23,8 @@ [assembly: AssemblyProduct("SharePointPnP.PowerShell.SP2016.Commands")] #elif SP2019 [assembly: AssemblyProduct("SharePointPnP.PowerShell.SP2019.Commands")] +#elif NETSTANDARD2_1 +[assembly: AssemblyProduct("PnP.PowerShell.Online.Commands")] #else [assembly: AssemblyProduct("SharePointPnP.PowerShell.Online.Commands")] #endif @@ -48,6 +50,11 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.22.2006.2")] -[assembly: AssemblyFileVersion("3.22.2006.2")] +#if !NETSTANDARD2_1 +[assembly: AssemblyVersion("3.23.2007.0")] +[assembly: AssemblyFileVersion("3.23.2007.0")] +#else +[assembly: AssemblyVersion("4.0.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] +#endif [assembly: InternalsVisibleTo("SharePointPnP.PowerShell.Tests")] \ No newline at end of file diff --git a/Commands/Properties/Resources.Designer.cs b/Commands/Properties/Resources.Designer.cs index c6164ea12..fa8f08820 100644 --- a/Commands/Properties/Resources.Designer.cs +++ b/Commands/Properties/Resources.Designer.cs @@ -79,7 +79,34 @@ internal static string ApplicationName { } /// - /// Looks up a localized string similar to No certificate with the thumbprint '{0}' has been found in the Windows certificate store. + /// Looks up a localized string similar to The certificate located at '{0}' holds no private key. Ensure you provide the private key certificate, typically the .pfx file.. + /// + internal static string CertificateAtPathHasNoPrivateKey { + get { + return ResourceManager.GetString("CertificateAtPathHasNoPrivateKey", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No private key certificate has been found at '{0}'. + /// + internal static string CertificateNotFoundAtPath { + get { + return ResourceManager.GetString("CertificateNotFoundAtPath", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The provided certificate with the thumbprint '{0}' does not have a private key which is required for a connection to be established. Ensure you have imported the certificate containing the private key, typically the .pfx file, into the Windows Certificate Store.. + /// + internal static string CertificateWithThumbprintDoesNotHavePrivateKey { + get { + return ResourceManager.GetString("CertificateWithThumbprintDoesNotHavePrivateKey", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No certificate with the thumbprint '{0}' has been found in the Windows Certificate Store. /// internal static string CertificateWithThumbprintNotFound { get { @@ -359,7 +386,7 @@ internal static string NoContextPresent { } /// - /// Looks up a localized string similar to The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument but not -SPOManagementShell or -PnPO365ManagementShell to connect.. + /// Looks up a localized string similar to The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument but not -SPOManagementShell or -PnPOManagementShell to connect.. /// internal static string NoSharePointConnection { get { @@ -394,6 +421,24 @@ internal static string ParameterSetNotImplemented { } } + /// + /// Looks up a localized string similar to Reading of the private key certificate failed as the password with which it has been signed does not match the provided password. Use {0} to provide the proper password for the private key certificate file.. + /// + internal static string PrivateKeyCertificateImportFailedPasswordIncorrect { + get { + return ResourceManager.GetString("PrivateKeyCertificateImportFailedPasswordIncorrect", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Reading of the private key certificate failed as the password with which it has been signed has not been provided. Use {0} to provide the password.. + /// + internal static string PrivateKeyCertificateImportFailedPasswordMissing { + get { + return ResourceManager.GetString("PrivateKeyCertificateImportFailedPasswordMissing", resourceCulture); + } + } + /// /// Looks up a localized string similar to Remove Client-Side Page?. /// @@ -726,5 +771,14 @@ internal static string Web0CreatedAt1 { return ResourceManager.GetString("Web0CreatedAt1", resourceCulture); } } + + /// + /// Looks up a localized string similar to This Cmdlet currently only supports List Webhooks. + /// + internal static string WebhooksOnlySupportsLists { + get { + return ResourceManager.GetString("WebhooksOnlySupportsLists", resourceCulture); + } + } } } diff --git a/Commands/Properties/Resources.resx b/Commands/Properties/Resources.resx index 198ae2253..5b6829372 100644 --- a/Commands/Properties/Resources.resx +++ b/Commands/Properties/Resources.resx @@ -151,7 +151,7 @@ No list found with id, title or url '{0}' - The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument but not -SPOManagementShell or -PnPO365ManagementShell to connect. + The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument but not -SPOManagementShell or -PnPOManagementShell to connect. No connection to disconnect @@ -328,7 +328,7 @@ No URL specified nor does the provided access token contain an audience - No certificate with the thumbprint '{0}' has been found in the Windows certificate store + No certificate with the thumbprint '{0}' has been found in the Windows Certificate Store The client certificate is invalid @@ -339,4 +339,22 @@ Parameter set {0} has not yet been implemented. Please create an issue for this on GitHub. + + This Cmdlet currently only supports List Webhooks + + + The certificate located at '{0}' holds no private key. Ensure you provide the private key certificate, typically the .pfx file. + + + No private key certificate has been found at '{0}' + + + Reading of the private key certificate failed as the password with which it has been signed does not match the provided password. Use {0} to provide the proper password for the private key certificate file. + + + Reading of the private key certificate failed as the password with which it has been signed has not been provided. Use {0} to provide the password. + + + The provided certificate with the thumbprint '{0}' does not have a private key which is required for a connection to be established. Ensure you have imported the certificate containing the private key, typically the .pfx file, into the Windows Certificate Store. + \ No newline at end of file diff --git a/Commands/Publishing/AddMasterPage.cs b/Commands/Publishing/AddMasterPage.cs index 4024eee65..0b8404e8e 100644 --- a/Commands/Publishing/AddMasterPage.cs +++ b/Commands/Publishing/AddMasterPage.cs @@ -44,4 +44,4 @@ protected override void ExecuteCmdlet() WriteObject(masterPageFile); } } -} +} \ No newline at end of file diff --git a/Commands/RecycleBin/ClearRecycleBinItem.cs b/Commands/RecycleBin/ClearRecycleBinItem.cs index 610cad6d2..7c7bde4f2 100644 --- a/Commands/RecycleBin/ClearRecycleBinItem.cs +++ b/Commands/RecycleBin/ClearRecycleBinItem.cs @@ -6,8 +6,9 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin { - [Cmdlet(VerbsCommon.Clear, "PnPRecycleBinItem", DefaultParameterSetName = "All")] + [Cmdlet(VerbsCommon.Clear, "PnPRecycleBinItem", DefaultParameterSetName = PARAMETERSET_ALL)] [CmdletHelp("Permanently deletes all or a specific recycle bin item", + SupportedPlatform = CmdletSupportedPlatform.All, Category = CmdletHelpCategory.RecycleBin)] [CmdletExample( Code = @"PS:> Get-PnPRecycleBinItem | ? FileLeafName -like ""*.docx"" | Clear-PnpRecycleBinItem", @@ -21,52 +22,85 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin Code = @"PS:> Clear-PnpRecycleBinItem -Identity $item -Force", Remarks = "Permanently deletes the recycle bin item stored under variable $item from the recycle bin without asking for confirmation from the end user first", SortOrder = 3)] +#if !SP2013 + [CmdletExample( + Code = @"PS:> Clear-PnPRecycleBinItem -All -RowLimit 10000", + Remarks = "Permanently deletes up to 10,000 items in the recycle bin", + SortOrder = 4)] +#endif + public class ClearRecycleBinItem : PnPSharePointCmdlet { - [Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item itself to permanently delete", ValueFromPipeline = true, ParameterSetName = "Identity")] + const string PARAMETERSET_ALL = "All"; + const string PARAMETERSET_IDENTITY = "Identity"; + + [Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item itself to permanently delete", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_IDENTITY)] public RecycleBinItemPipeBind Identity; - [Parameter(Mandatory = false, ParameterSetName = "All", HelpMessage = "Clears all items")] + [Parameter(Mandatory = false, ParameterSetName = PARAMETERSET_ALL, HelpMessage = "Clears all items")] public SwitchParameter All; #if !ONPREMISES - [Parameter(Mandatory = false, HelpMessage = "If provided, only all the items in the second stage recycle bin will be cleared", ParameterSetName = "All")] + [Parameter(Mandatory = false, HelpMessage = "If provided, only all the items in the second stage recycle bin will be cleared", ParameterSetName = PARAMETERSET_ALL)] public SwitchParameter SecondStageOnly = false; #endif - [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to permanently delete the recycle bin item")] + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_IDENTITY)] + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_ALL)] public SwitchParameter Force; +#if !SP2013 + [Parameter(Mandatory = false, HelpMessage = "Limits deletion to specified number of items", ParameterSetName = PARAMETERSET_ALL)] + public int RowLimit; +#endif protected override void ExecuteCmdlet() { switch (ParameterSetName) { - case "Identity": + case PARAMETERSET_IDENTITY: var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site); - if (Force || - ShouldContinue(string.Format(Resources.ClearRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm)) + if (Force || ShouldContinue(string.Format(Resources.ClearRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm)) { recycleBinItem.DeleteObject(); ClientContext.ExecuteQueryRetry(); } break; - case "All": + case PARAMETERSET_ALL: #if !ONPREMISES - if (SecondStageOnly) + if (ParameterSpecified(nameof(RowLimit))) { - if (Force || ShouldContinue(Resources.ClearSecondStageRecycleBin, Resources.Confirm)) - { - ClientContext.Site.RecycleBin.DeleteAllSecondStageItems(); + if (Force || ShouldContinue(SecondStageOnly ? Resources.ClearSecondStageRecycleBin : Resources.ClearBothRecycleBins, Resources.Confirm)) + { + RecycleBinItemState recycleBinStage = SecondStageOnly ? RecycleBinItemState.SecondStageRecycleBin : RecycleBinItemState.None; + + RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage); + ClientContext.Load(items); + ClientContext.ExecuteQueryRetry(); + + items.DeleteAll(); ClientContext.ExecuteQueryRetry(); } } else +#endif { - if (Force || ShouldContinue(Resources.ClearBothRecycleBins, Resources.Confirm)) +#if !ONPREMISES + if (SecondStageOnly) { - ClientContext.Site.RecycleBin.DeleteAll(); - ClientContext.ExecuteQueryRetry(); + if (Force || ShouldContinue(Resources.ClearSecondStageRecycleBin, Resources.Confirm)) + { + ClientContext.Site.RecycleBin.DeleteAllSecondStageItems(); + ClientContext.ExecuteQueryRetry(); + } + } + else + { + if (Force || ShouldContinue(Resources.ClearBothRecycleBins, Resources.Confirm)) + { + ClientContext.Site.RecycleBin.DeleteAll(); + ClientContext.ExecuteQueryRetry(); + } } } break; @@ -76,6 +110,7 @@ protected override void ExecuteCmdlet() ClientContext.Site.RecycleBin.DeleteAll(); ClientContext.ExecuteQueryRetry(); } + } break; #endif } diff --git a/Commands/RecycleBin/GetRecycleBinItem.cs b/Commands/RecycleBin/GetRecycleBinItem.cs index 4d3f80cad..b02690b96 100644 --- a/Commands/RecycleBin/GetRecycleBinItem.cs +++ b/Commands/RecycleBin/GetRecycleBinItem.cs @@ -14,7 +14,7 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin Category = CmdletHelpCategory.RecycleBin, OutputType = typeof(RecycleBinItem), SupportedPlatform = CmdletSupportedPlatform.All, - OutputTypeLink = "https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee541897(v=office.15)")] + OutputTypeLink = "https://docs.microsoft.com/previous-versions/office/sharepoint-server/ee541897(v=office.15)")] [CmdletExample( Code = @"PS:> Get-PnPRecycleBinItem", Remarks = "Returns all items in both the first and the second stage recycle bins in the current site collection", @@ -57,7 +57,7 @@ public class GetRecycleBinItems : PnPRetrievalsCmdlet [Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_FIRSTSTAGE)] [Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_SECONDSTAGE)] [Parameter(Mandatory = false, HelpMessage = "Limits return results to specified amount", ParameterSetName = ParameterSet_ALL)] - public int RowLimit = -1; + public int RowLimit; #endif protected override void ExecuteCmdlet() { @@ -73,7 +73,7 @@ protected override void ExecuteCmdlet() else { #if !SP2013 - if (HasRowLimit()) + if (ParameterSpecified(nameof(RowLimit))) { RecycleBinItemState recycleBinStage; switch (ParameterSetName) @@ -89,14 +89,12 @@ protected override void ExecuteCmdlet() break; } - RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, - recycleBinStage); + RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage); ClientContext.Load(items); ClientContext.ExecuteQueryRetry(); List recycleBinItemList = items.ToList(); WriteObject(recycleBinItemList, true); - } else { @@ -107,7 +105,6 @@ protected override void ExecuteCmdlet() switch (ParameterSetName) { - case ParameterSet_FIRSTSTAGE: WriteObject( recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.FirstStageRecycleBin), true); @@ -121,7 +118,6 @@ protected override void ExecuteCmdlet() WriteObject(recycleBinItemList, true); break; } - } #else ClientContext.Site.Context.Load(ClientContext.Site.RecycleBin, r => r.IncludeWithDefaultProperties(RetrievalExpressions)); @@ -148,12 +144,5 @@ protected override void ExecuteCmdlet() #endif } } - -#if !SP2013 - private bool HasRowLimit() - { - return RowLimit > 0; - } -#endif } } diff --git a/Commands/RecycleBin/RestoreRecycleBinItem.cs b/Commands/RecycleBin/RestoreRecycleBinItem.cs index 880419770..72c6e2dec 100644 --- a/Commands/RecycleBin/RestoreRecycleBinItem.cs +++ b/Commands/RecycleBin/RestoreRecycleBinItem.cs @@ -1,4 +1,5 @@ -using System.Management.Automation; +using System; +using System.Management.Automation; using Microsoft.SharePoint.Client; using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; @@ -6,8 +7,9 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin { - [Cmdlet(VerbsData.Restore, "PnPRecycleBinItem")] + [Cmdlet(VerbsData.Restore, "PnPRecycleBinItem", DefaultParameterSetName = PARAMETERSET_ALL)] [CmdletHelp("Restores the provided recycle bin item to its original location", + SupportedPlatform = CmdletSupportedPlatform.All, Category = CmdletHelpCategory.RecycleBin)] [CmdletExample( Code = @"PS:> Restore-PnpRecycleBinItem -Identity 72e4d749-d750-4989-b727-523d6726e442", @@ -17,40 +19,72 @@ namespace SharePointPnP.PowerShell.Commands.RecycleBin Code = @"PS:> Get-PnPRecycleBinItem | ? -Property LeafName -like ""*.docx"" | Restore-PnpRecycleBinItem", Remarks = "Restores all the items in the first and second stage recycle bins to their original location of which the filename ends with the .docx extension", SortOrder = 2)] +#if !SP2013 + [CmdletExample( + Code = @"PS:> Restore-PnPRecycleBinItem -All -RowLimit 10000", + Remarks = "Permanently restores up to 10,000 items in the recycle bin", + SortOrder = 4)] +#endif public class RestoreRecycleBinItem : PnPSharePointCmdlet { - [Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item object itself to restore", ValueFromPipeline = true, ParameterSetName = "Identity")] + const string PARAMETERSET_ALL = "All"; + const string PARAMETERSET_IDENTITY = "Identity"; + + [Parameter(Mandatory = true, HelpMessage = "Id of the recycle bin item or the recycle bin item object itself to restore", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_IDENTITY)] public RecycleBinItemPipeBind Identity; - [Parameter(Mandatory = true, HelpMessage = "If provided all items will be stored ", ValueFromPipeline = true, ParameterSetName = "All")] + [Parameter(Mandatory = false, HelpMessage = "If provided all items will be stored ", ValueFromPipeline = true, ParameterSetName = PARAMETERSET_ALL)] + [Obsolete("No need to add the -All parameter anymore")] public SwitchParameter All; - [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item")] + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_IDENTITY)] + [Parameter(Mandatory = false, HelpMessage = "If provided, no confirmation will be asked to restore the recycle bin item", ParameterSetName = PARAMETERSET_ALL)] public SwitchParameter Force; +#if !SP2013 + [Parameter(Mandatory = false, HelpMessage = "Limits restoration to specified number of items", ParameterSetName = PARAMETERSET_ALL)] + public int RowLimit; +#endif protected override void ExecuteCmdlet() { - if (ParameterSetName == "Identity") - { - var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site); - - if (Force || - ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName), - Resources.Confirm)) - { - recycleBinItem.Restore(); - ClientContext.ExecuteQueryRetry(); - } - } - else + switch (ParameterSetName) { - if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm)) - { - ClientContext.Site.RecycleBin.RestoreAll(); - ClientContext.ExecuteQueryRetry(); - } + case PARAMETERSET_IDENTITY: + var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site); + + if (Force || ShouldContinue(string.Format(Resources.RestoreRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm)) + { + recycleBinItem.Restore(); + ClientContext.ExecuteQueryRetry(); + } + break; + + case PARAMETERSET_ALL: +#if !SP2013 + if (ParameterSpecified(nameof(RowLimit))) + { + if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm)) + { + RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, RecycleBinItemState.None); + ClientContext.Load(items); + ClientContext.ExecuteQueryRetry(); + + items.RestoreAll(); + ClientContext.ExecuteQueryRetry(); + } + } + else +#endif + { + if (Force || ShouldContinue(Resources.RestoreRecycleBinItems, Resources.Confirm)) + { + ClientContext.Site.RecycleBin.RestoreAll(); + ClientContext.ExecuteQueryRetry(); + } + } + break; } } } diff --git a/Commands/SharePointPnP.PowerShell.Commands.csproj b/Commands/SharePointPnP.PowerShell.Commands.csproj index ed7d2865d..058a9a470 100644 --- a/Commands/SharePointPnP.PowerShell.Commands.csproj +++ b/Commands/SharePointPnP.PowerShell.Commands.csproj @@ -453,8 +453,8 @@ ..\packages\Microsoft.Graph.Core.1.9.0\lib\net45\Microsoft.Graph.Core.dll - - ..\packages\Microsoft.Identity.Client.4.10.0\lib\net45\Microsoft.Identity.Client.dll + + ..\packages\Microsoft.Identity.Client.4.16.1\lib\net45\Microsoft.Identity.Client.dll ..\packages\Microsoft.IdentityModel.6.1.7600.16394\lib\net35\Microsoft.IdentityModel.dll @@ -554,7 +554,7 @@ - + @@ -622,15 +622,27 @@ + + + + + + + + + + + + + - @@ -667,14 +679,14 @@ - + - + - + - + @@ -706,6 +718,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -819,19 +852,19 @@ - - + + - + - - + + Code @@ -844,7 +877,7 @@ - + @@ -872,7 +905,7 @@ - + @@ -897,6 +930,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -912,12 +968,15 @@ + + + @@ -1217,7 +1276,7 @@ - + diff --git a/Commands/Site/GetSiteCollectionAdmin.cs b/Commands/Site/GetSiteCollectionAdmin.cs index 1bc8de56a..47eafec0a 100644 --- a/Commands/Site/GetSiteCollectionAdmin.cs +++ b/Commands/Site/GetSiteCollectionAdmin.cs @@ -42,11 +42,11 @@ protected override void ExecuteCmdlet() g => g.LoginName) }; - ClientContext.Load(SelectedWeb.SiteUsers, users => users.Include(retrievalExpressions)); + var siteCollectionAdminUsersQuery = SelectedWeb.SiteUsers.Where(u => u.IsSiteAdmin); + var siteCollectionAdminUsers = ClientContext.LoadQuery(siteCollectionAdminUsersQuery.Include(retrievalExpressions)); ClientContext.ExecuteQueryRetry(); - var siteCollectionAdminUsers = SelectedWeb.SiteUsers.Where(su => su.IsSiteAdmin); WriteObject(siteCollectionAdminUsers, true); } } -} \ No newline at end of file +} diff --git a/Commands/Teams/AddTeamsChannel.cs b/Commands/Teams/AddTeamsChannel.cs new file mode 100644 index 000000000..0d75fb238 --- /dev/null +++ b/Commands/Teams/AddTeamsChannel.cs @@ -0,0 +1,74 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Add, "PnPTeamsChannel")] + [CmdletHelp("Adds a channel to an existing Microsoft Teams instance.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsChannel -Team 4efdf392-8225-4763-9e7f-4edeb7f721aa -DisplayName \"My Channel\"", + Remarks = "Adds a new channel to the specified Teams instance", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsChannel -Team MyTeam -DisplayName \"My Channel\"", + Remarks = "Adds a new channel to the specified Teams instance", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsChannel -Team MyTeam -DisplayName \"My Channel\" -Private", + Remarks = "Adds a new private channel to the specified Teams instance", + SortOrder = 3)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class AddTeamsChannel : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "The display name of the new channel. Letters, numbers and spaces are allowed.")] + public string DisplayName; + + [Parameter(Mandatory = false, HelpMessage = "An optional description of the channel.")] + public string Description; + + [Parameter(Mandatory = false, HelpMessage = "Specify to mark the channel as private.")] + public SwitchParameter Private; + + protected override void ExecuteCmdlet() + { + Model.Teams.TeamChannel channel = null; + + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + try + { + channel = TeamsUtility.AddChannel(AccessToken, HttpClient, groupId, DisplayName, Description, Private); + WriteObject(channel); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/AddTeamsTab.cs b/Commands/Teams/AddTeamsTab.cs new file mode 100644 index 000000000..6e4ec1f10 --- /dev/null +++ b/Commands/Teams/AddTeamsTab.cs @@ -0,0 +1,176 @@ +#if !ONPREMISES +using Microsoft.BusinessData.MetadataModel; +using Microsoft.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Add, "PnPTeamsTab")] + [CmdletHelp("Adds a tab to an existing Channel", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsTab -Team \"My Team\" -Channel \"My Channel\" -DisplayName \"My Channel\" -Type WebSite -ContentUrl \"https://aka.ms/sppnp", + Remarks = "Adds a web site tab to the specified channel.", + SortOrder = 1)] + [CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "TeamsAppId", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection")] + [CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "EntityId", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection")] + [CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "ContentUrl", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection")] + [CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "RemoveUrl", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection")] + [CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "WebSiteUrl", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection")] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class AddTeamsTab : PnPGraphCmdlet, IDynamicParameters + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the channel id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsChannelPipeBind Channel; + + + [Parameter(Mandatory = true, HelpMessage = "Specify the tab type")] + public string DisplayName; + + [Parameter(Mandatory = true, HelpMessage = "Specify the tab type")] + public TeamTabType Type; + + + private OfficeFileParameters officeFileParameters; + private DocumentLibraryParameters documentLibraryParameters; + private CustomParameters customParameters; + public object GetDynamicParameters() + { + switch (Type) + { + case TeamTabType.Word: + case TeamTabType.Excel: + case TeamTabType.PowerPoint: + case TeamTabType.PDF: + { + officeFileParameters = new OfficeFileParameters(); + return officeFileParameters; + } + case TeamTabType.DocumentLibrary: + case TeamTabType.WebSite: + { + documentLibraryParameters = new DocumentLibraryParameters(); + return documentLibraryParameters; + } + case TeamTabType.Custom: + { + customParameters = new CustomParameters(); + return customParameters; + } + } + return null; + } + + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channelId = Channel.GetId(HttpClient, AccessToken, groupId); + if (channelId != null) + { + try + { + string entityId = null; + string contentUrl = null; + string removeUrl = null; + string webSiteUrl = null; + string teamsAppId = null; + switch (Type) + { + case TeamTabType.Word: + case TeamTabType.Excel: + case TeamTabType.PowerPoint: + case TeamTabType.PDF: + { + entityId = officeFileParameters.EntityId; + contentUrl = officeFileParameters.ContentUrl; + break; + } + case TeamTabType.DocumentLibrary: + case TeamTabType.WebSite: + { + contentUrl = documentLibraryParameters.ContentUrl; + break; + } + case TeamTabType.Custom: + { + entityId = customParameters.EntityId; + contentUrl = customParameters.ContentUrl; + removeUrl = customParameters.RemoveUrl; + webSiteUrl = customParameters.WebSiteUrl; + teamsAppId = customParameters.TeamsAppId; + break; + } + } + TeamsUtility.AddTab(HttpClient, AccessToken, groupId, channelId, DisplayName, Type, teamsAppId, entityId, contentUrl, removeUrl, webSiteUrl); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + + public class OfficeFileParameters + { + [Parameter(Mandatory = true)] + public string EntityId; + + [Parameter(Mandatory = true)] + public string ContentUrl; + } + + public class DocumentLibraryParameters + { + [Parameter(Mandatory = true)] + public string ContentUrl; + } + + public class CustomParameters + { + [Parameter(Mandatory = true)] + public string TeamsAppId; + + [Parameter(Mandatory = false)] + public string EntityId; + + [Parameter(Mandatory = false)] + public string ContentUrl; + + [Parameter(Mandatory = false)] + public string RemoveUrl; + + [Parameter(Mandatory = false)] + public string WebSiteUrl; + } + } +} +#endif diff --git a/Commands/Teams/AddTeamsUser.cs b/Commands/Teams/AddTeamsUser.cs new file mode 100644 index 000000000..ecc9db2ff --- /dev/null +++ b/Commands/Teams/AddTeamsUser.cs @@ -0,0 +1,67 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Add, "PnPTeamsUser")] + [CmdletHelp("Adds a channel to an existing Microsoft Teams instance.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsUser -Team MyTeam -User john@doe.com -Role Owner", + Remarks = "Adds a user as an owner to the team", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsUser -Team MyTeam -User john@doe.com -Role Member", + Remarks = "Adds a user as a member to the team", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class AddTeamsUser : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the UPN (e.g. john@doe.com)")] + public string User; + + [Parameter(Mandatory = true, HelpMessage = "Specify the role of the user")] + [ValidateSet(new[] { "Owner", "Member" })] + public string Role; + protected override void ExecuteCmdlet() + { + Model.Teams.TeamChannel channel = null; + + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + try + { + TeamsUtility.AddUser(HttpClient, AccessToken, groupId, User, Role); + WriteObject(channel); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsApp.cs b/Commands/Teams/GetTeamsApp.cs new file mode 100644 index 000000000..d6c8d5a75 --- /dev/null +++ b/Commands/Teams/GetTeamsApp.cs @@ -0,0 +1,54 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Core.Attributes; +using System; +using System.Linq; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsApp")] + [CmdletHelp("Gets one Microsoft Teams App or a list of all apps.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsApp", + Remarks = "Retrieves all the Microsoft Teams Apps", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsApp -Identity a54224d7-608b-4839-bf74-1b68148e65d4", + Remarks = "Retrieves a specific Microsoft Teams App", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsApp -Identity \"MyTeamsApp\"", + Remarks = "Retrieves a specific Microsoft Teams App", + SortOrder = 3)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.AppCatalog_Read_All)] + [CmdletTokenType(TokenType = TokenType.Delegate)] + public class GetTeamsApp : PnPGraphCmdlet + { + [Parameter(Mandatory = false, HelpMessage = "Specify the name, id or external id of the app.")] + public TeamsAppPipeBind Identity; + + protected override void ExecuteCmdlet() + { + if (ParameterSpecified(nameof(Identity))) + { + var app = Identity.GetApp(HttpClient, AccessToken); + if (app != null) + { + WriteObject(app); + } + } + else + { + WriteObject(TeamsUtility.GetApps(AccessToken, HttpClient), true); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsChannel.cs b/Commands/Teams/GetTeamsChannel.cs new file mode 100644 index 000000000..ffdd62b3e --- /dev/null +++ b/Commands/Teams/GetTeamsChannel.cs @@ -0,0 +1,60 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Framework.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Teams +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsChannel")] + [CmdletHelp("Gets the channels for a specified Team.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsChannel -Team a6c1e0d7-f579-4993-81ab-4b666f8edea8", + Remarks = "Retrieves all channels for the specified team", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsChannel -Team a6c1e0d7-f579-4993-81ab-4b666f8edea8 -Identity \"Test Channel\"", + Remarks = "Retrieves the channel called 'Test Channel'", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsChannel -Team a6c1e0d7-f579-4993-81ab-4b666f8edea8 -Identity \"19:796d063b63e34497aeaf092c8fb9b44e@thread.skype\"", + Remarks = "Retrieves the channel specified by its channel id", + SortOrder = 3)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class GetTeamsChannel : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = false, HelpMessage = "The identity of the channel to retrieve.")] + public TeamsChannelPipeBind Identity; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + if (ParameterSpecified(nameof(Identity))) + { + WriteObject(Identity.GetChannel(HttpClient, AccessToken, groupId)); + } + else + { + WriteObject(TeamsUtility.GetChannels(AccessToken, HttpClient, groupId)); + } + } else + { + throw new PSArgumentException("Team not found", nameof(Team)); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsChannelMessage.cs b/Commands/Teams/GetTeamsChannelMessage.cs new file mode 100644 index 000000000..6b50bb837 --- /dev/null +++ b/Commands/Teams/GetTeamsChannelMessage.cs @@ -0,0 +1,51 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsChannelMessage")] + [CmdletHelp("Sends a message to a Microsoft Teams Channel.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Submit-PnPTeamsChannelMessage -Team MyTestTeam -Channel \"My Channel\" -Message \"A new message\"", + Remarks = "Sends \"A new message\" to the specified channel", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class GetTeamsChannelMessage : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsChannelPipeBind Channel; + + [Parameter(Mandatory = false, HelpMessage = "Specify to include deleted messages")] + public SwitchParameter IncludeDeleted; + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channel = Channel.GetChannel(HttpClient, AccessToken, groupId); + if (channel != null) + { + WriteObject(TeamsUtility.GetMessages(HttpClient, AccessToken, groupId, channel.Id, IncludeDeleted), true); + } else + { + throw new PSArgumentException("Channel not found"); + } + } else + { + throw new PSArgumentException("Team not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsTab.cs b/Commands/Teams/GetTeamsTab.cs new file mode 100644 index 000000000..7f3c022c6 --- /dev/null +++ b/Commands/Teams/GetTeamsTab.cs @@ -0,0 +1,81 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsTab")] + [CmdletHelp("Gets one or all tabs in a channel.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTab -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -Channel 19:796d063b63e34497aeaf092c8fb9b44e@thread.skype", + Remarks = "Retrieves the tabs for the specified Microsoft Teams instance and channel", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTab -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -Channel 19:796d063b63e34497aeaf092c8fb9b44e@thread.skype -Identity \"Wiki\"", + Remarks = "Retrieves a tab with the display name 'Wiki' from the specified team and channel", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTab -Team \"My Team\" -Channel \"My Channel\"", + Remarks = "Retrieves the tabs for the specified Microsoft Teams instance and channel", + SortOrder = 3)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTab \"My Team\" -Channel \"My Channel\" -Identity \"Wiki\"", + Remarks = "Retrieves a tab with the display name 'Wiki' from the specified team and channel", + SortOrder = 4)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class GetTeamsTab : PnPGraphCmdlet + { + + [Parameter(Mandatory = true, HelpMessage = "Specify the group id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the channel id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsChannelPipeBind Channel; + + [Parameter(Mandatory = false, HelpMessage = "Identity")] + public TeamsTabPipeBind Identity; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channelId = Channel.GetId(HttpClient, AccessToken, groupId); + if (!string.IsNullOrEmpty(channelId)) + { + if (ParameterSpecified(nameof(Identity))) + { + + if (string.IsNullOrEmpty(Identity.Id)) + { + WriteObject(Identity.GetTab(HttpClient, AccessToken, groupId, channelId)); + } + else + { + WriteObject(Identity.GetTabById(HttpClient, AccessToken, groupId, channelId)); + } + } + else + { + WriteObject(TeamsUtility.GetTabs(AccessToken, HttpClient, groupId, channelId), true); + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Team not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsTeam.cs b/Commands/Teams/GetTeamsTeam.cs new file mode 100644 index 000000000..87ed69290 --- /dev/null +++ b/Commands/Teams/GetTeamsTeam.cs @@ -0,0 +1,56 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsTeam")] + [CmdletHelp("Gets one Microsoft Teams Team or a list of Teams.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam", + Remarks = "Retrieves all the Microsoft Teams instances", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam -Identity $groupId", + Remarks = "Retrieves a specific Microsoft Teams instance", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam -Identity $groupId", + Remarks = "Retrieves a specific Microsoft Teams instance", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class GetTeamsTeam : PnPGraphCmdlet + { + private const string ParameterSet_GroupId = "Retrieve a specific Team"; + + [Parameter(Mandatory = false, HelpMessage = "Specify the group id of the team to retrieve.")] + public TeamsTeamPipeBind Identity; + + protected override void ExecuteCmdlet() + { + if (ParameterSpecified(nameof(Identity))) + { + var groupId = Identity.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + WriteObject(TeamsUtility.GetTeam(AccessToken, HttpClient, groupId)); + } + else + { + throw new PSArgumentException("Team not found"); + } + } + else + { + WriteObject(TeamsUtility.GetTeams(AccessToken, HttpClient), true); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/GetTeamsUser.cs b/Commands/Teams/GetTeamsUser.cs new file mode 100644 index 000000000..c83767bb4 --- /dev/null +++ b/Commands/Teams/GetTeamsUser.cs @@ -0,0 +1,70 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsUser")] + [CmdletHelp("Returns owners, members or guests from a team.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsUser -Team MyTeam", + Remarks = "Returns all owners, members or guests from the specified team.", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsUser -Team MyTeam -Role Owner", + Remarks = "Returns all owners from the specified team.", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsUser -Team MyTeam -Role Member", + Remarks = "Returns all members from the specified team.", + SortOrder = 3)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsUser -Team MyTeam -Role Guest", + Remarks = "Returns all guestss from the specified team.", + SortOrder = 4)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_Read_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class GetTeamsUser : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = false, HelpMessage = "Specify to filter on the role of the user")] + [ValidateSet(new[] { "Owner", "Member", "Guest" })] + public string Role; + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + try + { + WriteObject(TeamsUtility.GetUsers(HttpClient, AccessToken, groupId, Role), true); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/NewTeamsApp.cs b/Commands/Teams/NewTeamsApp.cs new file mode 100644 index 000000000..47ecf5768 --- /dev/null +++ b/Commands/Teams/NewTeamsApp.cs @@ -0,0 +1,59 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.New, "PnPTeamsApp")] + [CmdletHelp("Adds an app to the Teams App Catalog.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> New-PnPTeamsApp -Path c:\\myapp.zip", + Remarks = "Adds the app as defined in the zip file to the Teams App Catalog", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.AppCatalog_ReadWrite_All)] + public class NewTeamsApp : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "The path pointing to the packaged/zip file containing the app")] + public string Path; + + protected override void ExecuteCmdlet() + { + if (!System.IO.Path.IsPathRooted(Path)) + { + Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); + } + + if (System.IO.File.Exists(Path)) + { + try + { + var bytes = System.IO.File.ReadAllBytes(Path); + TeamsUtility.AddApp(HttpClient, AccessToken, bytes); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw new PSInvalidOperationException(ex.Message); + } + } + } + else + { + new PSArgumentException("File not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/NewTeamsTeam.cs b/Commands/Teams/NewTeamsTeam.cs new file mode 100644 index 000000000..a77be77b0 --- /dev/null +++ b/Commands/Teams/NewTeamsTeam.cs @@ -0,0 +1,140 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Framework.Provisioning.Model.Teams; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.New, "PnPTeamsTeam")] + [CmdletHelp("Creates a new Team in Microsoft Teams. The cmdlet will create a Microsoft 365 group and then add a team to the group.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam", + Remarks = "Retrieves all the Microsoft Teams instances", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam -GroupId $groupId", + Remarks = "Retrieves a specific Microsoft Teams instance", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsTeam -Visibility Public", + Remarks = "Retrieves all Microsoft Teams instances which are public visible", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class NewTeamsTeam : PnPGraphCmdlet + { + private const string ParameterSet_EXISTINGGROUP = "For an existing group"; + private const string ParameterSet_NEWGROUP = "For a new group"; + + [Parameter(Mandatory = true, ParameterSetName =ParameterSet_EXISTINGGROUP, HelpMessage = "Specify a GroupId to convert to a Team. If specified, you cannot provide the other values that are already specified by the existing group, namely: Visibility, Alias, Description, or DisplayName.")] + public string GroupId; + + [Parameter(Mandatory = true, ParameterSetName = ParameterSet_NEWGROUP, HelpMessage = "Team display name. Characters Limit - 256.")] + [ValidateLength(1, 256)] + public string DisplayName; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_NEWGROUP, HelpMessage = "The MailNickName parameter specifies the alias for the associated Microsoft 365 Group. This value will be used for the mail enabled object and will be used as PrimarySmtpAddress for this Microsoft 365 Group.The value of the MailNickName parameter has to be unique across your tenant.")] + public string MailNickName; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_NEWGROUP, HelpMessage = "Team description. Characters Limit - 1024.")] + [ValidateLength(0, 1024)] + public string Description; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "An admin who is allowed to create on behalf of another user should use this flag to specify the desired owner of the group.This user will be added as both a member and an owner of the group. If not specified, the user who creates the team will be added as both a member and an owner.")] + public string Owner; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Boolean value that determines whether or not members (not only owners) are allowed to add apps to the team.")] + public bool? AllowAddRemoveApps; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Boolean value that determines whether or not channels in the team can be @ mentioned so that all users who follow the channel are notified.")] + public bool? AllowChannelMentions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not just owners) are allowed to create channels.")] + public bool? AllowCreateUpdateChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can manage connectors in the team.")] + public bool? AllowCreateUpdateRemoveConnectors; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can manage tabs in channels.") ] + public bool? AllowCreateUpdateRemoveTabs; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members can use the custom memes functionality in teams.")] + public bool? AllowCustomMemes; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can delete channels in the team.")] + public bool? AllowDeleteChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not giphy can be used in the team.")] + public bool? AllowGiphy; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not guests can create channels in the team.")] + public bool? AllowGuestCreateUpdateChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not guests can delete in the team.")] + public bool? AllowGuestDeleteChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not owners can delete messages that they or other members of the team have posted.")] + public bool? AllowOwnerDeleteMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether stickers and memes usage is allowed in the team.")] + public bool? AllowStickersAndMemes; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether the entire team can be @ mentioned (which means that all users will be notified)")] + public bool? AllowTeamMentions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members can delete messages that they have posted.")] + public bool? AllowUserDeleteMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not users can edit messages that they have posted.")] + public bool? AllowUserEditMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines the level of sensitivity of giphy usage that is allowed in the team. Accepted values are \"Strict\" or \"Moderate\"")] + public Model.Teams.TeamGiphyContentRating GiphyContentRating; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_NEWGROUP, HelpMessage = "Set to Public to allow all users in your organization to join the group by default. Set to Private to require that an owner approve the join request.")] + public TeamVisibility Visibility; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not private teams should be searchable from Teams clients for users who do not belong to that team. Set to $false to make those teams not discoverable from Teams clients.")] + public bool? ShowInTeamsSearchAndSuggestions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)] + public string Classification; + + + protected override void ExecuteCmdlet() + { + var teamCI = new TeamCreationInformation() + { + AllowAddRemoveApps = AllowAddRemoveApps, + AllowChannelMentions = AllowChannelMentions, + AllowCreateUpdateChannels = AllowCreateUpdateChannels, + AllowCreateUpdateRemoveConnectors = AllowCreateUpdateRemoveConnectors, + AllowCreateUpdateRemoveTabs = AllowCreateUpdateRemoveTabs, + AllowCustomMemes = AllowCustomMemes, + AllowDeleteChannels = AllowDeleteChannels, + AllowGiphy = AllowGiphy, + AllowGuestCreateUpdateChannels = AllowGuestCreateUpdateChannels, + AllowGuestDeleteChannels = AllowGuestDeleteChannels, + AllowOwnerDeleteMessages = AllowOwnerDeleteMessages, + AllowStickersAndMemes = AllowStickersAndMemes, + AllowTeamMentions = AllowTeamMentions, + AllowUserDeleteMessages = AllowUserDeleteMessages, + AllowUserEditMessages = AllowUserEditMessages, + Classification = Classification, + Description = Description, + DisplayName = DisplayName, + GiphyContentRating = GiphyContentRating, + GroupId = GroupId, + ShowInTeamsSearchAndSuggestions = ShowInTeamsSearchAndSuggestions, + Visibility = (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()), + }; + WriteObject(TeamsUtility.NewTeam(AccessToken, HttpClient, GroupId, DisplayName, Description, Classification, MailNickName, Owner, (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()), teamCI)); + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/RemoveTeamsApp.cs b/Commands/Teams/RemoveTeamsApp.cs new file mode 100644 index 000000000..32da564be --- /dev/null +++ b/Commands/Teams/RemoveTeamsApp.cs @@ -0,0 +1,69 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPTeamsApp")] + [CmdletHelp("Removes an app from the Teams AppCatalog.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsApp -Identity ac139d8b-fa2b-4ffe-88b3-f0b30158b58b", + Remarks = "Adds a new channel to the specified Teams instance", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsApp -Identity \"My Teams App\"", + Remarks = "Adds a new channel to the specified Teams instance", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Add-PnPTeamsChannel -Team MyTeam -DisplayName \"My Channel\" -Private", + Remarks = "Adds a new private channel to the specified Teams instance", + SortOrder = 3)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.AppCatalog_ReadWrite_All)] + public class RemoveTeamsApp : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "The id, externalid or display name of the app.")] + public TeamsAppPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + var app = Identity.GetApp(HttpClient, AccessToken); + if (app == null) + { + throw new PSArgumentException("App not found"); + } + if (Force || ShouldContinue($"Do you want to remove {app.DisplayName}?", Properties.Resources.Confirm)) + { + var response = TeamsUtility.DeleteApp(HttpClient, AccessToken, app.Id); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + } + else + { + throw new PSInvalidOperationException("Removing app failed"); + } + } + else + { + WriteObject("App removed"); + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/RemoveTeamsChannel.cs b/Commands/Teams/RemoveTeamsChannel.cs new file mode 100644 index 000000000..3cbee5ca7 --- /dev/null +++ b/Commands/Teams/RemoveTeamsChannel.cs @@ -0,0 +1,72 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Teams +{ + [Cmdlet(VerbsCommon.Remove, "PnPTeamsChannel")] + [CmdletHelp("Removes a channel from a Microsoft Teams instance.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsChannel -Team 4efdf392-8225-4763-9e7f-4edeb7f721aa -DisplayName \"My Channel\"", + Remarks = "Removes the channel specified from the team specified", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class RemoveTeamsChannel : PnPGraphCmdlet + { + [Parameter(Mandatory = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true)] + public TeamsChannelPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + if (Force || ShouldContinue("Removing the channel will also remove all the messages in the channel.", Properties.Resources.Confirm)) + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channel = Identity.GetChannel(HttpClient, AccessToken, groupId); + if (channel != null) + { + var response = TeamsUtility.DeleteChannel(AccessToken, HttpClient, groupId, channel.Id); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + } + else + { + WriteError(new ErrorRecord(new Exception($"Channel remove failed"), "REMOVEFAILED", ErrorCategory.InvalidResult, this)); + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Team not found"); + } + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/RemoveTeamsTab.cs b/Commands/Teams/RemoveTeamsTab.cs new file mode 100644 index 000000000..6356b6cfd --- /dev/null +++ b/Commands/Teams/RemoveTeamsTab.cs @@ -0,0 +1,96 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPTeamsTab")] + [CmdletHelp("Removes a Microsoft Teams tab in a channel.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsTab -GroupId 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -ChannelId 19:796d063b63e34497aeaf092c8fb9b44e@thread.skype -Identity Wiki", + Remarks = "Removes the tab with the display name 'Wiki' from the channel", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsTab -GroupId 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -ChannelId 19:796d063b63e34497aeaf092c8fb9b44e@thread.skype -Identity fcef815d-2e8e-47a5-b06b-9bebba5c7852", + Remarks = "Removes a tab with the specified id from the channel", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class RemoveTeamsTab : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the channel id or display name of the channel to use.")] + public TeamsChannelPipeBind Channel; + + [Parameter(Mandatory = true, HelpMessage = "Specify the id of the tab ")] + public TeamsTabPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channelId = Channel.GetId(HttpClient, AccessToken, groupId); + if (channelId != null) + { + var tabId = string.Empty; + if (string.IsNullOrEmpty(Identity.Id)) + { + tabId = Identity.Id.ToString(); + } + else + { + var tab = Identity.GetTab(HttpClient, AccessToken, groupId, channelId); + if (tab != null) + { + tabId = tab.Id; + } + else + { + throw new PSArgumentException("Cannot find tab"); + } + } + if (Force || ShouldContinue("Removing the tab will remove the settings of this tab too.", Properties.Resources.Confirm)) + { + var response = TeamsUtility.DeleteTab(AccessToken, HttpClient, groupId, channelId, tabId); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + } + else + { + throw new PSInvalidOperationException("Tab remove failed"); + } + } + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Team not found", nameof(Team)); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/RemoveTeamsTeam.cs b/Commands/Teams/RemoveTeamsTeam.cs new file mode 100644 index 000000000..eb618d6e8 --- /dev/null +++ b/Commands/Teams/RemoveTeamsTeam.cs @@ -0,0 +1,65 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPTeamsTeam")] + [CmdletHelp("Removes a Microsoft Teams Team instance", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsTeam -Identity 5beb63c5-0571-499e-94d5-3279fdd9b6b5", + Remarks = "Removes the specified Team", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsTeam -Identity testteam", + Remarks = "Removes the specified Team. If there are multiple teams with the same display name it will not proceed deleting the team.", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class RemoveTeamsTeam : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Either the group id or the mailnickname of the group to remove.")] + public TeamsTeamPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + var groupId = Identity.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + if (Force || ShouldContinue("Removing the team will remove all messages in all channels in the team.", Properties.Resources.Confirm)) + { + var response = TeamsUtility.DeleteTeam(AccessToken, HttpClient, groupId); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + } + else + { + WriteError(new ErrorRecord(new Exception($"Team remove failed"), "REMOVEFAILED", ErrorCategory.InvalidResult, this)); + } + } + } + } + else + { + throw new PSArgumentException("Team not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/RemoveTeamsUser.cs b/Commands/Teams/RemoveTeamsUser.cs new file mode 100644 index 000000000..187136e38 --- /dev/null +++ b/Commands/Teams/RemoveTeamsUser.cs @@ -0,0 +1,73 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Remove, "PnPTeamsUser")] + [CmdletHelp("Removes users from a team.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Remove-PnPTeamsUser -Team MyTeam -User john@doe.com", + Remarks = "Removes the user specified from both owners and members of the team.", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPTeamsUser -Team MyTeam -User john@doe.com -Owner", + Remarks = "Removes the user john@doe.com from the owners of the team, but retains the user as a member.", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class RemoveTeamsUser : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the UPN (e.g. john@doe.com)")] + public string User; + + [Parameter(Mandatory = false, HelpMessage = @"Specify the role of the user you are removing from the team. Accepts ""Owner"" and ""Member"" as possible values. + If specified as ""Member"" then the specified user is removed from the Team completely even if they were the owner of the Team. If ""Owner"" is specified in the -Role parameter then the + specified user is removed as an owner of the team but stays as a team member. Defaults to ""Member"". Note: The last owner cannot be removed from the team.")] + [ValidateSet(new[] { "Owner", "Member" })] + public string Role = "Member"; + + [Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")] + public SwitchParameter Force; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + try + { + if (Force || ShouldContinue($"Remove user with UPN {User}?", Properties.Resources.Confirm)) + { + TeamsUtility.DeleteUser(HttpClient, AccessToken, groupId, User, Role); + } + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SetTeamsChannel .cs b/Commands/Teams/SetTeamsChannel .cs new file mode 100644 index 000000000..8b2d9011a --- /dev/null +++ b/Commands/Teams/SetTeamsChannel .cs @@ -0,0 +1,87 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Set, "PnPTeamsChannel")] + [CmdletHelp("Updates an existing Teams Channel", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsChannel -Team \"MyTeam\" -Channel \"MyChannel\" -DisplayName \"My Channel\"", + Remarks = "Updates the channel called 'MyChannel' to have the display name set to 'My Channel'", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class SetTeamsChannel : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the channel id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsChannelPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Changes the display name of the specified channel.")] + public string DisplayName; + + [Parameter(Mandatory = false, HelpMessage = "Changes the description of the specified channel.")] + public string Description; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var teamChannel = Identity.GetChannel(HttpClient, AccessToken, groupId); + if (teamChannel != null) + { + if (ParameterSpecified(nameof(DisplayName)) && teamChannel.DisplayName != DisplayName) + { + teamChannel.DisplayName = DisplayName; + } else + { + teamChannel.DisplayName = null; + } + if (ParameterSpecified(nameof(Description)) && teamChannel.Description != Description) + { + teamChannel.Description = Description; + } else + { + teamChannel.Description = null; + } + teamChannel.MembershipType = null; + try + { + var updated = TeamsUtility.UpdateChannel(HttpClient, AccessToken, groupId, teamChannel.Id, teamChannel); + WriteObject(updated); + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Group not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SetTeamsTab.cs b/Commands/Teams/SetTeamsTab.cs new file mode 100644 index 000000000..f95219dc9 --- /dev/null +++ b/Commands/Teams/SetTeamsTab.cs @@ -0,0 +1,70 @@ +#if !ONPREMISES +using Microsoft.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.IO; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Set, "PnPTeamsTab")] + [CmdletHelp("Updates Teams Tab settings", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsTab -Team \"MyTeam\" -Channel \"My Channel\" -Identity \"Wiki\" -DisplayName \"Channel Wiki\"", + Remarks = "Updates the tab named 'Wiki' and changes the display name of the tab to 'Channel Wiki'", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class SetTeamsTab : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the channel id of the team to retrieve.", ValueFromPipeline = true)] + public TeamsChannelPipeBind Channel; + + [Parameter(Mandatory = false, HelpMessage = "Identity of the tab.")] + public TeamsTabPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "The new name of the tab.")] + public string DisplayName; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channelId = Channel.GetId(HttpClient, AccessToken, groupId); + if (channelId != null) + { + var tab = Identity.GetTab(HttpClient, AccessToken, groupId, channelId); + if (tab != null) + { + if (ParameterSpecified(nameof(DisplayName)) && tab.DisplayName != DisplayName) + { + tab.DisplayName = DisplayName; + } + TeamsUtility.UpdateTab(HttpClient, AccessToken, groupId, channelId, tab); + } + else + { + throw new PSArgumentException("Tab not found"); + } + } + else + { + throw new PSArgumentException("Channel not found"); + } + } + else + { + throw new PSArgumentException("Team not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SetTeamsTeam.cs b/Commands/Teams/SetTeamsTeam.cs new file mode 100644 index 000000000..af67bad12 --- /dev/null +++ b/Commands/Teams/SetTeamsTeam.cs @@ -0,0 +1,174 @@ +#if !ONPREMISES +using OfficeDevPnP.Core.Framework.Provisioning.Model.Teams; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Set, "PnPTeamsTeam")] + [CmdletHelp("Updates an existing Team.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsChannel -Team \"MyTeam\" -DisplayName \"My Team\"", + Remarks = "Updates the team called 'MyTeam' to have the display name set to 'My Team'", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class SetTeamsTeam : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Changes the display name of the specified team.")] + public string DisplayName; + + [Parameter(Mandatory = false, HelpMessage = "Changes the description of the specified team.")] + public string Description; + + [Parameter(Mandatory = false, HelpMessage = "Changes the visibility of the specified team.")] + public TeamVisibility Visibility; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Boolean value that determines whether or not members (not only owners) are allowed to add apps to the team.")] + public bool? AllowAddRemoveApps; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Boolean value that determines whether or not channels in the team can be @ mentioned so that all users who follow the channel are notified.")] + public bool? AllowChannelMentions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not just owners) are allowed to create channels.")] + public bool? AllowCreateUpdateChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can manage connectors in the team.")] + public bool? AllowCreateUpdateRemoveConnectors; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can manage tabs in channels.")] + public bool? AllowCreateUpdateRemoveTabs; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members can use the custom memes functionality in teams.")] + public bool? AllowCustomMemes; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members (and not only owners) can delete channels in the team.")] + public bool? AllowDeleteChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not giphy can be used in the team.")] + public bool? AllowGiphy; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not guests can create channels in the team.")] + public bool? AllowGuestCreateUpdateChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not guests can delete in the team.")] + public bool? AllowGuestDeleteChannels; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not owners can delete messages that they or other members of the team have posted.")] + public bool? AllowOwnerDeleteMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether stickers and memes usage is allowed in the team.")] + public bool? AllowStickersAndMemes; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether the entire team can be @ mentioned (which means that all users will be notified)")] + public bool? AllowTeamMentions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not members can delete messages that they have posted.")] + public bool? AllowUserDeleteMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not users can edit messages that they have posted.")] + public bool? AllowUserEditMessages; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines the level of sensitivity of giphy usage that is allowed in the team. Accepted values are \"Strict\" or \"Moderate\"")] + public Model.Teams.TeamGiphyContentRating GiphyContentRating; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Setting that determines whether or not private teams should be searchable from Teams clients for users who do not belong to that team. Set to $false to make those teams not discoverable from Teams clients.")] + public bool? ShowInTeamsSearchAndSuggestions; + + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)] + public string Classification; + protected override void ExecuteCmdlet() + { + var groupId = Identity.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + try + { + var team = TeamsUtility.GetTeam(AccessToken, HttpClient, groupId); + var updateGroup = false; + var group = new Group(); + if (team != null) + { + if (ParameterSpecified(nameof(DisplayName)) && team.DisplayName != DisplayName) + { + updateGroup = true; + group.DisplayName = DisplayName; + } + else + { + team.DisplayName = null; + } + if (ParameterSpecified(nameof(Description)) && team.Description != Description) + { + updateGroup = true; + group.Description = Description; + } + else + { + team.Description = null; + } + if((GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()) != team.Visibility) + { + group.Visibility = (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()); + updateGroup = true; + } + team.IsArchived = null; // cannot update this value; + + if(updateGroup) + { + TeamsUtility.UpdateGroup(HttpClient, AccessToken, groupId, group); + } + + var teamCI = new TeamCreationInformation(); + teamCI.AllowAddRemoveApps = ParameterSpecified(nameof(AllowAddRemoveApps)) ? AllowAddRemoveApps : null; + teamCI.AllowChannelMentions = ParameterSpecified(nameof(AllowChannelMentions)) ? AllowChannelMentions : null; + teamCI.AllowCreateUpdateChannels = ParameterSpecified(nameof(AllowCreateUpdateChannels)) ? AllowCreateUpdateChannels : null; + teamCI.AllowCreateUpdateRemoveConnectors = ParameterSpecified(nameof(AllowCreateUpdateRemoveConnectors)) ? AllowCreateUpdateRemoveConnectors : null; + teamCI.AllowCreateUpdateRemoveTabs = ParameterSpecified(nameof(AllowCreateUpdateRemoveTabs)) ? AllowCreateUpdateRemoveTabs : null; + teamCI.AllowCustomMemes = ParameterSpecified(nameof(AllowCustomMemes)) ? AllowCustomMemes : null; + teamCI.AllowDeleteChannels = ParameterSpecified(nameof(AllowDeleteChannels)) ? AllowDeleteChannels : null; + teamCI.AllowGiphy = ParameterSpecified(nameof(AllowGiphy)) ? AllowGiphy : null; ; + teamCI.AllowGuestCreateUpdateChannels = ParameterSpecified(nameof(AllowGuestCreateUpdateChannels)) ? AllowGuestCreateUpdateChannels : null; + teamCI.AllowGuestDeleteChannels = ParameterSpecified(nameof(AllowGuestDeleteChannels)) ? AllowGuestDeleteChannels : null; + teamCI.AllowOwnerDeleteMessages = ParameterSpecified(nameof(AllowOwnerDeleteMessages)) ? AllowOwnerDeleteMessages : null; + teamCI.AllowStickersAndMemes = ParameterSpecified(nameof(AllowStickersAndMemes)) ? AllowStickersAndMemes : null; + teamCI.AllowTeamMentions = ParameterSpecified(nameof(AllowTeamMentions)) ? AllowTeamMentions : null; + teamCI.AllowUserDeleteMessages = ParameterSpecified(nameof(AllowUserDeleteMessages)) ? AllowUserDeleteMessages : null; + teamCI.AllowUserEditMessages = ParameterSpecified(nameof(AllowUserEditMessages)) ? AllowUserEditMessages : null; + teamCI.Classification = ParameterSpecified(nameof(Classification)) ? Classification : null; + + var updated = TeamsUtility.UpdateTeam(HttpClient, AccessToken, groupId, teamCI.ToTeam()); + WriteObject(updated); + } + } + catch (GraphException ex) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw ex; + } + } + + } + else + { + throw new PSArgumentException("Team not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SetTeamsTeamArchivedState.cs b/Commands/Teams/SetTeamsTeamArchivedState.cs new file mode 100644 index 000000000..8c23cb396 --- /dev/null +++ b/Commands/Teams/SetTeamsTeamArchivedState.cs @@ -0,0 +1,87 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using SharePointPnP.PowerShell.Core.Attributes; +using System; +using System.Linq; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Set, "PnPTeamsTeamArchivedState")] + [CmdletHelp("Sets the archived state of a team.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsTeamArchivedState -Identity \"My Team\" -Archived $true", + Remarks = "Archives the team as identified.", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsTeamArchivedState -Identity \"My Team\" -Archived $false", + Remarks = "Unarchives the team as identified.", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsTeamArchivedState -Identity \"My Team\" -Archived $true -SetSiteReadOnlyForMembers $true", + Remarks = "Archives the team as identified and sets the underlying SharePoint Online Site Collection as read only for members", + SortOrder = 3)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Directory_ReadWrite_All)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + [CmdletTokenType(TokenType = TokenType.Delegate)] + public class SetTeamsTeamArchivedState : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the name, id or external id of the app.")] + public TeamsTeamPipeBind Identity; + + [Parameter(Mandatory = true)] + public bool Archived; + + [Parameter(Mandatory = false)] + public bool? SetSiteReadOnlyForMembers; + + protected override void ExecuteCmdlet() + { + if (!Archived && SetSiteReadOnlyForMembers.HasValue) + { + throw new PSArgumentException("You can only modify the read only state of a site when archiving a team"); + } + var groupId = Identity.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var team = Identity.GetTeam(HttpClient, AccessToken); + if (Archived == team.IsArchived) + { + throw new PSInvalidOperationException($"Team {team.DisplayName} {(Archived ? "has already been" : "is not")} archived"); + } + var response = TeamsUtility.SetTeamArchivedState(HttpClient, AccessToken, groupId, Archived, SetSiteReadOnlyForMembers); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + if (ex.Error != null) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + } + else + { + throw new PSInvalidOperationException("Setting archived state failed."); + } + } + else + { + WriteObject($"Team {(Archived ? "archived" : "unarchived")}."); + + } + } + else + { + throw new PSArgumentException("Team not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SetTeamsTeamPicture.cs b/Commands/Teams/SetTeamsTeamPicture.cs new file mode 100644 index 000000000..b31bc6b5a --- /dev/null +++ b/Commands/Teams/SetTeamsTeamPicture.cs @@ -0,0 +1,79 @@ +#if !ONPREMISES +using Microsoft.Graph; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.IO; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Set, "PnPTeamsTeamPicture")] + [CmdletHelp("Sets the picture of an existing team.", + DetailedDescription = "Notice that this cmdlet will immediately return but it can take a few hours before the changes are reflected in Microsoft Teams.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Set-PnPTeamsTeamPicture -Team \"MyTeam\" -Path \"c:\\myimage.jpg\"", + Remarks = "Updates the channel called 'MyChannel' to have the display name set to 'My Channel'", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class SetTeamsTeamPicture : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.", ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "The path to the image file.")] + public string Path; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + if (!System.IO.Path.IsPathRooted(Path)) + { + Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); + + } + if (System.IO.File.Exists(Path)) + { + var contentType = ""; + var fileInfo = new FileInfo(Path); + switch (fileInfo.Extension) + { + case ".jpg": + case ".jpeg": + { + contentType = "image/jpeg"; + break; + } + case ".png": + { + contentType = "image/png"; + break; + } + } + if (string.IsNullOrEmpty(contentType)) + { + throw new PSArgumentException("File is not of a supported content type (jpg/png)"); + } + var byteArray = System.IO.File.ReadAllBytes(Path); + TeamsUtility.SetTeamPicture(HttpClient, AccessToken, groupId, byteArray, contentType); + } + else + { + throw new PSArgumentException("File not found"); + } + } + else + { + throw new PSArgumentException("Team not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/SubmitTeamsChannelMessage.cs b/Commands/Teams/SubmitTeamsChannelMessage.cs new file mode 100644 index 000000000..1480b3ca5 --- /dev/null +++ b/Commands/Teams/SubmitTeamsChannelMessage.cs @@ -0,0 +1,67 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsLifecycle.Submit, "PnPTeamsChannelMessage")] + [CmdletHelp("Sends a message to a Microsoft Teams Channel.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Submit-PnPTeamsChannelMessage -Team MyTestTeam -Channel \"My Channel\" -Message \"A new message\"", + Remarks = "Sends \"A new message\" to the specified channel", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Submit-PnPTeamsChannelMessage -Team MyTestTeam -Channel \"My Channel\" -Message \"A bold new message\" -ContentType Html", + Remarks = "Sends the message, formatted as html to the specified channel", + SortOrder = 2)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class SubmitTeamsChannelMessage : PnPGraphCmdlet + { + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = true, HelpMessage = "Specify the group id, mailNickname or display name of the team to use.")] + public TeamsChannelPipeBind Channel; + + [Parameter(Mandatory = true, HelpMessage = "The message to send to the channel.")] + public string Message; + + [Parameter(Mandatory = false, HelpMessage = "Specify to set the content type of the message, either Text or Html.")] + public TeamChannelMessageContentType ContentType; + + [Parameter(Mandatory = false, HelpMessage = "Specify to make this an important message.")] + public SwitchParameter Important; + + protected override void ExecuteCmdlet() + { + var groupId = Team.GetGroupId(HttpClient, AccessToken); + if (groupId != null) + { + var channel = Channel.GetChannel(HttpClient, AccessToken, groupId); + if (channel != null) + { + var channelMessage = new TeamChannelMessage(); + channelMessage.Importance = Important ? "high" : "normal"; + channelMessage.Body.Content = Message; + channelMessage.Body.ContentType = ContentType; + + TeamsUtility.PostMessage(HttpClient, AccessToken, groupId, channel.Id, channelMessage); + } else + { + throw new PSArgumentException("Channel not found"); + } + } else + { + throw new PSArgumentException("Team not found"); + } + + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Teams/UpdateTeamsApp.cs b/Commands/Teams/UpdateTeamsApp.cs new file mode 100644 index 000000000..8ca1b7512 --- /dev/null +++ b/Commands/Teams/UpdateTeamsApp.cs @@ -0,0 +1,72 @@ +#if !ONPREMISES +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System.Management.Automation; + +namespace SharePointPnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsData.Update, "PnPTeamsApp")] + [CmdletHelp("Updates an existing app in the Teams App Catalog.", + Category = CmdletHelpCategory.Teams, + SupportedPlatform = CmdletSupportedPlatform.Online)] + [CmdletExample( + Code = "PS:> Update-PnPTeamsApp -Identity 4efdf392-8225-4763-9e7f-4edeb7f721aa -Path c:\\myapp.zip", + Remarks = "Updates the specified app in the teams app catalog with the contents of the referenced zip file.", + SortOrder = 1)] + [CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission.Group_ReadWrite_All)] + public class UpdateTeamsApp : PnPGraphCmdlet + { + [Parameter(Mandatory = true)] + public TeamsAppPipeBind Identity; + + [Parameter(Mandatory = true, HelpMessage = "The path pointing to the packaged/zip file containing the app")] + public string Path; + + protected override void ExecuteCmdlet() + { + if (!System.IO.Path.IsPathRooted(Path)) + { + Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); + } + + if (System.IO.File.Exists(Path)) + { + var app = Identity.GetApp(HttpClient, AccessToken); + if (app != null) + { + + var bytes = System.IO.File.ReadAllBytes(Path); + var response = TeamsUtility.UpdateApp(HttpClient, AccessToken, bytes, app.Id); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException ex)) + { + throw new PSInvalidOperationException(ex.Error.Message); + } + else + { + throw new PSInvalidOperationException("Update app failed"); + } + } + else + { + WriteObject("App updated"); + } + } + else + { + throw new PSArgumentException("App not found"); + } + } + else + { + throw new PSArgumentException("File not found"); + } + } + } +} +#endif \ No newline at end of file diff --git a/Commands/Utilities/BrowserHelper.cs b/Commands/Utilities/BrowserHelper.cs index 0d3142b25..f2174054f 100644 --- a/Commands/Utilities/BrowserHelper.cs +++ b/Commands/Utilities/BrowserHelper.cs @@ -55,6 +55,51 @@ public static void OpenBrowser(string url, Action success, System.Drawing. thread.Start(); thread.Join(); } + + public static void LaunchBrowser(string url, Action success, System.Drawing.Icon icon = null) + { + var thread = new Thread(() => + { + var form = new System.Windows.Forms.Form(); + if (icon != null) + { + form.Icon = icon; + } + var browser = new System.Windows.Forms.WebBrowser + { + ScriptErrorsSuppressed = true, + Dock = DockStyle.Fill + }; + + form.SuspendLayout(); + form.Width = 568; + form.Height = 1012; + form.Text = $"Authenticate"; + form.Controls.Add(browser); + form.ResumeLayout(false); + form.FormClosed += (sender, args) => + { + success(false); + }; + browser.Navigated += (sender, args) => + { + if (browser.Url.AbsoluteUri.Equals("https://login.microsoftonline.com/common/login", StringComparison.InvariantCultureIgnoreCase) || browser.Url.AbsoluteUri.StartsWith("https://login.microsoftonline.com/common/reprocess", StringComparison.InvariantCultureIgnoreCase)) + { + form.Close(); + success(true); + } + }; + browser.Navigate(url); + + form.Focus(); + form.ShowDialog(); + browser.Dispose(); + }); + + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + thread.Join(); + } } } #endif \ No newline at end of file diff --git a/Commands/Utilities/Clipboard.cs b/Commands/Utilities/Clipboard.cs index 8c67af7fa..0612b02e5 100644 --- a/Commands/Utilities/Clipboard.cs +++ b/Commands/Utilities/Clipboard.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; namespace SharePointPnP.PowerShell.Commands.Utilities { @@ -27,5 +28,27 @@ public static void Copy(string val) System.IO.File.Delete(tempfile); #endif } + + public static void CopyNew(string value) + { + Exception threadEx = null; + Thread staThread = new Thread( + + delegate () + { + try + { + System.Windows.Forms.Clipboard.SetText(value); + } + + catch (Exception ex) + { + threadEx = ex; + } + }); + staThread.SetApartmentState(ApartmentState.STA); + staThread.Start(); + staThread.Join(); + } } } diff --git a/Commands/Utilities/REST/GraphCollection.cs b/Commands/Utilities/REST/GraphCollection.cs new file mode 100644 index 000000000..819cd72de --- /dev/null +++ b/Commands/Utilities/REST/GraphCollection.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Utilities.REST +{ + + public class GraphCollection + { + [JsonProperty("@odata.nextLink")] + public string NextLink { get; set; } + + [JsonProperty("value")] + public IEnumerable Items { get; set; } + } +} diff --git a/Commands/Utilities/REST/GraphHelper.cs b/Commands/Utilities/REST/GraphHelper.cs new file mode 100644 index 000000000..9b1a81e23 --- /dev/null +++ b/Commands/Utilities/REST/GraphHelper.cs @@ -0,0 +1,258 @@ +using Microsoft.Graph; +using Microsoft.Identity.Client; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Utilities.REST +{ + internal static class GraphHelper + { + public static bool TryGetGraphException(HttpResponseMessage responseMessage, out GraphException exception) + { + if (responseMessage == null) + { + exception = null; + return false; + } + var content = responseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + if (string.IsNullOrEmpty(content)) + { + exception = null; + return false; + } + try + { + exception = JsonConvert.DeserializeObject(content); + return true; + } + catch + { + exception = null; + return false; + } + } + + private static HttpRequestMessage GetMessage(string url, HttpMethod method, string accessToken, HttpContent content = null) + { + if (url.StartsWith("/")) + { + url = url.Substring(1); + } + + var message = new HttpRequestMessage(); + message.Method = method; + message.RequestUri = !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ? new Uri($"https://graph.microsoft.com/{url}") : new Uri(url); + message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); +#if NETSTANDARD2_1 + if (method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch) +#else + if (method == HttpMethod.Post || method == HttpMethod.Put || method.Method == "PATCH") +#endif + { + message.Content = content; + } + + return message; + } + + public static async Task GetAsync(HttpClient httpClient, string url, string accessToken) + { + var message = GetMessage(url, HttpMethod.Get, accessToken); + return await SendMessageAsync(httpClient, message); + } + + public static async Task GetAsync(HttpClient httpClient, string url, string accessToken) + { + var stringContent = await GetAsync(httpClient, url, accessToken); + if (stringContent != null) + { + try + { + return JsonConvert.DeserializeObject(stringContent); + } + catch + { + return default(T); + } + } + return default(T); + } + + public static async Task PostAsync(HttpClient httpClient, string url, string accessToken, HttpContent content) + { + var message = GetMessage(url, HttpMethod.Post, accessToken, content); + return await GetResponseMessageAsync(httpClient, message); + } + + public static async Task PutAsync(HttpClient httpClient, string url, string accessToken, HttpContent content) + { + var message = GetMessage(url, HttpMethod.Put, accessToken, content); + return await GetResponseMessageAsync(httpClient, message); + } + + + + public static async Task PatchAsync(HttpClient httpClient, string accessToken, string url, T content) + { + var requestContent = new StringContent(JsonConvert.SerializeObject(content, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() })); + requestContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); +#if NETSTANDARD2_1 + var message = GetMessage(url, HttpMethod.Patch, accessToken, requestContent); +#else + var message = GetMessage(url, new HttpMethod("PATCH"), accessToken, requestContent); +#endif + var returnValue = await SendMessageAsync(httpClient, message); + if (!string.IsNullOrEmpty(returnValue)) + { + return JsonConvert.DeserializeObject(returnValue); + } + else + { + return default; + } + } + + + + public static async Task PostAsync(HttpClient httpClient, string url, HttpContent content, string accessToken) + { + var message = GetMessage(url, HttpMethod.Post, accessToken, content); + var stringContent = await SendMessageAsync(httpClient, message); + if (stringContent != null) + { + try + { + return JsonConvert.DeserializeObject(stringContent); + } + catch + { + return default; + } + } + return default; + } + + public static async Task PutAsync(HttpClient httpClient, string url, string accessToken, HttpContent content) + { + var message = GetMessage(url, HttpMethod.Put, accessToken, content); + var stringContent = await SendMessageAsync(httpClient, message); + if (stringContent != null) + { + try + { + return JsonConvert.DeserializeObject(stringContent); + } + catch + { + return default; + } + } + return default; + } + + public static async Task PostAsync(HttpClient httpClient, string url, T content, string accessToken) + { + var requestContent = new StringContent(JsonConvert.SerializeObject(content, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() })); + requestContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + var message = GetMessage(url, HttpMethod.Post, accessToken, requestContent); + var returnValue = await SendMessageAsync(httpClient, message); + if (!string.IsNullOrEmpty(returnValue)) + { + return JsonConvert.DeserializeObject(returnValue); + } + else + { + return default; + } + } + + public static async Task PutAsync(HttpClient httpClient, string url, T content, string accessToken) + { + var requestContent = new StringContent(JsonConvert.SerializeObject(content, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() })); + requestContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + var message = GetMessage(url, HttpMethod.Put, accessToken, requestContent); + var returnValue = await SendMessageAsync(httpClient, message); + if (!string.IsNullOrEmpty(returnValue)) + { + return JsonConvert.DeserializeObject(returnValue); + } + else + { + return default; + } + } + + public static async Task DeleteAsync(HttpClient httpClient, string url, string accessToken) + { + var message = GetMessage(url, HttpMethod.Delete, accessToken); + var response = await GetResponseMessageAsync(httpClient, message); + return response; + } + + private static async Task SendMessageAsync(HttpClient httpClient, HttpRequestMessage message) + { + var response = await httpClient.SendAsync(message); + while (response.StatusCode == (HttpStatusCode)429) + { + // throttled + var retryAfter = response.Headers.RetryAfter; + Thread.Sleep(retryAfter.Delta.Value.Seconds * 1000); + response = await httpClient.SendAsync(CloneMessage(message)); + } + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsStringAsync(); + } + else + { + var errorContent = await response.Content.ReadAsStringAsync(); + var exception = JsonConvert.DeserializeObject(errorContent); + throw exception; + } + } + + + + public static async Task GetResponseMessageAsync(HttpClient httpClient, HttpRequestMessage message) + { + var response = await httpClient.SendAsync(message); + while (response.StatusCode == (HttpStatusCode)429) + { + // throttled + var retryAfter = response.Headers.RetryAfter; + Thread.Sleep(retryAfter.Delta.Value.Seconds * 1000); + response = await httpClient.SendAsync(CloneMessage(message)); + } + return response; + } + + private static HttpRequestMessage CloneMessage(HttpRequestMessage req) + { + HttpRequestMessage clone = new HttpRequestMessage(req.Method, req.RequestUri); + + clone.Content = req.Content; + clone.Version = req.Version; + + foreach (KeyValuePair prop in req.Properties) + { + clone.Properties.Add(prop); + } + + foreach (KeyValuePair> header in req.Headers) + { + clone.Headers.TryAddWithoutValidation(header.Key, header.Value); + } + + return clone; + } + } +} diff --git a/Commands/Utilities/REST/RestHelper.cs b/Commands/Utilities/REST/RestHelper.cs index 391ed1c26..12f920407 100644 --- a/Commands/Utilities/REST/RestHelper.cs +++ b/Commands/Utilities/REST/RestHelper.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Threading.Tasks; using Microsoft.SharePoint.Client; using Newtonsoft.Json; diff --git a/Commands/Utilities/TeamsUtility.cs b/Commands/Utilities/TeamsUtility.cs new file mode 100644 index 000000000..60426a934 --- /dev/null +++ b/Commands/Utilities/TeamsUtility.cs @@ -0,0 +1,654 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using SharePointPnP.PowerShell.Commands.Model.Teams; +using SharePointPnP.PowerShell.Commands.Site; +using SharePointPnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using System.Net.Http; +#if !NETSTANDARD2_1 +using System.Web; +#endif + +namespace SharePointPnP.PowerShell.Commands.Utilities +{ + internal static class TeamsUtility + { + private const int PageSize = 100; + + #region Team + public static List GetGroupsWithTeam(HttpClient httpClient, string accessToken) + { + List groups = new List(); + string url = string.Empty; + var collection = GraphHelper.GetAsync>(httpClient, $"beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&$select=Id,DisplayName,MailNickName,Description,Visibility&$top={PageSize}", accessToken).GetAwaiter().GetResult(); ; + if (collection != null) + { + groups.AddRange(collection.Items); + while (!string.IsNullOrEmpty(collection.NextLink)) + { + collection = GraphHelper.GetAsync>(httpClient, collection.NextLink, accessToken).GetAwaiter().GetResult(); + groups.AddRange(collection.Items); + } + } + return groups; + } + + public static Group GetGroupWithTeam(HttpClient httpClient, string accessToken, string mailNickname) + { + return GraphHelper.GetAsync(httpClient, $"beta/groups?$filter=(resourceProvisioningOptions/Any(x:x eq 'Team') and mailNickname eq '{mailNickname}')&$select=Id,DisplayName,MailNickName,Description,Visibility", accessToken).GetAwaiter().GetResult(); + + } + public static List GetTeams(string accessToken, HttpClient httpClient) + { + List teams = new List(); + + var groups = GetGroupsWithTeam(httpClient, accessToken); + foreach (var group in groups) + { + Team team = ParseTeamJson(accessToken, httpClient, group.Id); + + if (team != null) + { + team.DisplayName = group.DisplayName; + team.MailNickname = group.MailNickname; + team.Visibility = group.Visibility; + teams.Add(team); + } + } + return teams; + } + + public static Team GetTeam(string accessToken, HttpClient httpClient, string groupId) + { + // get the group + var group = GraphHelper.GetAsync(httpClient, $"v1.0/groups/{groupId}?$select=Id,DisplayName,MailNickName,Description,Visibility", accessToken).GetAwaiter().GetResult(); + + Team team = ParseTeamJson(accessToken, httpClient, group.Id); + if (team != null) + { + team.DisplayName = group.DisplayName; + team.MailNickname = group.MailNickname; + team.Visibility = group.Visibility; + return team; + } + else + { + return null; + } + } + + public static HttpResponseMessage DeleteTeam(string accessToken, HttpClient httpClient, string groupId) + { + return GraphHelper.DeleteAsync(httpClient, $"v1.0/groups/{groupId}", accessToken).GetAwaiter().GetResult(); + } + + private static Team ParseTeamJson(string accessToken, HttpClient httpClient, string groupId) + { + // Get Settings + try + { + var team = GraphHelper.GetAsync(httpClient, $"v1.0/teams/{groupId}", accessToken).GetAwaiter().GetResult(); + if (team != null) + { + team.GroupId = groupId; + return team; + } + else + { + return null; + } + + //team = GetTeamChannels(configuration, accessToken, groupId, team, scope); + //team = GetTeamApps(accessToken, groupId, team, scope); + //team = GetTeamSecurity(accessToken, groupId, team, scope); + //GetTeamPhoto(configuration, accessToken, groupId, team, scope); + } + catch (ApplicationException ex) + { +#if !NETSTANDARD2_1 + if (ex.InnerException is HttpException) + { + if (((HttpException)ex.InnerException).GetHttpCode() == 404) + { + // no team, swallow + return null; + } + else + { + throw ex; + } + } + else + { + throw ex; + } +#else + // untested change + if (ex.Message.StartsWith("404")) + { + // no team, swallow + } + else + { + throw ex; + } +#endif + return null; + } + } + + public static Team NewTeam(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamCreationInformation teamCI) + { + Group group = null; + Team returnTeam = null; + // Create group + if (string.IsNullOrEmpty(groupId)) + { + group = CreateGroup(accessToken, httpClient, displayName, description, classification, mailNickname, owner, visibility); + } + else + { + group = GraphHelper.GetAsync(httpClient, $"v1.0/groups/{groupId}", accessToken).GetAwaiter().GetResult(); + if (group == null) + { + throw new PSArgumentException($"Cannot find group with id {groupId}"); + } + teamCI.Visibility = group.Visibility; + teamCI.Description = group.Description; + } + if (group != null) + { + Team team = teamCI.ToTeam(); + var teamSettings = GraphHelper.PutAsync(httpClient, $"v1.0/groups/{group.Id}/team", team, accessToken).GetAwaiter().GetResult(); + if (teamSettings != null) + { + returnTeam = TeamsUtility.GetTeam(accessToken, httpClient, group.Id); + } + } + return returnTeam; + } + + private static Group CreateGroup(string accessToken, HttpClient httpClient, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility) + { + Group group = new Group(); + // get the owner if no owner was specified + var ownerId = string.Empty; + if (string.IsNullOrEmpty(owner)) + { + var user = GraphHelper.GetAsync(httpClient, "v1.0/me?$select=Id", accessToken).GetAwaiter().GetResult(); + ownerId = user.Id; + } + else + { + var user = GraphHelper.GetAsync(httpClient, $"v1.0/users/{owner}?$select=Id", accessToken).GetAwaiter().GetResult(); + if (user != null) + { + ownerId = user.Id; + } + else + { + // find the user in the organization + var collection = GraphHelper.GetAsync>(httpClient, "v1.0/myorganization/users?$filter=mail eq '{owner}'&$select=Id", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + if (collection.Items.Any()) + { + ownerId = collection.Items.First().Id; + } + } + } + } + + group.DisplayName = displayName; + group.Description = description; + group.Classification = classification; + group.MailEnabled = true; + group.MailNickname = mailNickname ?? CreateAlias(httpClient, accessToken); + group.GroupTypes = new List() { "Unified" }; + group.SecurityEnabled = false; + group.Owners = new List() { $"https://graph.microsoft.com/v1.0/users/{ownerId}" }; + group.Members = new List() { $"https://graph.microsoft.com/v1.0/users/{ownerId}" }; + group.Visibility = visibility == GroupVisibility.NotSpecified ? GroupVisibility.Private : visibility; + + return GraphHelper.PostAsync(httpClient, "v1.0/groups", group, accessToken).GetAwaiter().GetResult(); + + } + + private static string CreateAlias(HttpClient httpClient, string accessToken) + { + var guid = Guid.NewGuid().ToString(); + var teamName = string.Empty; + // check if the group exists + do + { + var teamNameTemp = $"msteams_{guid.Substring(0, 8)}{guid.Substring(9, 4)}"; + var collection = GraphHelper.GetAsync>(httpClient, $"v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified') and (mailNickname eq '{teamNameTemp}')", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + if (!collection.Items.Any()) teamName = teamNameTemp; + } + + } while (teamName == string.Empty); + return teamName; + } + + public static Team UpdateTeam(HttpClient httpClient, string accessToken, string groupId, Team team) + { + return GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/teams/{groupId}", team).GetAwaiter().GetResult(); + } + + public static Group UpdateGroup(HttpClient httpClient, string accessToken, string groupId, Group group) + { + return GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/groups/{groupId}", group).GetAwaiter().GetResult(); + } + + public static void SetTeamPicture(HttpClient httpClient, string accessToken, string groupId, byte[] bytes, string contentType) + { + var byteArrayContent = new ByteArrayContent(bytes); + byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType); + GraphHelper.PutAsync(httpClient, $"v1.0/groups/{groupId}/photo/$value", accessToken, byteArrayContent).GetAwaiter().GetResult(); + } + + public static HttpResponseMessage SetTeamArchivedState(HttpClient httpClient, string accessToken, string groupId, bool archived, bool? setSiteReadOnly) + { + if (archived) + { + StringContent content = new StringContent(JsonConvert.SerializeObject(setSiteReadOnly.HasValue ? new { shouldSetSpoSiteReadOnlyForMembers = setSiteReadOnly } : null)); + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + return GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/archive", accessToken, content).GetAwaiter().GetResult(); + } + else + { + StringContent content = new StringContent(""); + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + return GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/unarchive", accessToken, content).GetAwaiter().GetResult(); + } + } + #endregion + + #region Users + public static void AddUser(HttpClient httpClient, string accessToken, string groupId, string upn, string role) + { + var user = GraphHelper.GetAsync(httpClient, $"v1.0/users/{upn}", accessToken).GetAwaiter().GetResult(); + + // check if the user is a member + bool isMember = false; + try + { + var members = GraphHelper.GetAsync>(httpClient, $"v1.0/groups/{groupId}/members?$filter=Id eq '{user.Id}'&$select=Id", accessToken).GetAwaiter().GetResult(); + isMember = members.Items.Any(); + } + catch (GraphException) + { } + + bool isOwner = false; + try + { + var owners = GraphHelper.GetAsync>(httpClient, $"v1.0/groups/{groupId}/owners?$filter=Id eq '{user.Id}'&$select=Id", accessToken).GetAwaiter().GetResult(); + isOwner = owners.Items.Any(); + } + catch (GraphException) + { + + } + + var value = new Dictionary + { + { + "@odata.id", + $"https://graph.microsoft.com/v1.0/directoryObjects/{user.Id}" + } + }; + var stringContent = new StringContent(JsonConvert.SerializeObject(value)); + stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + if (role == "Owner") + { + if (!isMember) + { + GraphHelper.PostAsync(httpClient, $"v1.0/groups/{groupId}/members/$ref", accessToken, stringContent).GetAwaiter().GetResult(); + } + GraphHelper.PostAsync(httpClient, $"v1.0/groups/{groupId}/owners/$ref", accessToken, stringContent).GetAwaiter().GetResult(); + } + else + { + GraphHelper.PostAsync(httpClient, $"v1.0/groups/{groupId}/members/$ref", accessToken, stringContent).GetAwaiter().GetResult(); + } + } + + public static List GetUsers(HttpClient httpClient, string accessToken, string groupId, string role) + { + var selectedRole = role != null ? role.ToLower() : null; + var owners = new List(); + var guests = new List(); + var members = new List(); + if (selectedRole != "guest") + { + owners = GraphHelper.GetAsync>(httpClient, $"v1.0/groups/{groupId}/owners?$select=Id,displayName,userPrincipalName,userType", accessToken).GetAwaiter().GetResult().Items.Select(t => new User() + { + Id = t.Id, + DisplayName = t.DisplayName, + UserPrincipalName = t.UserPrincipalName, + UserType = "Owner" + }).ToList(); + } + if (selectedRole != "owner") + { + var users = GraphHelper.GetAsync>(httpClient, $"v1.0/groups/{groupId}/members?$select=Id,displayName,userPrincipalName,userType", accessToken).GetAwaiter().GetResult().Items; + HashSet hashSet = new HashSet(owners.Select(u => u.Id)); + foreach (var user in users) + { + if (!hashSet.Contains(user.Id)) + { + if (user.UserType != null && user.UserType.ToLower().Equals("guest")) + { + guests.Add(new User() { DisplayName = user.DisplayName, Id = user.Id, UserPrincipalName = user.UserPrincipalName, UserType = "Guest" }); + } + else + { + members.Add(new User() { DisplayName = user.DisplayName, Id = user.Id, UserPrincipalName = user.UserPrincipalName, UserType = "Member" }); + } + } + } + } + var finalList = new List(); + if (string.IsNullOrEmpty(selectedRole)) + { + finalList.AddRange(owners); + finalList.AddRange(members); + finalList.AddRange(guests); + } + else if (selectedRole == "owner") + { + finalList.AddRange(owners); + } + else if (selectedRole == "member") + { + finalList.AddRange(members); + } + else if (selectedRole == "guest") + { + finalList.AddRange(guests); + } + return finalList; + } + + public static void DeleteUser(HttpClient httpClient, string accessToken, string groupId, string upn, string role) + { + var user = GraphHelper.GetAsync(httpClient, $"v1.0/users/{upn}?$select=Id", accessToken).GetAwaiter().GetResult(); + if (user != null) + { + // check if the user is an owner + var owners = GraphHelper.GetAsync>(httpClient, $"v1.0/groups/{groupId}/owners?$select=Id", accessToken).GetAwaiter().GetResult(); + if (owners.Items.Any() && owners.Items.FirstOrDefault(u => u.Id.Equals(user.Id, StringComparison.OrdinalIgnoreCase)) != null) + { + if (owners.Items.Count() == 1) + { + throw new PSInvalidOperationException("Last owner cannot be removed"); + } + GraphHelper.DeleteAsync(httpClient, $"v1.0/groups/{groupId}/owners/{user.Id}/$ref", accessToken).GetAwaiter().GetResult(); + } + if (!role.Equals("owner", StringComparison.OrdinalIgnoreCase)) + { + GraphHelper.DeleteAsync(httpClient, $"v1.0/groups/{groupId}/members/{user.Id}/$ref", accessToken).GetAwaiter().GetResult(); + } + } + } + + #endregion + + #region Channel + public static IEnumerable GetChannels(string accessToken, HttpClient httpClient, string groupId) + { + var collection = GraphHelper.GetAsync>(httpClient, $"beta/teams/{groupId}/channels", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + return collection.Items; + } + else + { + return null; + } + } + + public static HttpResponseMessage DeleteChannel(string accessToken, HttpClient httpClient, string groupId, string channelId) + { + return GraphHelper.DeleteAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}", accessToken).GetAwaiter().GetResult(); + } + + public static TeamChannel AddChannel(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, bool isPrivate) + { + var channel = new TeamChannel() + { + Description = description, + DisplayName = displayName, + }; + if (isPrivate) + { + channel.MembershipType = "private"; + } + return GraphHelper.PostAsync(httpClient, $"beta/teams/{groupId}/channels", channel, accessToken).GetAwaiter().GetResult(); + } + + public static void PostMessage(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannelMessage message) + { + GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/messages", message, accessToken).GetAwaiter().GetResult(); + } + + public static List GetMessages(HttpClient httpClient, string accessToken, string groupId, string channelId, bool includeDeleted = false) + { + List messages = new List(); + var collection = GraphHelper.GetAsync>(httpClient, $"beta/teams/{groupId}/channels/{channelId}/messages", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + messages.AddRange(collection.Items); + while (collection != null && !string.IsNullOrEmpty(collection.NextLink)) + { + collection = GraphHelper.GetAsync>(httpClient, collection.NextLink, accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + messages.AddRange(collection.Items); + } + } + } + if (includeDeleted) + { + return messages; + } + else + { + return messages.Where(m => !m.DeletedDateTime.HasValue).ToList(); + } + } + + public static TeamChannel UpdateChannel(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannel channel) + { + return GraphHelper.PatchAsync(httpClient, accessToken, $"beta/teams/{groupId}/channels/{channelId}", channel).GetAwaiter().GetResult(); + } + #endregion + + #region Tabs + public static IEnumerable GetTabs(string accessToken, HttpClient httpClient, string groupId, string channelId) + { + var collection = GraphHelper.GetAsync>(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/tabs", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + return collection.Items; + } + return null; + } + + public static TeamTab GetTab(string accessToken, HttpClient httpClient, string groupId, string channelId, string tabId) + { + return GraphHelper.GetAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/tabs/{tabId}", accessToken).GetAwaiter().GetResult(); + } + + public static HttpResponseMessage DeleteTab(string accessToken, HttpClient httpClient, string groupId, string channelId, string tabId) + { + return GraphHelper.DeleteAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/tabs/{tabId}", accessToken).GetAwaiter().GetResult(); + } + + public static void UpdateTab(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamTab tab) + { + tab.Configuration = null; + GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/teams/{groupId}/channels/{channelId}/tabs/{tab.Id}", tab).GetAwaiter().GetResult(); + } + + public static TeamTab AddTab(HttpClient httpClient, string accessToken, string groupId, string channelId, string displayName, TeamTabType tabType, string teamsAppId, string entityId, string contentUrl, string removeUrl, string websiteUrl) + { + TeamTab tab = new TeamTab(); + tab.Configuration = new TeamTabConfiguration(); + switch (tabType) + { + case TeamTabType.Custom: + { + tab.TeamsAppId = teamsAppId; + tab.Configuration.EntityId = entityId; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = removeUrl; + tab.Configuration.WebsiteUrl = websiteUrl; + break; + } + case TeamTabType.DocumentLibrary: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.files.sharepoint"; + tab.Configuration.EntityId = ""; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = null; + break; + } + case TeamTabType.WebSite: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.web"; + tab.Configuration.EntityId = null; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = contentUrl; + break; + } + case TeamTabType.Word: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.file.staticviewer.word"; + tab.Configuration.EntityId = entityId; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = null; + break; + } + case TeamTabType.Excel: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.file.staticviewer.excel"; + tab.Configuration.EntityId = entityId; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = null; + break; + } + case TeamTabType.PowerPoint: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.file.staticviewer.powerpoint"; + tab.Configuration.EntityId = entityId; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = null; + break; + } + case TeamTabType.PDF: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.file.staticviewer.pdf"; + tab.Configuration.EntityId = entityId; + tab.Configuration.ContentUrl = contentUrl; + tab.Configuration.RemoveUrl = null; + tab.Configuration.WebsiteUrl = null; + break; + } + case TeamTabType.Wiki: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.wiki"; + break; + } + case TeamTabType.Planner: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.planner"; + break; + } + case TeamTabType.MicrosoftStream: + { + tab.TeamsAppId = "com.microsoftstream.embed.skypeteamstab"; + break; + } + case TeamTabType.MicrosoftForms: + { + tab.TeamsAppId = "81fef3a6-72aa-4648-a763-de824aeafb7d"; + break; + } + case TeamTabType.OneNote: + { + tab.TeamsAppId = "0d820ecd-def2-4297-adad-78056cde7c78"; + break; + } + case TeamTabType.PowerBI: + { + tab.TeamsAppId = "com.microsoft.teamspace.tab.powerbi"; + break; + } + case TeamTabType.SharePointPageAndList: + { + tab.TeamsAppId = "2a527703-1f6f-4559-a332-d8a7d288cd88"; + break; + } + } + tab.DisplayName = displayName; + tab.TeamsApp = $"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/{tab.TeamsAppId}"; + return GraphHelper.PostAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/tabs", tab, accessToken).GetAwaiter().GetResult(); + } + #endregion + + #region Apps + public static IEnumerable GetApps(string accessToken, HttpClient httpClient) + { + var collection = GraphHelper.GetAsync>(httpClient, $"v1.0/appCatalogs/teamsApps", accessToken).GetAwaiter().GetResult(); + if (collection != null) + { + return collection.Items; + } + return null; + } + + public static TeamApp AddApp(HttpClient httpClient, string accessToken, byte[] bytes) + { + var byteArrayContent = new ByteArrayContent(bytes); + byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip"); + var response = GraphHelper.PostAsync(httpClient, "v1.0/appCatalogs/teamsApps", accessToken, byteArrayContent).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + if (GraphHelper.TryGetGraphException(response, out GraphException exception)) + { + throw exception; + } + } + else + { + var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + return JsonConvert.DeserializeObject(content); + } + return null; + } + + public static HttpResponseMessage UpdateApp(HttpClient httpClient, string accessToken, byte[] bytes, string appId) + { + var byteArrayContent = new ByteArrayContent(bytes); + byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip"); + return GraphHelper.PutAsync(httpClient, $"v1.0/appCatalogs/teamsApps/{appId}", accessToken, byteArrayContent).GetAwaiter().GetResult(); + } + + public static HttpResponseMessage DeleteApp(HttpClient httpClient, string accessToken, string appId) + { + return GraphHelper.DeleteAsync(httpClient, $"v1.0/appCatalogs/teamsApps/{appId}", accessToken).GetAwaiter().GetResult(); + } + #endregion + } +} \ No newline at end of file diff --git a/Commands/Webhooks/GetWebhookSubscriptions.cs b/Commands/Webhooks/GetWebhookSubscriptions.cs index 8dd6d894d..b291e0981 100644 --- a/Commands/Webhooks/GetWebhookSubscriptions.cs +++ b/Commands/Webhooks/GetWebhookSubscriptions.cs @@ -4,8 +4,8 @@ using OfficeDevPnP.Core.Entities; using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; -using System; using System.Management.Automation; +using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources; namespace SharePointPnP.PowerShell.Commands.Webhooks { @@ -18,9 +18,13 @@ namespace SharePointPnP.PowerShell.Commands.Webhooks Code = "PS:> Get-PnPWebhookSubscriptions -List MyList", Remarks = "Gets all Webhook subscriptions of the list MyList", SortOrder = 1)] + [CmdletExample( + Code = "PS:> Get-PnPList | Get-PnPWebhookSubscriptions", + Remarks = "Gets all Webhook subscriptions of the all the lists", + SortOrder = 2)] public class GetWebhookSubscriptions : PnPWebCmdlet { - [Parameter(Mandatory = false, HelpMessage = "The list object or name to get the Webhook subscriptions from")] + [Parameter(Mandatory = false, ValueFromPipeline = true, HelpMessage = "The list object or name to get the Webhook subscriptions from")] public ListPipeBind List; protected override void ExecuteCmdlet() @@ -28,23 +32,29 @@ protected override void ExecuteCmdlet() // NOTE: Currently only supports List Webhooks if (ParameterSpecified(nameof(List))) { + // Ensure we didn't get piped in a null, i.e. when running Get-PnPList -Identity "ThisListDoesNotExist" | Get-PnPWebhookSubscriptions + if(List == null) + { + throw new PSArgumentNullException(nameof(List)); + } + // Get the list from the currently selected web List list = List.GetList(SelectedWeb); if (list != null) { - // Ensure we have list Id (TODO Should be changed in the Core extension method) - list.EnsureProperty(l => l.Id); - // Get all the webhook subscriptions for the specified list WriteObject(list.GetWebhookSubscriptions()); } + else + { + throw new PSArgumentOutOfRangeException(nameof(List), List.ToString(), string.Format(Resources.ListNotFound, List.ToString())); + } } else { - throw new PSNotImplementedException("This Cmdlet only supports List Webhooks currently"); + throw new PSNotImplementedException(Resources.WebhooksOnlySupportsLists); } } - } } diff --git a/Commands/packages.config b/Commands/packages.config index 241cf5f20..45cceac5b 100644 --- a/Commands/packages.config +++ b/Commands/packages.config @@ -17,7 +17,7 @@ - + diff --git a/HelpAttributes/CmdletMicrosoftGraphApiPermission.cs b/HelpAttributes/CmdletMicrosoftGraphApiPermission.cs index 52bdbb33b..304c7911c 100644 --- a/HelpAttributes/CmdletMicrosoftGraphApiPermission.cs +++ b/HelpAttributes/CmdletMicrosoftGraphApiPermission.cs @@ -9,6 +9,8 @@ namespace SharePointPnP.PowerShell.CmdletHelpAttributes [Flags] public enum MicrosoftGraphApiPermission : int { + None = 0, + #region Groups - https://docs.microsoft.com/graph/permissions-reference#group-permissions /// @@ -89,7 +91,18 @@ public enum MicrosoftGraphApiPermission : int /// Manage all user identities /// [EnumMember(Value = "User.ManageIdentities.All")] - User_ManageIdentities_All = 2048 + User_ManageIdentities_All = 2048, + + + #endregion + + #region AppCatalog - https://docs.microsoft.com/en-gb/graph/permissions-reference#appcatalog-resource-permissions + + [EnumMember(Value = "AppCatalog.Read.All")] + AppCatalog_Read_All = 4096, + + [EnumMember(Value = "AppCatalog.ReadWrite.All")] + AppCatalog_ReadWrite_All = 8192, #endregion } @@ -108,15 +121,18 @@ public sealed class CmdletMicrosoftGraphApiPermission : CmdletApiPermissionBase /// /// One or more permissions of which only one is needed to granted to the token /// - public MicrosoftGraphApiPermission ApiPermission { get; set; } + public MicrosoftGraphApiPermission OrApiPermissions { get; set; } + + public MicrosoftGraphApiPermission AndApiPermissions { get; set; } /// /// Constructs a new ApiPermissionAttribute /// /// One or more possible permissions of which only one is needed to be granted in the token - public CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission apiPermission) + public CmdletMicrosoftGraphApiPermission(MicrosoftGraphApiPermission orPermissions, MicrosoftGraphApiPermission andPermissions = MicrosoftGraphApiPermission.None) { - ApiPermission = apiPermission; + OrApiPermissions = orPermissions; + AndApiPermissions = andPermissions; } } } diff --git a/HelpAttributes/CmdletOfficeManagementApiPermission.cs b/HelpAttributes/CmdletOfficeManagementApiPermission.cs index c77fd437e..61f62b072 100644 --- a/HelpAttributes/CmdletOfficeManagementApiPermission.cs +++ b/HelpAttributes/CmdletOfficeManagementApiPermission.cs @@ -9,6 +9,8 @@ namespace SharePointPnP.PowerShell.CmdletHelpAttributes [Flags] public enum OfficeManagementApiPermission : int { + None = 0, + [EnumMember(Value = "ActivityFeed.Read")] ActivityFeed_Read = 1, @@ -31,15 +33,17 @@ public sealed class CmdletOfficeManagementApiPermissionAttribute : CmdletApiPerm /// /// One or more permissions of which only one is needed to granted to the token /// - public OfficeManagementApiPermission ApiPermission { get; set; } + public OfficeManagementApiPermission OrApiPermissions { get; set; } + public OfficeManagementApiPermission AndApiPermissions { get; set; } /// /// Constructs a new ApiPermissionAttribute /// /// One or more possible permissions of which only one is needed to be granted in the token - public CmdletOfficeManagementApiPermissionAttribute(OfficeManagementApiPermission apiPermission) + public CmdletOfficeManagementApiPermissionAttribute(OfficeManagementApiPermission orApiPermissions, OfficeManagementApiPermission andApiPermissions = OfficeManagementApiPermission.None) { - ApiPermission = apiPermission; + OrApiPermissions = orApiPermissions; + AndApiPermissions = andApiPermissions; } } } diff --git a/HelpAttributes/CmdletTokenTypeAttribute.cs b/HelpAttributes/CmdletTokenTypeAttribute.cs new file mode 100644 index 000000000..d74b5d3e9 --- /dev/null +++ b/HelpAttributes/CmdletTokenTypeAttribute.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharePointPnP.PowerShell.Core.Attributes +{ + public enum TokenType : short + { + All = 0, + Application = 1, + Delegate = 2 + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public sealed class CmdletTokenTypeAttribute : Attribute + { + public TokenType TokenType { get; set; } + + public CmdletTokenTypeAttribute(TokenType tokenType = TokenType.All) + { + TokenType = tokenType; + } + } +} diff --git a/HelpAttributes/SharePointPnP.PowerShell.CmdletHelpAttributes.csproj b/HelpAttributes/SharePointPnP.PowerShell.CmdletHelpAttributes.csproj index 946daf062..6b49f4543 100644 --- a/HelpAttributes/SharePointPnP.PowerShell.CmdletHelpAttributes.csproj +++ b/HelpAttributes/SharePointPnP.PowerShell.CmdletHelpAttributes.csproj @@ -112,6 +112,7 @@ + diff --git a/ModuleFilesGenerator/HelpFileGenerator.cs b/ModuleFilesGenerator/HelpFileGenerator.cs index 2dee1f696..2542d6501 100644 --- a/ModuleFilesGenerator/HelpFileGenerator.cs +++ b/ModuleFilesGenerator/HelpFileGenerator.cs @@ -73,48 +73,69 @@ private XElement GetCommandElement(Model.CmdletInfo cmdletInfo) additionalDescriptionInfo.AppendLine("* Required API permissions:"); // Go through each of the API permissions on this cmdlet and build a dictionary with the API type as the key and the requested scope(s) on it as the value - var requiredPermissionByApiDictionary = new Dictionary>(cmdletInfo.ApiPermissions.Count); + var requiredOrPermissionByApiDictionary = new Dictionary>(cmdletInfo.ApiPermissions.Count); + var requiredAndPermissionByApiDictionary = new Dictionary>(cmdletInfo.ApiPermissions.Count); foreach (var requiredApiPermission in cmdletInfo.ApiPermissions) { - // Through reflection, get the friendly name of the API and the permission scopes. We must use reflection here as generic attribute types do not exist in C# yet. Multiple scopes are returned as a comma-space separated string. - var scopePermission = requiredApiPermission.GetType().GetProperty("ApiPermission")?.GetValue(requiredApiPermission, null); - // If we were unable to retrieve the scopes and/or api through reflection, continue with the next permission attribute - if (scopePermission == null || requiredApiPermission.ApiName == null) continue; + requiredOrPermissionByApiDictionary = ParseApiPermissions("OrApiPermissions", requiredApiPermission, requiredOrPermissionByApiDictionary); + requiredAndPermissionByApiDictionary = ParseApiPermissions("AndApiPermissions", requiredApiPermission, requiredAndPermissionByApiDictionary); + + //// Through reflection, get the friendly name of the API and the permission scopes. We must use reflection here as generic attribute types do not exist in C# yet. Multiple scopes are returned as a comma-space separated string. + //var scopePermission = requiredApiPermission.GetType().GetProperty("OrApiPermissions")?.GetValue(requiredApiPermission, null); + + //// If we were unable to retrieve the scopes and/or api through reflection, continue with the next permission attribute + //if (scopePermission == null || requiredApiPermission.ApiName == null) continue; + + //// Ensure our dictionary with APIs already has an entry for the current API being processed + //if(!requiredPermissionByApiDictionary.ContainsKey(requiredApiPermission.ApiName)) + //{ + // // Add another entry to the dictionary for this API + // requiredPermissionByApiDictionary.Add(requiredApiPermission.ApiName, new List()); + //} + + //// The returned scopes are the enum names which use an underscore instead of a dot for the scope names and are comma-space separated if multiple scopes are possible + //var scopes = scopePermission.ToString().Replace("_", ".").Split(','); + + //// Go through each scope + //foreach (var scope in scopes) + //{ + // // Remove the potential trailing space + // var trimmedScope = scope.Trim(); + + // // If the scope is not known to be required yet, add it to the dictionary with APIs and requested scopes + // if (!requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Contains(trimmedScope)) + // { + // requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Add(trimmedScope); + // } + //} + } - // Ensure our dictionary with APIs already has an entry for the current API being processed - if(!requiredPermissionByApiDictionary.ContainsKey(requiredApiPermission.ApiName)) + // Loop through all the items in our dictionary with API types and requested scopes on the API so we can add it to the help text output + foreach (var requiredPermissionDictionaryItem in requiredOrPermissionByApiDictionary) + { + if (requiredPermissionDictionaryItem.Value.Count > 0) { - // Add another entry to the dictionary for this API - requiredPermissionByApiDictionary.Add(requiredApiPermission.ApiName, new List()); + additionalDescriptionInfo.AppendLine($" * {requiredPermissionDictionaryItem.Key}: {string.Join(" or ", requiredPermissionDictionaryItem.Value.OrderBy(s => s))}"); } - - // The returned scopes are the enum names which use an underscore instead of a dot for the scope names and are comma-space separated if multiple scopes are possible - var scopes = scopePermission.ToString().Replace("_", ".").Split(','); - - // Go through each scope - foreach (var scope in scopes) + } + foreach (var requiredPermissionDictionaryItem in requiredAndPermissionByApiDictionary) + { + if (requiredPermissionDictionaryItem.Value.Count > 0) { - // Remove the potential trailing space - var trimmedScope = scope.Trim(); - - // If the scope is not known to be required yet, add it to the dictionary with APIs and requested scopes - if (!requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Contains(trimmedScope)) - { - requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Add(trimmedScope); - } + additionalDescriptionInfo.AppendLine($" * {requiredPermissionDictionaryItem.Key}: {string.Join(" and ", requiredPermissionDictionaryItem.Value.OrderBy(s => s))}"); } } - // Loop through all the items in our dictionary with API types and requested scopes on the API so we can add it to the help text output - foreach(var requiredPermissionDictionaryItem in requiredPermissionByApiDictionary) - { - additionalDescriptionInfo.AppendLine($" * {requiredPermissionDictionaryItem.Key}: {string.Join(" or ", requiredPermissionDictionaryItem.Value.OrderBy(s => s))}"); - } - additionalDescriptionInfo.AppendLine(); } + // Notice if the cmdlet is a PnPAdminCmdlet that access to the SharePoint Tenant Admin site is needed + if (cmdletInfo.CmdletType.BaseType.Name.Equals("PnPAdminCmdlet")) + { + additionalDescriptionInfo.AppendLine("* Required SharePoint permissions: Access to the SharePoint Tenant Administration site"); + } + // Validate if additional information should be prepended to the description if (additionalDescriptionInfo.Length > 0) { @@ -157,6 +178,41 @@ private XElement GetSyntaxElement(Model.CmdletInfo cmdletInfo) return syntaxElement; } + private Dictionary> ParseApiPermissions(string propertyName, CmdletApiPermissionBase requiredApiPermission, Dictionary> requiredPermissionByApiDictionary) + { + // Through reflection, get the friendly name of the API and the permission scopes. We must use reflection here as generic attribute types do not exist in C# yet. Multiple scopes are returned as a comma-space separated string. + var scopePermission = requiredApiPermission.GetType().GetProperty(propertyName)?.GetValue(requiredApiPermission, null); + + // If we were unable to retrieve the scopes and/or api through reflection, continue with the next permission attribute + if (scopePermission != null && requiredApiPermission.ApiName != null) + { + + // Ensure our dictionary with APIs already has an entry for the current API being processed + if (!requiredPermissionByApiDictionary.ContainsKey(requiredApiPermission.ApiName)) + { + // Add another entry to the dictionary for this API + requiredPermissionByApiDictionary.Add(requiredApiPermission.ApiName, new List()); + } + + // The returned scopes are the enum names which use an underscore instead of a dot for the scope names and are comma-space separated if multiple scopes are possible + var scopes = scopePermission.ToString().Replace("_", ".").Split(',').Where(s => s != "None"); + + // Go through each scope + foreach (var scope in scopes) + { + // Remove the potential trailing space + var trimmedScope = scope.Trim(); + + // If the scope is not known to be required yet, add it to the dictionary with APIs and requested scopes + if (!requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Contains(trimmedScope)) + { + requiredPermissionByApiDictionary[requiredApiPermission.ApiName].Add(trimmedScope); + } + } + } + return requiredPermissionByApiDictionary; + } + private XElement GetParametersElement(Model.CmdletInfo cmdletInfo) { var parametersElement = new XElement(command + "parameters"); @@ -264,8 +320,13 @@ private XElement GetExamplesElement(Model.CmdletInfo cmdletInfo) private XElement GetRelatedLinksElement(Model.CmdletInfo cmdletInfo) { var relatedLinksElement = new XElement(maml + "relatedLinks"); - cmdletInfo.RelatedLinks.Insert(0, new CmdletRelatedLinkAttribute() { Text = "SharePoint Developer Patterns and Practices", Url = "http://aka.ms/sppnp" }); - + cmdletInfo.RelatedLinks.Insert(0, new CmdletRelatedLinkAttribute { Text = "SharePoint Developer Patterns and Practices", Url = "http://aka.ms/sppnp" }); + + if(!string.IsNullOrEmpty(cmdletInfo.OutputTypeLink)) + { + cmdletInfo.RelatedLinks.Insert(1, new CmdletRelatedLinkAttribute { Text = "Output type documentation", Url = cmdletInfo.OutputTypeLink }); + } + foreach (var link in cmdletInfo.RelatedLinks) { var navigationLinksElement = new XElement(maml + "navigationLink"); diff --git a/ModuleFilesGenerator/ModuleManifestGenerator.cs b/ModuleFilesGenerator/ModuleManifestGenerator.cs index 20294b200..f06865ddf 100644 --- a/ModuleFilesGenerator/ModuleManifestGenerator.cs +++ b/ModuleFilesGenerator/ModuleManifestGenerator.cs @@ -71,7 +71,7 @@ internal void Generate() #if !NETCOREAPP3_0 var psd1Path = $"{new FileInfo(_assemblyPath).Directory}\\ModuleFiles\\SharePointPnPPowerShell{spVersion}.psd1"; #else - var psd1Path = $"{new FileInfo(_assemblyPath).Directory}\\ModuleFiles\\SharePointPnPPowerShellCore.psd1"; + var psd1Path = $"{new FileInfo(_assemblyPath).Directory}\\ModuleFiles\\PnPPowerShellCore.psd1"; #endif var cmdletsToExportString = string.Join(",", _cmdlets.Select(c => "'" + c.FullCommand + "'")); string aliasesToExportString = null; @@ -102,25 +102,25 @@ private void WriteModuleManifest(string path, string spVersion, string cmdletsTo PrivateData = @{{ PSData = @{{ ProjectUri = 'https://aka.ms/sppnp' - IconUri = 'https://raw.githubusercontent.com/pnp/media/master/optimized/pnp-projects/blue/png/pnp-powershell-300.png' + IconUri = 'https://github.com/pnp/media/blob/19f8d40f400f9f0d766a8efd69496d8f536b853f/parker/ms/300w/parker-ms-300.png' }} }} }}"; #else var manifest = $@"@{{ - RootModule = 'SharePointPnP.PowerShell.Core.dll' + RootModule = 'PnP.PowerShell.Core.dll' ModuleVersion = '{_assemblyVersion}' Description = 'SharePoint Patterns and Practices PowerShell Cmdlets for SharePoint Online' GUID = '0b0430ce-d799-4f3b-a565-f0dca1f31e17' Author = 'SharePoint Patterns and Practices' CompanyName = 'SharePoint Patterns and Practices' - PowerShellVersion = '5.0' + PowerShellVersion = '7.0' ProcessorArchitecture = 'None' FunctionsToExport = '*' CmdletsToExport = {cmdletsToExport} VariablesToExport = '*' AliasesToExport = '*' - FormatsToProcess = 'SharePointPnP.PowerShell.{spVersion}.Format.ps1xml' + FormatsToProcess = 'PnP.PowerShell.{spVersion}.Format.ps1xml' PrivateData = @{{ PSData = @{{ ProjectUri = 'https://aka.ms/sppnp' diff --git a/PostBuild.ps1 b/PostBuild.ps1 index 750e57b66..5eab131b8 100644 --- a/PostBuild.ps1 +++ b/PostBuild.ps1 @@ -5,7 +5,7 @@ if($ConfigurationName -like "Debug*") $documentsFolder = [environment]::getfolderpath("mydocuments"); if($TargetDir -like "*Core*") { - $DestinationFolder = "$documentsFolder\PowerShell\Modules\SharePointPnPPowerShellCore" + $DestinationFolder = "$documentsFolder\PowerShell\Modules\PnPPowerShellCore" } else { if($ConfigurationName -like "Debug15") { @@ -83,23 +83,28 @@ if($ConfigurationName -like "Debug*") } elseif ($ConfigurationName -like "Release*") { $documentsFolder = [environment]::getfolderpath("mydocuments"); - switch($ConfigurationName) + if($TargetDir -like "*Core*") { - "Release15" - { - $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2013" - } - "Release16" - { - $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2016" - } - "Release19" - { - $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2019" - } - "Release" + $DestinationFolder = "$documentsFolder\PowerShell\Modules\PnPPowerShellCore" + } else { + switch($ConfigurationName) { - $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline" + "Release15" + { + $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2013" + } + "Release16" + { + $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2016" + } + "Release19" + { + $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShell2019" + } + "Release" + { + $DestinationFolder = "$documentsFolder\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline" + } } } @@ -119,38 +124,44 @@ if($ConfigurationName -like "Debug*") { Copy-Item "$TargetDir\*.dll" -Destination "$DestinationFolder" Copy-Item "$TargetDir\*help.xml" -Destination "$DestinationFolder" - switch($ConfigurationName) + if($TargetDir -like "*Core*") { - "Release15" { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013.psd1" -Destination "$DestinationFolder" - Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2013.Commands.Format.ps1xml" -Destination "$DestinationFolder" - if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013Aliases.psm1") - { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013Aliases.psm1" -Destination "$DestinationFolder" - } - } - "Release16" { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016.psd1" -Destination "$DestinationFolder" - Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2016.Commands.Format.ps1xml" -Destination "$DestinationFolder" - if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016Aliases.psm1") - { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016Aliases.psm1" -Destination "$DestinationFolder" - } - } - "Release19" { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019.psd1" -Destination "$DestinationFolder" - Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2019.Commands.Format.ps1xml" -Destination "$DestinationFolder" - if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019Aliases.psm1") - { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019Aliases.psm1" -Destination "$DestinationFolder" - } - } - "Release" { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnline.psd1" -Destination "$DestinationFolder" - Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.Online.Commands.Format.ps1xml" -Destination "$DestinationFolder" - if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnlineAliases.psm1") - { - Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnlineAliases.psm1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\PnPPowerShellCore.psd1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\PnP.PowerShell.Core.Format.ps1xml" -Destination "$DestinationFolder" + } else { + switch($ConfigurationName) + { + "Release15" { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013.psd1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2013.Commands.Format.ps1xml" -Destination "$DestinationFolder" + if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013Aliases.psm1") + { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2013Aliases.psm1" -Destination "$DestinationFolder" + } + } + "Release16" { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016.psd1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2016.Commands.Format.ps1xml" -Destination "$DestinationFolder" + if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016Aliases.psm1") + { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2016Aliases.psm1" -Destination "$DestinationFolder" + } + } + "Release19" { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019.psd1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.2019.Commands.Format.ps1xml" -Destination "$DestinationFolder" + if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019Aliases.psm1") + { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShell2019Aliases.psm1" -Destination "$DestinationFolder" + } + } + "Release" { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnline.psd1" -Destination "$DestinationFolder" + Copy-Item "$TargetDir\ModuleFiles\SharePointPnP.PowerShell.Online.Commands.Format.ps1xml" -Destination "$DestinationFolder" + if(Test-Path -Path "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnlineAliases.psm1") + { + Copy-Item "$TargetDir\ModuleFiles\SharePointPnPPowerShellOnlineAliases.psm1" -Destination "$DestinationFolder" + } } } } diff --git a/SharePointPnP.PowerShell.sln b/SharePointPnP.PowerShell.sln index dbfbb3710..984fe6adb 100644 --- a/SharePointPnP.PowerShell.sln +++ b/SharePointPnP.PowerShell.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2026 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30128.74 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharePointPnP.PowerShell.Commands", "Commands\SharePointPnP.PowerShell.Commands.csproj", "{1DDE6F0A-CA49-419A-9CE8-A6CA02F43CE0}" ProjectSection(ProjectDependencies) = postProject @@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat CHANGELOG.md = CHANGELOG.md CONTRIBUTING.md = CONTRIBUTING.md readme.md = readme.md + Tests\UnitTests-Readme.md = Tests\UnitTests-Readme.md version.txt = version.txt EndProjectSection EndProject diff --git a/Tests/Admin/AddPnPHubSiteAssociationTests.cs b/Tests/Admin/AddPnPHubSiteAssociationTests.cs new file mode 100644 index 000000000..28c338484 --- /dev/null +++ b/Tests/Admin/AddPnPHubSiteAssociationTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddHubSiteAssociationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPHubSiteAssociationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site to connect to the hubsite + var site = ""; + // This is a mandatory parameter + // From Cmdlet Help: The hubsite to connect the site to + var hubSite = ""; + + var results = scope.ExecuteCommand("Add-PnPHubSiteAssociation", + new CommandParameter("Site", site), + new CommandParameter("HubSite", hubSite)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPOffice365GroupToSiteTests.cs b/Tests/Admin/AddPnPOffice365GroupToSiteTests.cs new file mode 100644 index 000000000..293e1b13e --- /dev/null +++ b/Tests/Admin/AddPnPOffice365GroupToSiteTests.cs @@ -0,0 +1,104 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddOffice365GroupToSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPOffice365GroupToSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Url of the site to be connected to an Microsoft 365 Group + var url = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the alias of the group. Cannot contain spaces. + var alias = ""; + // From Cmdlet Help: The optional description of the group + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: The display name of the group + var displayName = ""; + // From Cmdlet Help: Specifies the classification of the group + var classification = ""; + // From Cmdlet Help: Specifies if the group is public. Defaults to false. + var isPublic = ""; + // From Cmdlet Help: Specifies if the current site home page is kept. Defaults to false. + var keepOldHomePage = ""; + // From Cmdlet Help: If specified the site will be associated to the hubsite as identified by this id + var hubSiteId = ""; + // From Cmdlet Help: The array UPN values of the group's owners. + var owners = ""; + + var results = scope.ExecuteCommand("Add-PnPOffice365GroupToSite", + new CommandParameter("Url", url), + new CommandParameter("Alias", alias), + new CommandParameter("Description", description), + new CommandParameter("DisplayName", displayName), + new CommandParameter("Classification", classification), + new CommandParameter("IsPublic", isPublic), + new CommandParameter("KeepOldHomePage", keepOldHomePage), + new CommandParameter("HubSiteId", hubSiteId), + new CommandParameter("Owners", owners)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPOrgAssetsLibraryTests.cs b/Tests/Admin/AddPnPOrgAssetsLibraryTests.cs new file mode 100644 index 000000000..25d7d3060 --- /dev/null +++ b/Tests/Admin/AddPnPOrgAssetsLibraryTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddOrgAssetsLibraryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPOrgAssetsLibraryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The full url of the document library to be marked as one of organization's assets sources + var libraryUrl = ""; + // From Cmdlet Help: The full url to an image that should be used as a thumbnail for showing this source. The image must reside in the same site as the document library you specify. + var thumbnailUrl = ""; + // From Cmdlet Help: Indicates what type of Office 365 CDN source the document library will be added to + var cdnType = ""; + + var results = scope.ExecuteCommand("Add-PnPOrgAssetsLibrary", + new CommandParameter("LibraryUrl", libraryUrl), + new CommandParameter("ThumbnailUrl", thumbnailUrl), + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPOrgNewsSiteTests.cs b/Tests/Admin/AddPnPOrgNewsSiteTests.cs new file mode 100644 index 000000000..02b1fc340 --- /dev/null +++ b/Tests/Admin/AddPnPOrgNewsSiteTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddOrgNewsSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPOrgNewsSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The url of the site to be marked as one of organization's news sites + var orgNewsSiteUrl = ""; + + var results = scope.ExecuteCommand("Add-PnPOrgNewsSite", + new CommandParameter("OrgNewsSiteUrl", orgNewsSiteUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPSiteCollectionAppCatalogTests.cs b/Tests/Admin/AddPnPSiteCollectionAppCatalogTests.cs new file mode 100644 index 000000000..d6f9474fb --- /dev/null +++ b/Tests/Admin/AddPnPSiteCollectionAppCatalogTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddSiteCollectionAppCatalogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteCollectionAppCatalogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Url of the site to add the app catalog to. + var site = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteCollectionAppCatalog", + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPTenantCdnOriginTests.cs b/Tests/Admin/AddPnPTenantCdnOriginTests.cs new file mode 100644 index 000000000..be278a1b7 --- /dev/null +++ b/Tests/Admin/AddPnPTenantCdnOriginTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddTenantCdnOriginTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTenantCdnOriginTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies a path to the doc library to be configured. It can be provided in two ways: relative path, or a mask.Relative-Relative path depends on the OriginScope. If the originScope is Tenant, a path must be a relative path under the tenant root. If the originScope is Site, a path must be a relative path under the given Site. The path must point to the valid Document Library or a folder with a document library. + var originUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the CDN type. The valid values are: public or private. + var cdnType = ""; + + var results = scope.ExecuteCommand("Add-PnPTenantCdnOrigin", + new CommandParameter("OriginUrl", originUrl), + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/AddPnPTenantThemeTests.cs b/Tests/Admin/AddPnPTenantThemeTests.cs new file mode 100644 index 000000000..8a4af5c8d --- /dev/null +++ b/Tests/Admin/AddPnPTenantThemeTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class AddTenantThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTenantThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: If a theme is already present, specifying this will overwrite the existing theme + var overwrite = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the theme to add or update + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The palette to add. See examples for more information. + var palette = ""; + // This is a mandatory parameter + // From Cmdlet Help: If the theme is inverted or not + var isInverted = ""; + + var results = scope.ExecuteCommand("Add-PnPTenantTheme", + new CommandParameter("Overwrite", overwrite), + new CommandParameter("Identity", identity), + new CommandParameter("Palette", palette), + new CommandParameter("IsInverted", isInverted)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/ClearPnPTenantAppCatalogUrlTests.cs b/Tests/Admin/ClearPnPTenantAppCatalogUrlTests.cs new file mode 100644 index 000000000..233f6b5b7 --- /dev/null +++ b/Tests/Admin/ClearPnPTenantAppCatalogUrlTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class ClearTenantAppCatalogUrlTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ClearPnPTenantAppCatalogUrlTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Clear-PnPTenantAppCatalogUrl"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPHideDefaultThemesTests.cs b/Tests/Admin/GetPnPHideDefaultThemesTests.cs new file mode 100644 index 000000000..41747104e --- /dev/null +++ b/Tests/Admin/GetPnPHideDefaultThemesTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetHideDefaultThemesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHideDefaultThemesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPHideDefaultThemes"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPHomeSiteTests.cs b/Tests/Admin/GetPnPHomeSiteTests.cs new file mode 100644 index 000000000..8a89b6832 --- /dev/null +++ b/Tests/Admin/GetPnPHomeSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetHomeSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHomeSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPHomeSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPHubSiteChildTests.cs b/Tests/Admin/GetPnPHubSiteChildTests.cs new file mode 100644 index 000000000..4fe765392 --- /dev/null +++ b/Tests/Admin/GetPnPHubSiteChildTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetHubSiteChildTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHubSiteChildTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The URL of the hubsite for which to receive the sites refering to it + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPHubSiteChild", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPHubSiteTests.cs b/Tests/Admin/GetPnPHubSiteTests.cs new file mode 100644 index 000000000..84c21d66e --- /dev/null +++ b/Tests/Admin/GetPnPHubSiteTests.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPHubSite", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPKnowledgeHubSiteTests.cs b/Tests/Admin/GetPnPKnowledgeHubSiteTests.cs new file mode 100644 index 000000000..aa4311dd6 --- /dev/null +++ b/Tests/Admin/GetPnPKnowledgeHubSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetKnowledgeHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPKnowledgeHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPKnowledgeHubSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPOrgAssetsLibraryTests.cs b/Tests/Admin/GetPnPOrgAssetsLibraryTests.cs new file mode 100644 index 000000000..94e626ef4 --- /dev/null +++ b/Tests/Admin/GetPnPOrgAssetsLibraryTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetOrgAssetsLibraryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOrgAssetsLibraryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPOrgAssetsLibrary"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPOrgNewsSiteTests.cs b/Tests/Admin/GetPnPOrgNewsSiteTests.cs new file mode 100644 index 000000000..02596d39a --- /dev/null +++ b/Tests/Admin/GetPnPOrgNewsSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetOrgNewsSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOrgNewsSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPOrgNewsSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPStorageEntityTests.cs b/Tests/Admin/GetPnPStorageEntityTests.cs new file mode 100644 index 000000000..26d04c580 --- /dev/null +++ b/Tests/Admin/GetPnPStorageEntityTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetPnPStorageEntityTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPStorageEntityTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The key of the value to retrieve. + var key = ""; + // From Cmdlet Help: Defines the scope of the storage entity. Defaults to Tenant. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Get-PnPStorageEntity", + new CommandParameter("Key", key), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantAppCatalogUrlTests.cs b/Tests/Admin/GetPnPTenantAppCatalogUrlTests.cs new file mode 100644 index 000000000..6bd1fece8 --- /dev/null +++ b/Tests/Admin/GetPnPTenantAppCatalogUrlTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantAppCatalogUrlTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantAppCatalogUrlTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantAppCatalogUrl"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantCdnEnabledTests.cs b/Tests/Admin/GetPnPTenantCdnEnabledTests.cs new file mode 100644 index 000000000..cec67e04e --- /dev/null +++ b/Tests/Admin/GetPnPTenantCdnEnabledTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantCdnEnabledTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantCdnEnabledTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The type of cdn to retrieve the origins from + var cdnType = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantCdnEnabled", + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantCdnOriginTests.cs b/Tests/Admin/GetPnPTenantCdnOriginTests.cs new file mode 100644 index 000000000..972cdb09e --- /dev/null +++ b/Tests/Admin/GetPnPTenantCdnOriginTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantCdnOriginTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantCdnOriginTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The type of cdn to retrieve the origins from + var cdnType = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantCdnOrigin", + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantCdnPoliciesTests.cs b/Tests/Admin/GetPnPTenantCdnPoliciesTests.cs new file mode 100644 index 000000000..d3a8d7796 --- /dev/null +++ b/Tests/Admin/GetPnPTenantCdnPoliciesTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantCdnPoliciesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantCdnPoliciesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The type of cdn to retrieve the policies from + var cdnType = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantCdnPolicies", + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantIdTests.cs b/Tests/Admin/GetPnPTenantIdTests.cs new file mode 100644 index 000000000..ffe0b24ba --- /dev/null +++ b/Tests/Admin/GetPnPTenantIdTests.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantIdTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantIdTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var tenantUrl = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantId", + new CommandParameter("TenantUrl", tenantUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantSiteTests.cs b/Tests/Admin/GetPnPTenantSiteTests.cs new file mode 100644 index 000000000..406794c7a --- /dev/null +++ b/Tests/Admin/GetPnPTenantSiteTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The URL of the site + var url = ""; + // From Cmdlet Help: By default, all sites will be returned. Specify a template value alike "STS#0" here to filter on the template + var template = ""; + // From Cmdlet Help: By default, not all returned attributes are populated. This switch populates all attributes. It can take several seconds to run. Without this, some attributes will show default values that may not be correct. + var detailed = ""; + // From Cmdlet Help: By default, the OneDrives are not returned. This switch includes all OneDrives. + var includeOneDriveSites = ""; + // From Cmdlet Help: When the switch IncludeOneDriveSites is used, this switch ignores the question shown that the command can take a long time to execute + var force = ""; + // From Cmdlet Help: Limit results to a specific web template name + var webTemplate = ""; + // From Cmdlet Help: Specifies the script block of the server-side filter to apply. See https://technet.microsoft.com/en-us/library/fp161380.aspx + var filter = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantSite", + new CommandParameter("Url", url), + new CommandParameter("Template", template), + new CommandParameter("Detailed", detailed), + new CommandParameter("IncludeOneDriveSites", includeOneDriveSites), + new CommandParameter("Force", force), + new CommandParameter("WebTemplate", webTemplate), + new CommandParameter("Filter", filter)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantSyncClientRestrictionTests.cs b/Tests/Admin/GetPnPTenantSyncClientRestrictionTests.cs new file mode 100644 index 000000000..436e37ac0 --- /dev/null +++ b/Tests/Admin/GetPnPTenantSyncClientRestrictionTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetPnPTenantSyncClientRestrictionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantSyncClientRestrictionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantSyncClientRestriction"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantTests.cs b/Tests/Admin/GetPnPTenantTests.cs new file mode 100644 index 000000000..82a27b1c2 --- /dev/null +++ b/Tests/Admin/GetPnPTenantTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenant"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTenantThemeTests.cs b/Tests/Admin/GetPnPTenantThemeTests.cs new file mode 100644 index 000000000..2c6740a19 --- /dev/null +++ b/Tests/Admin/GetPnPTenantThemeTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTenantThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The name of the theme to retrieve + var name = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantTheme", + new CommandParameter("Name", name)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GetPnPTimeZoneIdTests.cs b/Tests/Admin/GetPnPTimeZoneIdTests.cs new file mode 100644 index 000000000..8416e1910 --- /dev/null +++ b/Tests/Admin/GetPnPTimeZoneIdTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GetTimeZoneIdTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTimeZoneIdTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: A string to search for like 'Stockholm' + var match = ""; + + var results = scope.ExecuteCommand("Get-PnPTimeZoneId", + new CommandParameter("Match", match)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/GrantPnPHubSiteRightsTests.cs b/Tests/Admin/GrantPnPHubSiteRightsTests.cs new file mode 100644 index 000000000..743eaf24c --- /dev/null +++ b/Tests/Admin/GrantPnPHubSiteRightsTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class GrantHubSiteRightsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GrantPnPHubSiteRightsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Hub Site to set the permissions on to associate another site with this Hub Site + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: One or more usernames that will be given or revoked the permission to associate a site with this Hub Site. It does not replace permissions given out before but adds to the already existing permissions. + var principals = ""; + // From Cmdlet Help: Provide Join to give permissions to associate a site with this Hub Site or use None to revoke the permissions for the user(s) specified with the Principals argument + var rights = ""; + + var results = scope.ExecuteCommand("Grant-PnPHubSiteRights", + new CommandParameter("Identity", identity), + new CommandParameter("Principals", principals), + new CommandParameter("Rights", rights)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/InvokePnPSPRestMethodTests.cs b/Tests/Admin/InvokePnPSPRestMethodTests.cs new file mode 100644 index 000000000..e809ad394 --- /dev/null +++ b/Tests/Admin/InvokePnPSPRestMethodTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class InvokeSPRestMethodTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InvokePnPSPRestMethodTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The Http method to execute. Defaults to GET. + var method = ""; + // This is a mandatory parameter + // From Cmdlet Help: The url to execute. + var url = ""; + // From Cmdlet Help: A string or object to send + var content = ""; + // From Cmdlet Help: The content type of the object to send. Defaults to 'application/json' + var contentType = ""; + + var results = scope.ExecuteCommand("Invoke-PnPSPRestMethod", + new CommandParameter("Method", method), + new CommandParameter("Url", url), + new CommandParameter("Content", content), + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/NewPnPTenantSiteTests.cs b/Tests/Admin/NewPnPTenantSiteTests.cs new file mode 100644 index 000000000..7f77e7ccc --- /dev/null +++ b/Tests/Admin/NewPnPTenantSiteTests.cs @@ -0,0 +1,119 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class NewTenantSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the title of the new site collection + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the full URL of the new site collection. It must be in a valid managed path in the company's site. For example, for company contoso, valid managed paths are https://contoso.sharepoint.com/sites and https://contoso.sharepoint.com/teams. + var url = ""; + // From Cmdlet Help: Specifies the description of the new site collection. Setting a value for this parameter will override the Wait parameter as we have to set the description after the site has been created. + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the user name of the site collection's primary owner. The owner must be a user instead of a security group or an email-enabled security group. + var owner = ""; + // From Cmdlet Help: Specifies the language of this site collection. For more information, see Locale IDs supported by SharePoint at https://github.com/pnp/PnP-PowerShell/wiki/Supported-LCIDs-by-SharePoint. To get the list of supported languages on a SharePoint environment use: Get-PnPAvailableLanguage. + var lcid = ""; + // From Cmdlet Help: Specifies the site collection template type. Use the Get-PnPWebTemplates cmdlet to get the list of valid templates. If no template is specified, one can be added later. The Template and LocaleId parameters must be a valid combination as returned from the Get-PnPWebTemplates cmdlet. + var template = ""; + // This is a mandatory parameter + // From Cmdlet Help: Use Get-PnPTimeZoneId to retrieve possible timezone values + var timeZone = ""; + // From Cmdlet Help: Specifies the quota for this site collection in Sandboxed Solutions units. This value must not exceed the company's aggregate available Sandboxed Solutions quota. The default value is 0. For more information, see Resource Usage Limits on Sandboxed Solutions in SharePoint 2010 : http://msdn.microsoft.com/en-us/library/gg615462.aspx. + var resourceQuota = ""; + // From Cmdlet Help: Specifies the warning level for the resource quota. This value must not exceed the value set for the ResourceQuota parameter + var resourceQuotaWarningLevel = ""; + // From Cmdlet Help: Specifies the storage quota for this site collection in megabytes. This value must not exceed the company's available quota. + var storageQuota = ""; + // From Cmdlet Help: Specifies the warning level for the storage quota in megabytes. This value must not exceed the values set for the StorageQuota parameter + var storageQuotaWarningLevel = ""; + // From Cmdlet Help: Specifies if any existing site with the same URL should be removed from the recycle bin + var removeDeletedSite = ""; + var wait = ""; + // From Cmdlet Help: Do not ask for confirmation. + var force = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSite", + new CommandParameter("Title", title), + new CommandParameter("Url", url), + new CommandParameter("Description", description), + new CommandParameter("Owner", owner), + new CommandParameter("Lcid", lcid), + new CommandParameter("Template", template), + new CommandParameter("TimeZone", timeZone), + new CommandParameter("ResourceQuota", resourceQuota), + new CommandParameter("ResourceQuotaWarningLevel", resourceQuotaWarningLevel), + new CommandParameter("StorageQuota", storageQuota), + new CommandParameter("StorageQuotaWarningLevel", storageQuotaWarningLevel), + new CommandParameter("RemoveDeletedSite", removeDeletedSite), + new CommandParameter("Wait", wait), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RegisterPnPHubSiteTests.cs b/Tests/Admin/RegisterPnPHubSiteTests.cs new file mode 100644 index 000000000..cfc40ad45 --- /dev/null +++ b/Tests/Admin/RegisterPnPHubSiteTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RegisterHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RegisterPnPHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site to register as a hubsite + var site = ""; + + var results = scope.ExecuteCommand("Register-PnPHubSite", + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPHomeSiteTests.cs b/Tests/Admin/RemovePnPHomeSiteTests.cs new file mode 100644 index 000000000..dc7a3720a --- /dev/null +++ b/Tests/Admin/RemovePnPHomeSiteTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveHomeSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPHomeSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPHomeSite", + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPHubSiteAssociationTests.cs b/Tests/Admin/RemovePnPHubSiteAssociationTests.cs new file mode 100644 index 000000000..259e236f7 --- /dev/null +++ b/Tests/Admin/RemovePnPHubSiteAssociationTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveHubSiteAssociationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPHubSiteAssociationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site to disconnect from its hubsite + var site = ""; + + var results = scope.ExecuteCommand("Remove-PnPHubSiteAssociation", + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPKnowledgeHubSiteTests.cs b/Tests/Admin/RemovePnPKnowledgeHubSiteTests.cs new file mode 100644 index 000000000..b0b9c0325 --- /dev/null +++ b/Tests/Admin/RemovePnPKnowledgeHubSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveKnowledgeHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPKnowledgeHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Remove-PnPKnowledgeHubSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPOrgAssetsLibraryTests.cs b/Tests/Admin/RemovePnPOrgAssetsLibraryTests.cs new file mode 100644 index 000000000..aee0b3589 --- /dev/null +++ b/Tests/Admin/RemovePnPOrgAssetsLibraryTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveOrgAssetsLibraryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPOrgAssetsLibraryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative url of the document library flagged as organizational asset which you want to remove, i.e. "sites/branding/logos" + var libraryUrl = ""; + // From Cmdlet Help: Boolean indicating if the document library that will no longer be flagged as an organizational asset also needs to be removed as an Office 365 CDN source + var shouldRemoveFromCdn = ""; + // From Cmdlet Help: Indicates what type of Office 365 CDN source the document library that will no longer be flagged as an organizational asset was of + var cdnType = ""; + + var results = scope.ExecuteCommand("Remove-PnPOrgAssetsLibrary", + new CommandParameter("LibraryUrl", libraryUrl), + new CommandParameter("ShouldRemoveFromCdn", shouldRemoveFromCdn), + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPOrgNewsSiteTests.cs b/Tests/Admin/RemovePnPOrgNewsSiteTests.cs new file mode 100644 index 000000000..cb949ae67 --- /dev/null +++ b/Tests/Admin/RemovePnPOrgNewsSiteTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveOrgNewsSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPOrgNewsSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site to be removed from list of organization's news sites + var orgNewsSiteUrl = ""; + + var results = scope.ExecuteCommand("Remove-PnPOrgNewsSite", + new CommandParameter("OrgNewsSiteUrl", orgNewsSiteUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPSiteCollectionAppCatalogTests.cs b/Tests/Admin/RemovePnPSiteCollectionAppCatalogTests.cs new file mode 100644 index 000000000..cf7f06dda --- /dev/null +++ b/Tests/Admin/RemovePnPSiteCollectionAppCatalogTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveSiteCollectionAppCatalogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteCollectionAppCatalogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Url of the site to remove the app catalog from. + var site = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteCollectionAppCatalog", + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPStorageEntityTests.cs b/Tests/Admin/RemovePnPStorageEntityTests.cs new file mode 100644 index 000000000..d036188a2 --- /dev/null +++ b/Tests/Admin/RemovePnPStorageEntityTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemovePnPStorageEntityTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPStorageEntityTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The key of the value to remove. + var key = ""; + // From Cmdlet Help: Defines the scope of the storage entity. Defaults to Tenant. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Remove-PnPStorageEntity", + new CommandParameter("Key", key), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPTenantCdnOriginTests.cs b/Tests/Admin/RemovePnPTenantCdnOriginTests.cs new file mode 100644 index 000000000..be66409d5 --- /dev/null +++ b/Tests/Admin/RemovePnPTenantCdnOriginTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveTenantCdnOriginTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPTenantCdnOriginTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The origin to remove. + var originUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: The cdn type to remove the origin from. + var cdnType = ""; + + var results = scope.ExecuteCommand("Remove-PnPTenantCdnOrigin", + new CommandParameter("OriginUrl", originUrl), + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPTenantSiteTests.cs b/Tests/Admin/RemovePnPTenantSiteTests.cs new file mode 100644 index 000000000..aadb5b695 --- /dev/null +++ b/Tests/Admin/RemovePnPTenantSiteTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPTenantSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the full URL of the site collection that needs to be deleted + var url = ""; + // From Cmdlet Help: Do not add to the tenant scoped recycle bin when selected. + var skipRecycleBin = ""; + // From Cmdlet Help: OBSOLETE: If true, will wait for the site to be deleted before processing continues + var wait = ""; + // From Cmdlet Help: If specified, will search for the site in the Recycle Bin and remove it from there. + var fromRecycleBin = ""; + // From Cmdlet Help: Do not ask for confirmation. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPTenantSite", + new CommandParameter("Url", url), + new CommandParameter("SkipRecycleBin", skipRecycleBin), + new CommandParameter("Wait", wait), + new CommandParameter("FromRecycleBin", fromRecycleBin), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RemovePnPTenantThemeTests.cs b/Tests/Admin/RemovePnPTenantThemeTests.cs new file mode 100644 index 000000000..d507e5da9 --- /dev/null +++ b/Tests/Admin/RemovePnPTenantThemeTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RemoveTenantThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPTenantThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the theme to retrieve + var identity = ""; + + var results = scope.ExecuteCommand("Remove-PnPTenantTheme", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/RevokePnPHubSiteRightsTests.cs b/Tests/Admin/RevokePnPHubSiteRightsTests.cs new file mode 100644 index 000000000..aa7814c81 --- /dev/null +++ b/Tests/Admin/RevokePnPHubSiteRightsTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class RevokeHubSiteRightsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RevokePnPHubSiteRightsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Hub Site to revoke the permissions on to associate another site with this Hub Site + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: One or more usernames that will be revoked the permission to associate a site with this Hub Site. + var principals = ""; + + var results = scope.ExecuteCommand("Revoke-PnPHubSiteRights", + new CommandParameter("Identity", identity), + new CommandParameter("Principals", principals)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPHideDefaultThemesTests.cs b/Tests/Admin/SetPnPHideDefaultThemesTests.cs new file mode 100644 index 000000000..9e9083fda --- /dev/null +++ b/Tests/Admin/SetPnPHideDefaultThemesTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetHideDefaultThemesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPHideDefaultThemesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Defines if the default themes should be visible or hidden + var hideDefaultThemes = ""; + + var results = scope.ExecuteCommand("Set-PnPHideDefaultThemes", + new CommandParameter("HideDefaultThemes", hideDefaultThemes)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPHomeSiteTests.cs b/Tests/Admin/SetPnPHomeSiteTests.cs new file mode 100644 index 000000000..0d4f9d7d0 --- /dev/null +++ b/Tests/Admin/SetPnPHomeSiteTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetHomeSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPHomeSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The url of the site to set as the home site + var url = ""; + + var results = scope.ExecuteCommand("Set-PnPHomeSite", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPHubSiteTests.cs b/Tests/Admin/SetPnPHubSiteTests.cs new file mode 100644 index 000000000..ca1015d72 --- /dev/null +++ b/Tests/Admin/SetPnPHubSiteTests.cs @@ -0,0 +1,94 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Id or Url of a hub site to configure + var identity = ""; + // From Cmdlet Help: The title to set on the hub which will be shown in the hub navigation bar + var title = ""; + // From Cmdlet Help: Full url to the image to use for the hub site logo. Can either be a logo hosted on SharePoint or outside of SharePoint and must be an absolute URL to the image. + var logoUrl = ""; + // From Cmdlet Help: The description of the hub site + var description = ""; + // From Cmdlet Help: GUID of the SharePoint Site Design which should be applied when a site joins the hub site + var siteDesignId = ""; + var hideNameInNavigation = ""; + var requiresJoinApproval = ""; + + var results = scope.ExecuteCommand("Set-PnPHubSite", + new CommandParameter("Identity", identity), + new CommandParameter("Title", title), + new CommandParameter("LogoUrl", logoUrl), + new CommandParameter("Description", description), + new CommandParameter("SiteDesignId", siteDesignId), + new CommandParameter("HideNameInNavigation", hideNameInNavigation), + new CommandParameter("RequiresJoinApproval", requiresJoinApproval)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPKnowledgeHubSiteTests.cs b/Tests/Admin/SetPnPKnowledgeHubSiteTests.cs new file mode 100644 index 000000000..36ed5ecf3 --- /dev/null +++ b/Tests/Admin/SetPnPKnowledgeHubSiteTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetKnowledgeHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPKnowledgeHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var knowledgeHubSiteUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPKnowledgeHubSite", + new CommandParameter("KnowledgeHubSiteUrl", knowledgeHubSiteUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPStorageEntityTests.cs b/Tests/Admin/SetPnPStorageEntityTests.cs new file mode 100644 index 000000000..fcc7513f0 --- /dev/null +++ b/Tests/Admin/SetPnPStorageEntityTests.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetPnPStorageEntityTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPStorageEntityTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The key of the value to set. + var key = ""; + // This is a mandatory parameter + // From Cmdlet Help: The value to set. + var value = ""; + // From Cmdlet Help: The comment to set. + var comment = ""; + // From Cmdlet Help: The description to set. + var description = ""; + // From Cmdlet Help: Defines the scope of the storage entity. Defaults to Tenant. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Set-PnPStorageEntity", + new CommandParameter("Key", key), + new CommandParameter("Value", value), + new CommandParameter("Comment", comment), + new CommandParameter("Description", description), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantAppCatalogUrlTests.cs b/Tests/Admin/SetPnPTenantAppCatalogUrlTests.cs new file mode 100644 index 000000000..3744280ab --- /dev/null +++ b/Tests/Admin/SetPnPTenantAppCatalogUrlTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantAppCatalogUrlTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantAppCatalogUrlTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The url of the site to set as the tenant scoped app catalog + var url = ""; + + var results = scope.ExecuteCommand("Set-PnPTenantAppCatalogUrl", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantCdnEnabledTests.cs b/Tests/Admin/SetPnPTenantCdnEnabledTests.cs new file mode 100644 index 000000000..a94a523df --- /dev/null +++ b/Tests/Admin/SetPnPTenantCdnEnabledTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantCdnEnabledTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantCdnEnabledTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var noDefaultOrigins = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specify to enable or disable + var enable = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of cdn to enable or disable + var cdnType = ""; + + var results = scope.ExecuteCommand("Set-PnPTenantCdnEnabled", + new CommandParameter("NoDefaultOrigins", noDefaultOrigins), + new CommandParameter("Enable", enable), + new CommandParameter("CdnType", cdnType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantCdnPolicyTests.cs b/Tests/Admin/SetPnPTenantCdnPolicyTests.cs new file mode 100644 index 000000000..2dd9349e1 --- /dev/null +++ b/Tests/Admin/SetPnPTenantCdnPolicyTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantCdnPolicyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantCdnPolicyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The type of cdn to retrieve the policies from + var cdnType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of the policy to set + var policyType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The value of the policy to set + var policyValue = ""; + + var results = scope.ExecuteCommand("Set-PnPTenantCdnPolicy", + new CommandParameter("CdnType", cdnType), + new CommandParameter("PolicyType", policyType), + new CommandParameter("PolicyValue", policyValue)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantSiteTests.cs b/Tests/Admin/SetPnPTenantSiteTests.cs new file mode 100644 index 000000000..f6fc35c80 --- /dev/null +++ b/Tests/Admin/SetPnPTenantSiteTests.cs @@ -0,0 +1,144 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the URL of the site + var url = ""; + // From Cmdlet Help: Specifies the title of the site + var title = ""; + // From Cmdlet Help: Specifies the language of this site collection. For more information, see Locale IDs supported by SharePoint at https://github.com/pnp/PnP-PowerShell/wiki/Supported-LCIDs-by-SharePoint. To get the list of supported languages on a SharePoint environment use: (Get-PnPWeb -Includes RegionalSettings.InstalledLanguages).RegionalSettings.InstalledLanguages. + var localeId = ""; + // From Cmdlet Help: Specifies if the site administrator can upgrade the site collection + var allowSelfServiceUpgrade = ""; + // From Cmdlet Help: Specifies owner(s) to add as site collection administrators. They will be added as additional site collection administrators. Existing administrators will stay. Can be both users and groups. + var owners = ""; + // From Cmdlet Help: Determines whether the Add And Customize Pages right is denied on the site collection. For more information about permission levels, see User permissions and permission levels in SharePoint. + var denyAddAndCustomizePages = ""; + // From Cmdlet Help: Specifies what the sharing capabilities are for the site. Possible values: Disabled, ExternalUserSharingOnly, ExternalUserAndGuestSharing, ExistingExternalUserSharingOnly + var sharingCapability = ""; + // From Cmdlet Help: Specifies the storage quota for this site collection in megabytes. This value must not exceed the company's available quota. + var storageMaximumLevel = ""; + // From Cmdlet Help: Specifies the warning level for the storage quota in megabytes. This value must not exceed the values set for the StorageMaximumLevel parameter + var storageWarningLevel = ""; + // From Cmdlet Help: Specifies the quota for this site collection in Sandboxed Solutions units. This value must not exceed the company's aggregate available Sandboxed Solutions quota. The default value is 0. For more information, see Resource Usage Limits on Sandboxed Solutions in SharePoint 2010 : http://msdn.microsoft.com/en-us/library/gg615462.aspx. + var userCodeMaximumLevel = ""; + // From Cmdlet Help: Specifies the warning level for the resource quota. This value must not exceed the value set for the UserCodeMaximumLevel parameter + var userCodeWarningLevel = ""; + // From Cmdlet Help: Sets the lockstate of a site + var lockState = ""; + // From Cmdlet Help: Specifies the default link permission for the site collection. None - Respect the organization default link permission. View - Sets the default link permission for the site to "view" permissions. Edit - Sets the default link permission for the site to "edit" permissions + var defaultLinkPermission = ""; + // From Cmdlet Help: Specifies the default link type for the site collection. None - Respect the organization default sharing link type. AnonymousAccess - Sets the default sharing link for this site to an Anonymous Access or Anyone link. Internal - Sets the default sharing link for this site to the "organization" link or company shareable link. Direct - Sets the default sharing link for this site to the "Specific people" link + var defaultSharingLinkType = ""; + // From Cmdlet Help: Specifies a list of email domains that is allowed for sharing with the external collaborators. Use the space character as the delimiter for entering multiple values. For example, "contoso.com fabrikam.com". + var sharingAllowedDomainList = ""; + // From Cmdlet Help: Specifies a list of email domains that is blocked for sharing with the external collaborators. Use the space character as the delimiter for entering multiple values. For example, "contoso.com fabrikam.com". + var sharingBlockedDomainList = ""; + // From Cmdlet Help: Specifies if non web viewable files can be downloaded. + var blockDownloadOfNonViewableFiles = ""; + // From Cmdlet Help: Specifies the external sharing mode for domains. + var sharingDomainRestrictionMode = ""; + // From Cmdlet Help: Specifies if comments on site pages are enabled + var commentsOnSitePagesDisabled = ""; + // From Cmdlet Help: - + var disableAppViews = ""; + // From Cmdlet Help: - + var disableCompanyWideSharingLinks = ""; + // From Cmdlet Help: - + var disableFlows = ""; + // From Cmdlet Help: Wait for the operation to complete + var wait = ""; + + var results = scope.ExecuteCommand("Set-PnPTenantSite", + new CommandParameter("Url", url), + new CommandParameter("Title", title), + new CommandParameter("LocaleId", localeId), + new CommandParameter("AllowSelfServiceUpgrade", allowSelfServiceUpgrade), + new CommandParameter("Owners", owners), + new CommandParameter("DenyAddAndCustomizePages", denyAddAndCustomizePages), + new CommandParameter("SharingCapability", sharingCapability), + new CommandParameter("StorageMaximumLevel", storageMaximumLevel), + new CommandParameter("StorageWarningLevel", storageWarningLevel), + new CommandParameter("UserCodeMaximumLevel", userCodeMaximumLevel), + new CommandParameter("UserCodeWarningLevel", userCodeWarningLevel), + new CommandParameter("LockState", lockState), + new CommandParameter("DefaultLinkPermission", defaultLinkPermission), + new CommandParameter("DefaultSharingLinkType", defaultSharingLinkType), + new CommandParameter("SharingAllowedDomainList", sharingAllowedDomainList), + new CommandParameter("SharingBlockedDomainList", sharingBlockedDomainList), + new CommandParameter("BlockDownloadOfNonViewableFiles", blockDownloadOfNonViewableFiles), + new CommandParameter("SharingDomainRestrictionMode", sharingDomainRestrictionMode), + new CommandParameter("CommentsOnSitePagesDisabled", commentsOnSitePagesDisabled), + new CommandParameter("DisableAppViews", disableAppViews), + new CommandParameter("DisableCompanyWideSharingLinks", disableCompanyWideSharingLinks), + new CommandParameter("DisableFlows", disableFlows), + new CommandParameter("Wait", wait)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantSyncClientRestrictionTests.cs b/Tests/Admin/SetPnPTenantSyncClientRestrictionTests.cs new file mode 100644 index 000000000..7a67ede2f --- /dev/null +++ b/Tests/Admin/SetPnPTenantSyncClientRestrictionTests.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantSyncClientRestrictionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantSyncClientRestrictionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Block Mac sync clients-- the Beta version and the new sync client (OneDrive.exe). The values for this parameter are $true and $false. The default value is $false. + var blockMacSync = ""; + // From Cmdlet Help: Specifies if the Report Problem Dialog is disabled or not. + var disableReportProblemDialog = ""; + // From Cmdlet Help: Sets the domain GUID to add to the safe recipient list. Requires a minimum of 1 domain GUID. The maximum number of domain GUIDs allowed are 125. I.e. 634c71f6-fa83-429c-b77b-0dba3cb70b93,4fbc735f-0ac2-48ba-b035-b1ae3a480887. + var domainGuids = ""; + // From Cmdlet Help: Enables the feature to block sync originating from domains that are not present in the safe recipients list. + var enable = ""; + // From Cmdlet Help: Blocks certain file types from syncing with the new sync client (OneDrive.exe). Provide as one string separating the extensions using a semicolon (;). I.e. "docx;pptx" + var excludedFileExtensions = ""; + // From Cmdlet Help: Controls whether or not a tenant's users can sync OneDrive for Business libraries with the old OneDrive for Business sync client. The valid values are OptOut, HardOptin, and SoftOptin. + var grooveBlockOption = ""; + + var results = scope.ExecuteCommand("Set-PnPTenantSyncClientRestriction", + new CommandParameter("BlockMacSync", blockMacSync), + new CommandParameter("DisableReportProblemDialog", disableReportProblemDialog), + new CommandParameter("DomainGuids", domainGuids), + new CommandParameter("Enable", enable), + new CommandParameter("ExcludedFileExtensions", excludedFileExtensions), + new CommandParameter("GrooveBlockOption", grooveBlockOption)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/SetPnPTenantTests.cs b/Tests/Admin/SetPnPTenantTests.cs new file mode 100644 index 000000000..8ad3dcaa1 --- /dev/null +++ b/Tests/Admin/SetPnPTenantTests.cs @@ -0,0 +1,281 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class SetTenantTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTenantTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Permits the use of special characters in file and folder names in SharePoint Online and OneDrive for Business document libraries.Note: + // The only two characters that can be managed at this time are the # and % characters.The following are the valid values:NoPreference- Support for feature will be enabled by Microsoft on your Office 365 tenant.Allowed- Lets the # and % characters in file and folder names in SharePoint Online and OneDrive for Business document libraries.Disallowed- Disallows the # and % characters in file and folder names in SharePoint Online and OneDrive for Business document libraries. + var specialCharactersStateInFileFolderNames = ""; + // From Cmdlet Help: Specifies the lower bound on the compatibility level for new sites. + var minCompatibilityLevel = ""; + // From Cmdlet Help: Specifies the upper bound on the compatibility level for new sites. + var maxCompatibilityLevel = ""; + // From Cmdlet Help: Enables external services for a tenant. + // External services are defined as services that are not in the Office 365 datacenters.The valid values are: + // True (default) - External services are enabled for the tenant. + // False - External services that are outside of the Office 365 datacenters cannot interact with SharePoint. + var externalServicesEnabled = ""; + // From Cmdlet Help: Specifies the URL of the redirected site for those site collections which have the locked state "NoAccess"The valid values are: + // ""(default) - Blank by default, this will also remove or clear any value that has been set. + // Full URL - Example: https://contoso.sharepoint.com/Pages/Locked.aspx + var noAccessRedirectUrl = ""; + // From Cmdlet Help: Determines what level of sharing is available for the site.The valid values are: + // ExternalUserAndGuestSharing (default) - External user sharing (share by email) and guest link sharing are both enabled. Disabled - External user sharing (share by email) and guest link sharing are both disabled. + // ExternalUserSharingOnly - External user sharing (share by email) is enabled, but guest link sharing is disabled.For more information about sharing, see Manage external sharing for your SharePoint online environment (http://office.microsoft.com/en-us/office365-sharepoint-online-enterprise-help/manage-external-sharing-for-your-sharepoint-online-environment-HA102849864.aspx). + var sharingCapability = ""; + // From Cmdlet Help: Determines whether tenant users see the Start a Site menu option.The valid values are: + // True (default) - Tenant users will see the Start a Site menu option. + // False - Start a Site is hidden from the menu. + var displayStartASiteOption = ""; + // From Cmdlet Help: Specifies URL of the form to load in the Start a Site dialog.The valid values are: + // "" (default) - Blank by default, this will also remove or clear any value that has been set. + // Full URL - Example: "https://contoso.sharepoint.com/path/to/form" + var startASiteFormUrl = ""; + // From Cmdlet Help: Enables the administrator to hide the Everyone claim in the People Picker. + // When users share an item with Everyone, it is accessible to all authenticated users in the tenant's Azure Active Directory, including any active external users who have previously accepted invitations.Note, that some SharePoint system resources such as templates and pages are required to be shared to Everyone and this type of sharing does not expose any user data or metadata.The valid values are: + // True (default) - The Everyone claim group is displayed in People Picker. + // False - The Everyone claim group is hidden from the People Picker. + var showEveryoneClaim = ""; + // From Cmdlet Help: Enables the administrator to hide the All Users claim groups in People Picker.When users share an item with "All Users (x)", it is accessible to all organization members in the tenant's Azure Active Directory who have authenticated with via this method. When users share an item with "All Users (x)" it is accessible to all organization members in the tenant that used NTLM to authentication with SharePoint.Note, the All Users(authenticated) group is equivalent to the Everyone claim, and shows as Everyone.To change this, see - ShowEveryoneClaim.The valid values are: + // True(default) - The All Users claim groups are displayed in People Picker. + // False - The All Users claim groups are hidden in People Picker. + var showAllUsersClaim = ""; + // From Cmdlet Help: Enables the administrator to hide the "Everyone except external users" claim in the People Picker. + // When users share an item with "Everyone except external users", it is accessible to all organization members in the tenant's Azure Active Directory, but not to any users who have previously accepted invitations.The valid values are: + // True(default) - The Everyone except external users is displayed in People Picker. + // False - The Everyone except external users claim is not visible in People Picker. + var showEveryoneExceptExternalUsersClaim = ""; + // From Cmdlet Help: Removes the search capability from People Picker. Note, recently resolved names will still appear in the list until browser cache is cleared or expired.SharePoint Administrators will still be able to use starts with or partial name matching when enabled.The valid values are: + // False (default) - Starts with / partial name search functionality is available. + // True - Disables starts with / partial name search functionality for all SharePoint users, except SharePoint Admins. + var searchResolveExactEmailOrUPN = ""; + // From Cmdlet Help: When set to true this will disable the ability to use Modern Authentication that leverages ADAL across the tenant.The valid values are: + // False (default) - Modern Authentication is enabled/allowed. + // True - Modern Authentication via ADAL is disabled. + var officeClientADALDisabled = ""; + // From Cmdlet Help: By default this value is set to $true.Setting this parameter prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources.A value of $true - Enables Office clients using non-modern authentication protocols(such as, Forms-Based Authentication (FBA) or Identity Client Runtime Library (IDCRL)) to access SharePoint resources.A value of $false - Prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources.Note: + // This may also prevent third-party apps from accessing SharePoint Online resources.Also, this will also block apps using the SharePointOnlineCredentials class to access SharePoint Online resources.For additional information about SharePointOnlineCredentials, see SharePointOnlineCredentials class. + var legacyAuthProtocolsEnabled = ""; + // From Cmdlet Help: Ensures that an external user can only accept an external sharing invitation with an account matching the invited email address.Administrators who desire increased control over external collaborators should consider enabling this feature.Note, this only applies to new external users accepting new sharing invitations. Also, the resource owner must share with an organizational or Microsoft account or the external user will be unable to access the resource.The valid values are: + // False (default) - When a document is shared with an external user, bob@contoso.com, it can be accepted by any user with access to the invitation link in the original e-mail. + // True - User must accept this invitation with bob@contoso.com. + var requireAcceptingAccountMatchInvitedAccount = ""; + // From Cmdlet Help: Creates a Shared with Everyone folder in every user's new OneDrive for Business document library.The valid values are: + // True (default) - The Shared with Everyone folder is created. + // False - No folder is created when the site and OneDrive for Business document library is created.The default behavior of the Shared with Everyone folder changed in August 2015. + // For additional information about the change, see Provision the Shared with Everyone folder in OneDrive for Business (https://support.office.com/en-us/article/Provision-the-Shared-with-Everyone-folder-in-OneDrive-for-Business-6bb02c91-fd0b-42ba-9457-3921cb6dc5b2?ui=en-US&rs=en-US&ad=US) + var provisionSharedWithEveryoneFolder = ""; + // From Cmdlet Help: Specifies the home realm discovery value to be sent to Azure Active Directory (AAD) during the user sign-in process.When the organization uses a third-party identity provider, this prevents the user from seeing the Azure Active Directory Home Realm Discovery web page and ensures the user only sees their company's Identity Provider's portal. + // This value can also be used with Azure Active Directory Premium to customize the Azure Active Directory login page.Acceleration will not occur on site collections that are shared externally.This value should be configured with the login domain that is used by your company (that is, example@contoso.com).If your company has multiple third-party identity providers, configuring the sign-in acceleration value will break sign-in for your organization.The valid values are: + // "" (default) - Blank by default, this will also remove or clear any value that has been set. + // Login Domain - For example: "contoso.com" + var signInAccelerationDomain = ""; + // From Cmdlet Help: Accelerates guest-enabled site collections as well as member-only site collections when the SignInAccelerationDomain parameter is set.Note: + // If enabled, your identity provider must be capable of authenticating guest users. If it is not, guest users will be unable to log in and access content that was shared with them. + var enableGuestSignInAcceleration = ""; + // From Cmdlet Help: Lets SharePoint issue a special cookie that will allow this feature to work even when "Keep Me Signed In" is not selected."Open with Explorer" requires persisted cookies to operate correctly. + // When the user does not select "Keep Me Signed in" at the time of sign -in, "Open with Explorer" will fail.This special cookie expires after 30 minutes and cannot be cleared by closing the browser or signing out of SharePoint Online.To clear this cookie, the user must log out of their Windows session.The valid values are: + // False(default) - No special cookie is generated and the normal Office 365 sign -in length / timing applies. + // True - Generates a special cookie that will allow "Open with Explorer" to function if the "Keep Me Signed In" box is not checked at sign -in. + var usePersistentCookiesForExplorerView = ""; + // From Cmdlet Help: When the feature is enabled, all external sharing invitations that are sent will blind copy the e-mail messages listed in the BccExternalSharingInvitationsList.The valid values are: + // False (default) - BCC for external sharing is disabled. + // True - All external sharing invitations that are sent will blind copy the e-mail messages listed in the BccExternalSharingInvitationsList. + var bccExternalSharingInvitations = ""; + // From Cmdlet Help: Specifies a list of e-mail addresses to be BCC'd when the BCC for External Sharing feature is enabled. + // Multiple addresses can be specified by creating a comma separated list with no spaces.The valid values are: + // "" (default) - Blank by default, this will also clear any value that has been set. + // Single or Multiple e-mail addresses - joe@contoso.com or joe@contoso.com,bob@contoso.com + var bccExternalSharingInvitationsList = ""; + var userVoiceForFeedbackEnabled = ""; + var publicVarCdnEnabled = ""; + var publicVarCdnAllowedFileTypes = ""; + // From Cmdlet Help: Specifies all anonymous links that have been created (or will be created) will expire after the set number of days .To remove the expiration requirement, set the value to zero (0). + var requireAnonymousLinksExpireInDays = ""; + // From Cmdlet Help: Specifies a list of email domains that is allowed for sharing with the external collaborators. Use the space character as the delimiter for entering multiple values. For example, "contoso.com fabrikam.com".For additional information about how to restrict a domain sharing, see Restricted Domains Sharing in Office 365 SharePoint Online and OneDrive for Business + var sharingAllowedDomainList = ""; + // From Cmdlet Help: Specifies a list of email domains that is blocked or prohibited for sharing with the external collaborators. Use space character as the delimiter for entering multiple values. For example, "contoso.com fabrikam.com".For additional information about how to restrict a domain sharing, see Restricted Domains Sharing in Office 365 SharePoint Online and OneDrive for Business + var sharingBlockedDomainList = ""; + // From Cmdlet Help: Specifies the external sharing mode for domains.The following values are: None AllowList BlockListFor additional information about how to restrict a domain sharing, see Restricted Domains Sharing in Office 365 SharePoint Online and OneDrive for Business. + var sharingDomainRestrictionMode = ""; + // From Cmdlet Help: Sets a default OneDrive for Business storage quota for the tenant. It will be used for new OneDrive for Business sites created.A typical use will be to reduce the amount of storage associated with OneDrive for Business to a level below what the License entitles the users. For example, it could be used to set the quota to 10 gigabytes (GB) by default.If value is set to 0, the parameter will have no effect.If the value is set larger than the Maximum allowed OneDrive for Business quota, it will have no effect. + var oneDriveStorageQuota = ""; + // From Cmdlet Help: Lets OneDrive for Business creation for administrator managed guest users. Administrator managed Guest users use credentials in the resource tenant to access the resources.The valid values are the following:$true-Administrator managed Guest users can be given OneDrives, provided needed licenses are assigned.$false- Administrator managed Guest users can't be given OneDrives as functionality is turned off. + var oneDriveForGuestsEnabled = ""; + // From Cmdlet Help: Allows access from network locations that are defined by an administrator.The values are $true and $false. The default value is $false which means the setting is disabled.Before the IPAddressEnforcement parameter is set, make sure you add a valid IPv4 or IPv6 address to the IPAddressAllowList parameter. + var iPAddressEnforcement = ""; + // From Cmdlet Help: Configures multiple IP addresses or IP address ranges (IPv4 or IPv6).Use commas to separate multiple IP addresses or IP address ranges. Verify there are no overlapping IP addresses and ensure IP ranges use Classless Inter-Domain Routing (CIDR) notation. For example, 172.16.0.0, 192.168.1.0/27.Note: + // The IPAddressAllowList parameter only lets administrators set IP addresses or ranges that are recognized as trusted. To only grant access from these IP addresses or ranges, set the IPAddressEnforcement parameter to $true. + var iPAddressAllowList = ""; + var iPAddressWACTokenLifetime = ""; + // From Cmdlet Help: Note: + // When set to $true, users aren't able to share with security groups or SharePoint groups. + var useFindPeopleInPeoplePicker = ""; + // From Cmdlet Help: Lets administrators choose what type of link appears is selected in the “Get a link” sharing dialog box in OneDrive for Business and SharePoint Online.For additional information about how to change the default link type, see Change the default link type when users get links for sharing.Note: + // Setting this value to “none” will default “get a link” to the most permissive link available (that is, if anonymous links are enabled, the default link will be anonymous access; if they are disabled then the default link will be internal.The values are: None Direct Internal AnonymousAccess + var defaultSharingLinkType = ""; + // From Cmdlet Help: Lets administrators set policy on re-sharing behavior in OneDrive for Business.Values:On- Users with edit permissions can re-share.Off- Only OneDrive for Business owner can share. The value of ODBAccessRequests defines whether a request to share gets sent to the owner.Unspecified- Let each OneDrive for Business owner enable or disable re-sharing behavior on their OneDrive. + var oDBMembersCanShare = ""; + // From Cmdlet Help: Lets administrators set policy on access requests and requests to share in OneDrive for Business.Values:On- Users without permission to share can trigger sharing requests to the OneDrive for Business owner when they attempt to share. Also, users without permission to a file or folder can trigger access requests to the OneDrive for Business owner when they attempt to access an item they do not have permissions to.Off- Prevent access requests and requests to share on OneDrive for Business.Unspecified- Let each OneDrive for Business owner enable or disable access requests and requests to share on their OneDrive. + var oDBAccessRequests = ""; + var preventExternalUsersFromResharing = ""; + var showPeoplePickerSuggestionsForGuestUsers = ""; + var fileAnonymousLinkType = ""; + var folderAnonymousLinkType = ""; + // From Cmdlet Help: When this parameter is set to $true and another user re-shares a document from a user’s OneDrive for Business, the OneDrive for Business owner is notified by e-mail.For additional information about how to configure notifications for external sharing, see Configure notifications for external sharing for OneDrive for Business.The values are $true and $false. + var notifyOwnersWhenItemsReshared = ""; + // From Cmdlet Help: When this parameter is set to $true and when an external user accepts an invitation to a resource in a user’s OneDrive for Business, the OneDrive for Business owner is notified by e-mail.For additional information about how to configure notifications for external sharing, see Configure notifications for external sharing for OneDrive for Business.The values are $true and $false. + var notifyOwnersWhenInvitationsAccepted = ""; + var notificationsInOneDriveForBusinessEnabled = ""; + var notificationsInSharePointEnabled = ""; + var ownerAnonymousNotification = ""; + var commentsOnSitePagesDisabled = ""; + var socialBarOnSitePagesDisabled = ""; + // From Cmdlet Help: Specifies the number of days after a user's Active Directory account is deleted that their OneDrive for Business content will be deleted.The value range is in days, between 30 and 3650. The default value is 30. + var orphanedPersonalSitesRetentionPeriod = ""; + // From Cmdlet Help: Prevents the Download button from being displayed on the Virus Found warning page.Accepts a value of true (enabled) to hide the Download button or false (disabled) to display the Download button. By default this feature is set to false. + var disallowInfectedFileDownload = ""; + var defaultLinkPermission = ""; + var conditionalAccessPolicy = ""; + var allowDownloadingNonWebViewableFiles = ""; + var allowEditing = ""; + var applyAppEnforcedRestrictionsToAdHocRecipients = ""; + var filePickerExternalImageSearchEnabled = ""; + var emailAttestationRequired = ""; + var emailAttestationReAuthDays = ""; + // From Cmdlet Help: Defines if the default themes are visible or hidden + var hideDefaultThemes = ""; + // From Cmdlet Help: Guids of out of the box modern web part id's to hide + var disabledWebPartIds = ""; + // From Cmdlet Help: Boolean indicating if Azure Information Protection (AIP) should be enabled on the tenant. For more information, see https://docs.microsoft.com/microsoft-365/compliance/sensitivity-labels-sharepoint-onedrive-files#use-powershell-to-enable-support-for-sensitivity-labels + var enableAIPIntegration = ""; + + var results = scope.ExecuteCommand("Set-PnPTenant", + new CommandParameter("SpecialCharactersStateInFileFolderNames", specialCharactersStateInFileFolderNames), + new CommandParameter("MinCompatibilityLevel", minCompatibilityLevel), + new CommandParameter("MaxCompatibilityLevel", maxCompatibilityLevel), + new CommandParameter("ExternalServicesEnabled", externalServicesEnabled), + new CommandParameter("NoAccessRedirectUrl", noAccessRedirectUrl), + new CommandParameter("SharingCapability", sharingCapability), + new CommandParameter("DisplayStartASiteOption", displayStartASiteOption), + new CommandParameter("StartASiteFormUrl", startASiteFormUrl), + new CommandParameter("ShowEveryoneClaim", showEveryoneClaim), + new CommandParameter("ShowAllUsersClaim", showAllUsersClaim), + new CommandParameter("ShowEveryoneExceptExternalUsersClaim", showEveryoneExceptExternalUsersClaim), + new CommandParameter("SearchResolveExactEmailOrUPN", searchResolveExactEmailOrUPN), + new CommandParameter("OfficeClientADALDisabled", officeClientADALDisabled), + new CommandParameter("LegacyAuthProtocolsEnabled", legacyAuthProtocolsEnabled), + new CommandParameter("RequireAcceptingAccountMatchInvitedAccount", requireAcceptingAccountMatchInvitedAccount), + new CommandParameter("ProvisionSharedWithEveryoneFolder", provisionSharedWithEveryoneFolder), + new CommandParameter("SignInAccelerationDomain", signInAccelerationDomain), + new CommandParameter("EnableGuestSignInAcceleration", enableGuestSignInAcceleration), + new CommandParameter("UsePersistentCookiesForExplorerView", usePersistentCookiesForExplorerView), + new CommandParameter("BccExternalSharingInvitations", bccExternalSharingInvitations), + new CommandParameter("BccExternalSharingInvitationsList", bccExternalSharingInvitationsList), + new CommandParameter("UserVoiceForFeedbackEnabled", userVoiceForFeedbackEnabled), + new CommandParameter("PublicCdnEnabled", publicVarCdnEnabled), + new CommandParameter("PublicCdnAllowedFileTypes", publicVarCdnAllowedFileTypes), + new CommandParameter("RequireAnonymousLinksExpireInDays", requireAnonymousLinksExpireInDays), + new CommandParameter("SharingAllowedDomainList", sharingAllowedDomainList), + new CommandParameter("SharingBlockedDomainList", sharingBlockedDomainList), + new CommandParameter("SharingDomainRestrictionMode", sharingDomainRestrictionMode), + new CommandParameter("OneDriveStorageQuota", oneDriveStorageQuota), + new CommandParameter("OneDriveForGuestsEnabled", oneDriveForGuestsEnabled), + new CommandParameter("IPAddressEnforcement", iPAddressEnforcement), + new CommandParameter("IPAddressAllowList", iPAddressAllowList), + new CommandParameter("IPAddressWACTokenLifetime", iPAddressWACTokenLifetime), + new CommandParameter("UseFindPeopleInPeoplePicker", useFindPeopleInPeoplePicker), + new CommandParameter("DefaultSharingLinkType", defaultSharingLinkType), + new CommandParameter("ODBMembersCanShare", oDBMembersCanShare), + new CommandParameter("ODBAccessRequests", oDBAccessRequests), + new CommandParameter("PreventExternalUsersFromResharing", preventExternalUsersFromResharing), + new CommandParameter("ShowPeoplePickerSuggestionsForGuestUsers", showPeoplePickerSuggestionsForGuestUsers), + new CommandParameter("FileAnonymousLinkType", fileAnonymousLinkType), + new CommandParameter("FolderAnonymousLinkType", folderAnonymousLinkType), + new CommandParameter("NotifyOwnersWhenItemsReshared", notifyOwnersWhenItemsReshared), + new CommandParameter("NotifyOwnersWhenInvitationsAccepted", notifyOwnersWhenInvitationsAccepted), + new CommandParameter("NotificationsInOneDriveForBusinessEnabled", notificationsInOneDriveForBusinessEnabled), + new CommandParameter("NotificationsInSharePointEnabled", notificationsInSharePointEnabled), + new CommandParameter("OwnerAnonymousNotification", ownerAnonymousNotification), + new CommandParameter("CommentsOnSitePagesDisabled", commentsOnSitePagesDisabled), + new CommandParameter("SocialBarOnSitePagesDisabled", socialBarOnSitePagesDisabled), + new CommandParameter("OrphanedPersonalSitesRetentionPeriod", orphanedPersonalSitesRetentionPeriod), + new CommandParameter("DisallowInfectedFileDownload", disallowInfectedFileDownload), + new CommandParameter("DefaultLinkPermission", defaultLinkPermission), + new CommandParameter("ConditionalAccessPolicy", conditionalAccessPolicy), + new CommandParameter("AllowDownloadingNonWebViewableFiles", allowDownloadingNonWebViewableFiles), + new CommandParameter("AllowEditing", allowEditing), + new CommandParameter("ApplyAppEnforcedRestrictionsToAdHocRecipients", applyAppEnforcedRestrictionsToAdHocRecipients), + new CommandParameter("FilePickerExternalImageSearchEnabled", filePickerExternalImageSearchEnabled), + new CommandParameter("EmailAttestationRequired", emailAttestationRequired), + new CommandParameter("EmailAttestationReAuthDays", emailAttestationReAuthDays), + new CommandParameter("HideDefaultThemes", hideDefaultThemes), + new CommandParameter("DisabledWebPartIds", disabledWebPartIds), + new CommandParameter("EnableAIPIntegration", enableAIPIntegration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Admin/UnregisterPnPHubSiteTests.cs b/Tests/Admin/UnregisterPnPHubSiteTests.cs new file mode 100644 index 000000000..96e723b8e --- /dev/null +++ b/Tests/Admin/UnregisterPnPHubSiteTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Admin +{ + [TestClass] + public class UnregisterHubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UnregisterPnPHubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site to unregister as a hubsite + var site = ""; + + var results = scope.ExecuteCommand("Unregister-PnPHubSite", + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/AddPnPAppTests.cs b/Tests/Apps/AddPnPAppTests.cs new file mode 100644 index 000000000..d16bc05f7 --- /dev/null +++ b/Tests/Apps/AddPnPAppTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class AddAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id or an actual app metadata instance + var path = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + // This is a mandatory parameter + // From Cmdlet Help: This will deploy/trust an app into the app catalog + var publish = ""; + var skipFeatureDeployment = ""; + // From Cmdlet Help: Overwrites the existing app package if it already exists + var overwrite = ""; + // From Cmdlet Help: Specifies the timeout in seconds. Defaults to 200. + var timeoutVar = ""; + + var results = scope.ExecuteCommand("Add-PnPApp", + new CommandParameter("Path", path), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Publish", publish), + new CommandParameter("SkipFeatureDeployment", skipFeatureDeployment), + new CommandParameter("Overwrite", overwrite), + new CommandParameter("Timeout", timeoutVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/ApprovePnPTenantServicePrincipalPermissionRequestTests.cs b/Tests/Apps/ApprovePnPTenantServicePrincipalPermissionRequestTests.cs new file mode 100644 index 000000000..bb6c95ba2 --- /dev/null +++ b/Tests/Apps/ApprovePnPTenantServicePrincipalPermissionRequestTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class ApproveTenantServicePrincipalPermissionRequestsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ApprovePnPTenantServicePrincipalPermissionRequestTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var requestId = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Approve-PnPTenantServicePrincipalPermissionRequest", + new CommandParameter("RequestId", requestId), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/DenyPnPTenantServicePrincipalPermissionRequestTests.cs b/Tests/Apps/DenyPnPTenantServicePrincipalPermissionRequestTests.cs new file mode 100644 index 000000000..f166c03dc --- /dev/null +++ b/Tests/Apps/DenyPnPTenantServicePrincipalPermissionRequestTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class DenyTenantServicePrincipalPermissionRequestsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DenyPnPTenantServicePrincipalPermissionRequestTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var requestId = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Deny-PnPTenantServicePrincipalPermissionRequest", + new CommandParameter("RequestId", requestId), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/DisablePnPTenantServicePrincipalTests.cs b/Tests/Apps/DisablePnPTenantServicePrincipalTests.cs new file mode 100644 index 000000000..d4107919f --- /dev/null +++ b/Tests/Apps/DisablePnPTenantServicePrincipalTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class DisableTenantServicePrincipalTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPTenantServicePrincipalTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Disable-PnPTenantServicePrincipal", + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/EnablePnPTenantServicePrincipalTests.cs b/Tests/Apps/EnablePnPTenantServicePrincipalTests.cs new file mode 100644 index 000000000..e93ce6bc6 --- /dev/null +++ b/Tests/Apps/EnablePnPTenantServicePrincipalTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class EnableTenantServicePrincipalTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPTenantServicePrincipalTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Enable-PnPTenantServicePrincipal", + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GetPnPAppInstanceTests.cs b/Tests/Apps/GetPnPAppInstanceTests.cs new file mode 100644 index 000000000..a1c2db0d4 --- /dev/null +++ b/Tests/Apps/GetPnPAppInstanceTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GetAppInstanceTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAppInstanceTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the Id of the App Instance + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPAppInstance", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GetPnPAppTests.cs b/Tests/Apps/GetPnPAppTests.cs new file mode 100644 index 000000000..8e0dafb8d --- /dev/null +++ b/Tests/Apps/GetPnPAppTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GetAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the Id of an app which is available in the app catalog + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Get-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GetPnPTenantServicePrincipalPermissionGrantsTests.cs b/Tests/Apps/GetPnPTenantServicePrincipalPermissionGrantsTests.cs new file mode 100644 index 000000000..c953feeaa --- /dev/null +++ b/Tests/Apps/GetPnPTenantServicePrincipalPermissionGrantsTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GetTenantServicePrincipalPermissionGrantsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantServicePrincipalPermissionGrantsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantServicePrincipalPermissionGrants"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GetPnPTenantServicePrincipalPermissionRequestsTests.cs b/Tests/Apps/GetPnPTenantServicePrincipalPermissionRequestsTests.cs new file mode 100644 index 000000000..41b8a9f0b --- /dev/null +++ b/Tests/Apps/GetPnPTenantServicePrincipalPermissionRequestsTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GetTenantServicePrincipalPermissionRequestsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantServicePrincipalPermissionRequestsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantServicePrincipalPermissionRequests"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GetPnPTenantServicePrincipalTests.cs b/Tests/Apps/GetPnPTenantServicePrincipalTests.cs new file mode 100644 index 000000000..8a4e53fe5 --- /dev/null +++ b/Tests/Apps/GetPnPTenantServicePrincipalTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GetTenantServicePrincipalTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantServicePrincipalTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantServicePrincipal"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/GrantPnPTenantServicePrincipalPermissionTests.cs b/Tests/Apps/GrantPnPTenantServicePrincipalPermissionTests.cs new file mode 100644 index 000000000..3bd6acf12 --- /dev/null +++ b/Tests/Apps/GrantPnPTenantServicePrincipalPermissionTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class GrantTenantServicePrincipalPermissionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GrantPnPTenantServicePrincipalPermissionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The scope to grant the permission for + var scopeVar = ""; + // This is a mandatory parameter + // From Cmdlet Help: The resource to grant the permission for + var resource = ""; + + var results = scope.ExecuteCommand("Grant-PnPTenantServicePrincipalPermission", + new CommandParameter("Scope", scopeVar), + new CommandParameter("Resource", resource)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/ImportPnPAppPackageTests.cs b/Tests/Apps/ImportPnPAppPackageTests.cs new file mode 100644 index 000000000..bc522dfae --- /dev/null +++ b/Tests/Apps/ImportPnPAppPackageTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class ImportAppPackageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ImportPnPAppPackageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path pointing to the .app file + var path = ""; + // From Cmdlet Help: Will forcibly install the app by activating the addin sideloading feature, installing the addin, and deactivating the sideloading feature + var force = ""; + // From Cmdlet Help: Will only upload the addin, but not install it + var loadOnly = ""; + // From Cmdlet Help: Will install the addin for the specified locale + var locale = ""; + + var results = scope.ExecuteCommand("Import-PnPAppPackage", + new CommandParameter("Path", path), + new CommandParameter("Force", force), + new CommandParameter("LoadOnly", loadOnly), + new CommandParameter("Locale", locale)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/InstallPnPAppTests.cs b/Tests/Apps/InstallPnPAppTests.cs new file mode 100644 index 000000000..5e7d5e0f3 --- /dev/null +++ b/Tests/Apps/InstallPnPAppTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class InstallAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InstallPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id or an actual app metadata instance + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + // From Cmdlet Help: If specified the execution will pause until the app has been installed in the site. + var wait = ""; + + var results = scope.ExecuteCommand("Install-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Wait", wait)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/PublishPnPAppTests.cs b/Tests/Apps/PublishPnPAppTests.cs new file mode 100644 index 000000000..90e9c20c1 --- /dev/null +++ b/Tests/Apps/PublishPnPAppTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class PublishAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void PublishPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id of the app + var identity = ""; + var skipFeatureDeployment = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Publish-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("SkipFeatureDeployment", skipFeatureDeployment), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/RegisterPnPAppCatalogSiteTests.cs b/Tests/Apps/RegisterPnPAppCatalogSiteTests.cs new file mode 100644 index 000000000..e02b31c61 --- /dev/null +++ b/Tests/Apps/RegisterPnPAppCatalogSiteTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class RegisterAppCatalogSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RegisterPnPAppCatalogSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The full url of the app catalog site to be created, e.g. https://yourtenant.sharepoint.com/sites/appcatalog + var url = ""; + // This is a mandatory parameter + // From Cmdlet Help: The login account of the user designated to be the admin for the site, e.g. user@domain.com + var owner = ""; + // This is a mandatory parameter + // From Cmdlet Help: Use Get-PnPTimeZoneId to retrieve possible timezone values + var timeZoneId = ""; + // From Cmdlet Help: If specified, and an app catalog is already present, a new app catalog site will be created. If the same URL is used the existing/current app catalog site will be deleted first. + var force = ""; + + var results = scope.ExecuteCommand("Register-PnPAppCatalogSite", + new CommandParameter("Url", url), + new CommandParameter("Owner", owner), + new CommandParameter("TimeZoneId", timeZoneId), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/RemovePnPAppTests.cs b/Tests/Apps/RemovePnPAppTests.cs new file mode 100644 index 000000000..53bd7ae85 --- /dev/null +++ b/Tests/Apps/RemovePnPAppTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class RemoveAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id of the Addin Instance + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Remove-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/RevokePnPTenantServicePrincipalPermissionTests.cs b/Tests/Apps/RevokePnPTenantServicePrincipalPermissionTests.cs new file mode 100644 index 000000000..a485f194a --- /dev/null +++ b/Tests/Apps/RevokePnPTenantServicePrincipalPermissionTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class RevokeTenantServicePrincipalTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RevokePnPTenantServicePrincipalPermissionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var objectId = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Revoke-PnPTenantServicePrincipalPermission", + new CommandParameter("ObjectId", objectId), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/SyncPnPAppToTeamsTests.cs b/Tests/Apps/SyncPnPAppToTeamsTests.cs new file mode 100644 index 000000000..f8bb0397d --- /dev/null +++ b/Tests/Apps/SyncPnPAppToTeamsTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class SyncAppToTeamsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SyncPnPAppToTeamsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id of the Addin Instance + var identity = ""; + + var results = scope.ExecuteCommand("Sync-PnPAppToTeams", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/UninstallPnPAppInstanceTests.cs b/Tests/Apps/UninstallPnPAppInstanceTests.cs new file mode 100644 index 000000000..2e193de41 --- /dev/null +++ b/Tests/Apps/UninstallPnPAppInstanceTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class UninstallAppInstanceTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UninstallPnPAppInstanceTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Appinstance or Id of the addin to remove. + var identity = ""; + // From Cmdlet Help: Do not ask for confirmation. + var force = ""; + + var results = scope.ExecuteCommand("Uninstall-PnPAppInstance", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/UninstallPnPAppTests.cs b/Tests/Apps/UninstallPnPAppTests.cs new file mode 100644 index 000000000..d09b51d94 --- /dev/null +++ b/Tests/Apps/UninstallPnPAppTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class UninstallAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UninstallPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id of the Addin Instance + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Uninstall-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/UnpublishPnPAppTests.cs b/Tests/Apps/UnpublishPnPAppTests.cs new file mode 100644 index 000000000..762cf5dd6 --- /dev/null +++ b/Tests/Apps/UnpublishPnPAppTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class UnpublishAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UnpublishPnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id of the Addin Instance + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Unpublish-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Apps/UpdatePnPAppTests.cs b/Tests/Apps/UpdatePnPAppTests.cs new file mode 100644 index 000000000..aad5648a0 --- /dev/null +++ b/Tests/Apps/UpdatePnPAppTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Apps +{ + [TestClass] + public class UpdateAppTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UpdatePnPAppTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the Id or an actual app metadata instance + var identity = ""; + // From Cmdlet Help: Defines which app catalog to use. Defaults to Tenant + var scopeVar = ""; + + var results = scope.ExecuteCommand("Update-PnPApp", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/AddPnPStoredCredentialTests.cs b/Tests/Base/AddPnPStoredCredentialTests.cs new file mode 100644 index 000000000..0de423be5 --- /dev/null +++ b/Tests/Base/AddPnPStoredCredentialTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class AddStoredCredentialTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPStoredCredentialTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The credential to set + var name = ""; + // This is a mandatory parameter + var username = ""; + // From Cmdlet Help: If not specified you will be prompted to enter your password. + // If you want to specify this value use ConvertTo-SecureString -String 'YourPassword' -AsPlainText -Force + var password = ""; + + var results = scope.ExecuteCommand("Add-PnPStoredCredential", + new CommandParameter("Name", name), + new CommandParameter("Username", username), + new CommandParameter("Password", password)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/ConnectPnPOnlineTests.cs b/Tests/Base/ConnectPnPOnlineTests.cs new file mode 100644 index 000000000..d52b0f2c6 --- /dev/null +++ b/Tests/Base/ConnectPnPOnlineTests.cs @@ -0,0 +1,238 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class ConnectOnlineTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ConnectPnPOnlineTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the connection for use with the -Connection parameter on cmdlets. + var returnConnection = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Url of the site collection to connect to + var url = ""; + // From Cmdlet Help: Credentials of the user to connect with. Either specify a PSCredential object or a string. In case of a string value a lookup will be done to the Generic Credentials section of the Windows Credentials in the Windows Credential Manager for the correct credentials. + var credentials = ""; + // From Cmdlet Help: If you want to connect with the current user credentials + var currentCredentials = ""; + // From Cmdlet Help: If you want to connect to SharePoint using ADFS and credentials + var useAdfs = ""; + // From Cmdlet Help: If you want to connect to SharePoint farm using ADFS with a client certificate + var useAdfsCert = ""; + // From Cmdlet Help: The client certificate which you want to use for the ADFS authentication + var clientCertificate = ""; + // From Cmdlet Help: Authenticate using Kerberos to ADFS + var kerberos = ""; + // From Cmdlet Help: The name of the ADFS trusted login provider + var loginProviderName = ""; + // From Cmdlet Help: Specifies a minimal server healthscore before any requests are executed + var minimalHealthScore = ""; + // From Cmdlet Help: Defines how often a retry should be executed if the server healthscore is not sufficient. Default is 10 times. + var retryCount = ""; + // From Cmdlet Help: Defines how many seconds to wait before each retry. Default is 1 second. + var retryWait = ""; + // From Cmdlet Help: The request timeout. Default is 1800000 + var requestTimeoutVar = ""; + // From Cmdlet Help: Authentication realm. If not specified will be resolved from the url specified. + var realm = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Application Client ID to use. + var appId = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Application Client Secret to use. + var appSecret = ""; + // This is a mandatory parameter + // From Cmdlet Help: The client secret to use. + var clientSecret = ""; + // This is a mandatory parameter + // From Cmdlet Help: If you want to connect to SharePoint with browser based login. This is required when you have multi-factor authentication (MFA) enabled. + var useWebLogin = ""; + // From Cmdlet Help: Specify to use for instance use forms based authentication (FBA) + var authenticationMode = ""; + // From Cmdlet Help: If you want to create a PSDrive connected to the URL + var createDrive = ""; + // From Cmdlet Help: Name of the PSDrive to create (default: SPO) + var driveName = ""; + // This is a mandatory parameter + // From Cmdlet Help: Log in using the SharePoint Online Management Shell application + var sPOManagementShell = ""; + // This is a mandatory parameter + // From Cmdlet Help: Log in using the PnP O365 Management Shell application. You will be asked to consent to:* Read and write managed metadata + // * Have full control of all site collections + // * Read user profiles + // * Invite guest users to the organization + // * Read and write all groups + // * Read and write directory data + // * Read and write identity providers + // * Access the directory as you + var pnPO365ManagementShell = ""; + // From Cmdlet Help: Launch a browser automatically and copy the code to enter to the clipboard + var launchBrowser = ""; + // This is a mandatory parameter + // From Cmdlet Help: Log in using the PnP O365 Management Shell application towards the Graph. You will be asked to consent to:* Read and write managed metadata + // * Have full control of all site collections + // * Read user profiles + // * Invite guest users to the organization + // * Read and write all groups + // * Read and write directory data + // * Read and write identity providers + // * Access the directory as you + // + var graph = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client ID of the Azure AD Application + var clientId = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Redirect URI of the Azure AD Application + var redirectUri = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Azure AD Tenant name,e.g. mycompany.onmicrosoft.com + var tenant = ""; + // From Cmdlet Help: Path to the certificate containing the private key (*.pfx) + var certificatePath = ""; + // From Cmdlet Help: Base64 Encoded X509Certificate2 certificate containing the private key to authenticate the requests to SharePoint Online such as retrieved in Azure Functions from Azure KeyVault + var certificateBase64Encoded = ""; + // From Cmdlet Help: X509Certificate2 reference containing the private key to authenticate the requests to SharePoint Online + var certificate = ""; + // From Cmdlet Help: Password to the certificate (*.pfx) + var certificatePassword = ""; + // This is a mandatory parameter + // From Cmdlet Help: PEM encoded certificate + var pEMCertificate = ""; + // This is a mandatory parameter + // From Cmdlet Help: PEM encoded private key for the certificate + var pEMPrivateKey = ""; + // This is a mandatory parameter + // From Cmdlet Help: Certificate thumbprint + var thumbprint = ""; + // From Cmdlet Help: Clears the token cache. + var clearTokenCache = ""; + // From Cmdlet Help: The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment. + var azureEnvironment = ""; + // This is a mandatory parameter + // From Cmdlet Help: The array of permission scopes for the Microsoft Graph API. + var scopeVars = ""; + // This is a mandatory parameter + // From Cmdlet Help: The AAD where the O365 app is registered. Eg.: contoso.com, or contoso.onmicrosoft.com. + var aADDomain = ""; + // This is a mandatory parameter + // From Cmdlet Help: Connect with an existing Access Token + var accessToken = ""; + // From Cmdlet Help: The url to the Tenant Admin site. If not specified, the cmdlets will assume to connect automatically to https://-admin.sharepoint.com where appropriate. + var tenantAdminUrl = ""; + // From Cmdlet Help: Should we skip the check if this site is the Tenant admin site. Default is false + var skipTenantAdminCheck = ""; + // From Cmdlet Help: Ignores any SSL errors. To be used i.e. when connecting to a SharePoint farm using self signed certificates or using a certificate authority not trusted by this machine. + var ignoreSslErrors = ""; + // From Cmdlet Help: In order to help to make PnP PowerShell better, we can track anonymous telemetry. We track the version of the cmdlets you are using, which cmdlet you are executing and which version of SharePoint you are connecting to. Use Disable-PnPPowerShellTelemetry to turn this off in general or use the -NoTelemetry switch to turn it off for that session. + var noTelemetry = ""; + + var results = scope.ExecuteCommand("Connect-PnPOnline", + new CommandParameter("ReturnConnection", returnConnection), + new CommandParameter("Url", url), + new CommandParameter("Credentials", credentials), + new CommandParameter("CurrentCredentials", currentCredentials), + new CommandParameter("UseAdfs", useAdfs), + new CommandParameter("UseAdfsCert", useAdfsCert), + new CommandParameter("ClientCertificate", clientCertificate), + new CommandParameter("Kerberos", kerberos), + new CommandParameter("LoginProviderName", loginProviderName), + new CommandParameter("MinimalHealthScore", minimalHealthScore), + new CommandParameter("RetryCount", retryCount), + new CommandParameter("RetryWait", retryWait), + new CommandParameter("RequestTimeout", requestTimeoutVar), + new CommandParameter("Realm", realm), + new CommandParameter("AppId", appId), + new CommandParameter("AppSecret", appSecret), + new CommandParameter("ClientSecret", clientSecret), + new CommandParameter("UseWebLogin", useWebLogin), + new CommandParameter("AuthenticationMode", authenticationMode), + new CommandParameter("CreateDrive", createDrive), + new CommandParameter("DriveName", driveName), + new CommandParameter("SPOManagementShell", sPOManagementShell), + new CommandParameter("PnPO365ManagementShell", pnPO365ManagementShell), + new CommandParameter("LaunchBrowser", launchBrowser), + new CommandParameter("Graph", graph), + new CommandParameter("ClientId", clientId), + new CommandParameter("RedirectUri", redirectUri), + new CommandParameter("Tenant", tenant), + new CommandParameter("CertificatePath", certificatePath), + new CommandParameter("CertificateBase64Encoded", certificateBase64Encoded), + new CommandParameter("Certificate", certificate), + new CommandParameter("CertificatePassword", certificatePassword), + new CommandParameter("PEMCertificate", pEMCertificate), + new CommandParameter("PEMPrivateKey", pEMPrivateKey), + new CommandParameter("Thumbprint", thumbprint), + new CommandParameter("ClearTokenCache", clearTokenCache), + new CommandParameter("AzureEnvironment", azureEnvironment), + new CommandParameter("Scopes", scopeVars), + new CommandParameter("AADDomain", aADDomain), + new CommandParameter("AccessToken", accessToken), + new CommandParameter("TenantAdminUrl", tenantAdminUrl), + new CommandParameter("SkipTenantAdminCheck", skipTenantAdminCheck), + new CommandParameter("IgnoreSslErrors", ignoreSslErrors), + new CommandParameter("NoTelemetry", noTelemetry)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/DisablePnPPowerShellTelemetryTests.cs b/Tests/Base/DisablePnPPowerShellTelemetryTests.cs new file mode 100644 index 000000000..8c4f8be2b --- /dev/null +++ b/Tests/Base/DisablePnPPowerShellTelemetryTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class DisablePowerShellTelemetryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPPowerShellTelemetryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Disable-PnPPowerShellTelemetry", + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/DisconnectPnPOnlineTests.cs b/Tests/Base/DisconnectPnPOnlineTests.cs new file mode 100644 index 000000000..158a0fdf7 --- /dev/null +++ b/Tests/Base/DisconnectPnPOnlineTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class DisconnectOnlineTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisconnectPnPOnlineTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Connection to be used by cmdlet + var connection = ""; + + var results = scope.ExecuteCommand("Disconnect-PnPOnline", + new CommandParameter("Connection", connection)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/EnablePnPPowerShellTelemetryTests.cs b/Tests/Base/EnablePnPPowerShellTelemetryTests.cs new file mode 100644 index 000000000..3e5f39a05 --- /dev/null +++ b/Tests/Base/EnablePnPPowerShellTelemetryTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class EnablePowerShellTelemetryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPPowerShellTelemetryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Enable-PnPPowerShellTelemetry", + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPAccessTokenTests.cs b/Tests/Base/GetPnPAccessTokenTests.cs new file mode 100644 index 000000000..01b6f0d07 --- /dev/null +++ b/Tests/Base/GetPnPAccessTokenTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetPnPAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the details from the access token in a decoded manner + var decoded = ""; + + var results = scope.ExecuteCommand("Get-PnPAccessToken", + new CommandParameter("Decoded", decoded)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPAppAuthAccessTokenTests.cs b/Tests/Base/GetPnPAppAuthAccessTokenTests.cs new file mode 100644 index 000000000..c10a481a7 --- /dev/null +++ b/Tests/Base/GetPnPAppAuthAccessTokenTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetPnPAppAuthAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAppAuthAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPAppAuthAccessToken"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPAuthenticationRealmTests.cs b/Tests/Base/GetPnPAuthenticationRealmTests.cs new file mode 100644 index 000000000..9a0f8da92 --- /dev/null +++ b/Tests/Base/GetPnPAuthenticationRealmTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetAuthenticationRealmTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAuthenticationRealmTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the URL of the site + var url = ""; + + var results = scope.ExecuteCommand("Get-PnPAuthenticationRealm", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPAzureCertificateTests.cs b/Tests/Base/GetPnPAzureCertificateTests.cs new file mode 100644 index 000000000..8bc3f4f75 --- /dev/null +++ b/Tests/Base/GetPnPAzureCertificateTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetPnPAdalCertificateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAzureCertificateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the certificate (*.pfx) + var certificatePath = ""; + // From Cmdlet Help: Password to the certificate (*.pfx) + var certificatePassword = ""; + + var results = scope.ExecuteCommand("Get-PnPAzureCertificate", + new CommandParameter("CertificatePath", certificatePath), + new CommandParameter("CertificatePassword", certificatePassword)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPConnectionTests.cs b/Tests/Base/GetPnPConnectionTests.cs new file mode 100644 index 000000000..af1b01d20 --- /dev/null +++ b/Tests/Base/GetPnPConnectionTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetPnPConnectionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPConnectionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPConnection"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPContextTests.cs b/Tests/Base/GetPnPContextTests.cs new file mode 100644 index 000000000..acf1e4821 --- /dev/null +++ b/Tests/Base/GetPnPContextTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetSPOContextTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPContextTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPContext"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPExceptionTests.cs b/Tests/Base/GetPnPExceptionTests.cs new file mode 100644 index 000000000..c7528f05a --- /dev/null +++ b/Tests/Base/GetPnPExceptionTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetExceptionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPExceptionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Show all exceptions + var all = ""; + + var results = scope.ExecuteCommand("Get-PnPException", + new CommandParameter("All", all)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPGraphAccessTokenTests.cs b/Tests/Base/GetPnPGraphAccessTokenTests.cs new file mode 100644 index 000000000..d86bbb2ad --- /dev/null +++ b/Tests/Base/GetPnPGraphAccessTokenTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetGraphAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPGraphAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the access token in a decoded manner + var decoded = ""; + + var results = scope.ExecuteCommand("Get-PnPGraphAccessToken", + new CommandParameter("Decoded", decoded)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPHealthScoreTests.cs b/Tests/Base/GetPnPHealthScoreTests.cs new file mode 100644 index 000000000..4131e8199 --- /dev/null +++ b/Tests/Base/GetPnPHealthScoreTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetHealthScoreTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHealthScoreTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The url of the WebApplication to retrieve the health score from + var url = ""; + + var results = scope.ExecuteCommand("Get-PnPHealthScore", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPPowerShellTelemetryEnabledTests.cs b/Tests/Base/GetPnPPowerShellTelemetryEnabledTests.cs new file mode 100644 index 000000000..0ce834b7b --- /dev/null +++ b/Tests/Base/GetPnPPowerShellTelemetryEnabledTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetPowerShellTelemetryEnabledTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPPowerShellTelemetryEnabledTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPPowerShellTelemetryEnabled"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPPropertyTests.cs b/Tests/Base/GetPnPPropertyTests.cs new file mode 100644 index 000000000..f88a62a47 --- /dev/null +++ b/Tests/Base/GetPnPPropertyTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class EnsurePropertyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPPropertyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the object where the properties of should be retrieved + var clientObject = ""; + // This is a mandatory parameter + // From Cmdlet Help: The properties to load. If one property is specified its value will be returned to the output. + var property = ""; + + var results = scope.ExecuteCommand("Get-PnPProperty", + new CommandParameter("ClientObject", clientObject), + new CommandParameter("Property", property)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/GetPnPStoredCredentialTests.cs b/Tests/Base/GetPnPStoredCredentialTests.cs new file mode 100644 index 000000000..7c2b18cc6 --- /dev/null +++ b/Tests/Base/GetPnPStoredCredentialTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class GetStoredCredentialTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPStoredCredentialTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The credential to retrieve. + var name = ""; + // From Cmdlet Help: The object type of the credential to return from the Credential Manager. Possible values are 'O365', 'OnPrem' or 'PSCredential' + var type = ""; + + var results = scope.ExecuteCommand("Get-PnPStoredCredential", + new CommandParameter("Name", name), + new CommandParameter("Type", type)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/InitializePnPPowerShellAuthenticationTests.cs b/Tests/Base/InitializePnPPowerShellAuthenticationTests.cs new file mode 100644 index 000000000..bd3098467 --- /dev/null +++ b/Tests/Base/InitializePnPPowerShellAuthenticationTests.cs @@ -0,0 +1,116 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class InitializePowerShellAuthenticationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InitializePnPPowerShellAuthenticationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the Azure AD Application to create + var applicationName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The identifier of your tenant, e.g. mytenant.onmicrosoft.com + var tenant = ""; + // This is a mandatory parameter + // From Cmdlet Help: Password for the certificate being created + var certificatePath = ""; + // From Cmdlet Help: Common Name (e.g. server FQDN or YOUR name). defaults to 'pnp.contoso.com' + var commonName = ""; + // From Cmdlet Help: Country Name (2 letter code) + var country = ""; + // From Cmdlet Help: State or Province Name (full name) + var state = ""; + // From Cmdlet Help: Locality Name (eg, city) + var locality = ""; + // From Cmdlet Help: Organization Name (eg, company) + var organization = ""; + // From Cmdlet Help: Organizational Unit Name (eg, section) + var organizationUnit = ""; + // From Cmdlet Help: Number of years until expiration (default is 10, max is 30) + var validYears = ""; + // From Cmdlet Help: Optional certificate password + var certificatePassword = ""; + // From Cmdlet Help: Folder to create certificate files in (.CER and .PFX) + var outVarPath = ""; + // From Cmdlet Help: Local Certificate Store to add the certificate to + var store = ""; + + var results = scope.ExecuteCommand("Initialize-PnPPowerShellAuthentication", + new CommandParameter("ApplicationName", applicationName), + new CommandParameter("Tenant", tenant), + new CommandParameter("CertificatePath", certificatePath), + new CommandParameter("CommonName", commonName), + new CommandParameter("Country", country), + new CommandParameter("State", state), + new CommandParameter("Locality", locality), + new CommandParameter("Organization", organization), + new CommandParameter("OrganizationUnit", organizationUnit), + new CommandParameter("ValidYears", validYears), + new CommandParameter("CertificatePassword", certificatePassword), + new CommandParameter("OutPath", outVarPath), + new CommandParameter("Store", store)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/InvokePnPQueryTests.cs b/Tests/Base/InvokePnPQueryTests.cs new file mode 100644 index 000000000..43a891fc1 --- /dev/null +++ b/Tests/Base/InvokePnPQueryTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class InvokeQueryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InvokePnPQueryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Number of times to retry in case of throttling. Defaults to 10. + var retryCount = ""; + // From Cmdlet Help: Delay in seconds. Defaults to 1. + var retryWait = ""; + + var results = scope.ExecuteCommand("Invoke-PnPQuery", + new CommandParameter("RetryCount", retryCount), + new CommandParameter("RetryWait", retryWait)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/NewPnPAzureCertificateTests.cs b/Tests/Base/NewPnPAzureCertificateTests.cs new file mode 100644 index 000000000..adc693379 --- /dev/null +++ b/Tests/Base/NewPnPAzureCertificateTests.cs @@ -0,0 +1,107 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class NewPnPAdalCertificateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPAzureCertificateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Common Name (e.g. server FQDN or YOUR name) [pnp.contoso.com] + var commonName = ""; + // From Cmdlet Help: Country Name (2 letter code) + var country = ""; + // From Cmdlet Help: State or Province Name (full name) + var state = ""; + // From Cmdlet Help: Locality Name (eg, city) + var locality = ""; + // From Cmdlet Help: Organization Name (eg, company) + var organization = ""; + // From Cmdlet Help: Organizational Unit Name (eg, section) + var organizationUnit = ""; + // From Cmdlet Help: Filename to write to, optionally including full path (.pfx) + var outVar = ""; + // From Cmdlet Help: Filename to write to, optionally including full path (.pfx) + var outVarPfx = ""; + // From Cmdlet Help: Filename to write to, optionally including full path (.cer) + var outVarCert = ""; + // From Cmdlet Help: Number of years until expiration (default is 10, max is 30) + var validYears = ""; + // From Cmdlet Help: Optional certificate password + var certificatePassword = ""; + + var results = scope.ExecuteCommand("New-PnPAzureCertificate", + new CommandParameter("CommonName", commonName), + new CommandParameter("Country", country), + new CommandParameter("State", state), + new CommandParameter("Locality", locality), + new CommandParameter("Organization", organization), + new CommandParameter("OrganizationUnit", organizationUnit), + new CommandParameter("Out", outVar), + new CommandParameter("OutPfx", outVarPfx), + new CommandParameter("OutCert", outVarCert), + new CommandParameter("ValidYears", validYears), + new CommandParameter("CertificatePassword", certificatePassword)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/RemovePnPStoredCredentialTests.cs b/Tests/Base/RemovePnPStoredCredentialTests.cs new file mode 100644 index 000000000..08c06a844 --- /dev/null +++ b/Tests/Base/RemovePnPStoredCredentialTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class RemoveStoredCredentialTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPStoredCredentialTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The credential to remove + var name = ""; + // From Cmdlet Help: If specified you will not be asked for confirmation + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPStoredCredential", + new CommandParameter("Name", name), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/RequestPnPAccessTokenTests.cs b/Tests/Base/RequestPnPAccessTokenTests.cs new file mode 100644 index 000000000..b6ea5ef89 --- /dev/null +++ b/Tests/Base/RequestPnPAccessTokenTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class RequestAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RequestPnPAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The Azure Application Client Id to use to retrieve the token. Defaults to the PnP Office 365 Management Shell + var clientId = ""; + // From Cmdlet Help: The scopes to retrieve the token for. Defaults to AllSites.FullControl + var resource = ""; + // From Cmdlet Help: The scopes to retrieve the token for. Defaults to AllSites.FullControl + var scopeVars = ""; + // From Cmdlet Help: Returns the token in a decoded / human readible manner + var decoded = ""; + // From Cmdlet Help: Set this token as the current token to use when performing Azure AD based authentication requests with PnP PowerShell + var setAsCurrent = ""; + // From Cmdlet Help: Optional credentials to use when retrieving the access token. If not present you need to connect first with Connect-PnPOnline. + var credentials = ""; + // From Cmdlet Help: Optional tenant URL to use when retrieving the access token. The Url should be in the shape of https://yourtenant.sharepoint.com. See examples for more info. + var tenantUrl = ""; + + var results = scope.ExecuteCommand("Request-PnPAccessToken", + new CommandParameter("ClientId", clientId), + new CommandParameter("Resource", resource), + new CommandParameter("Scopes", scopeVars), + new CommandParameter("Decoded", decoded), + new CommandParameter("SetAsCurrent", setAsCurrent), + new CommandParameter("Credentials", credentials), + new CommandParameter("TenantUrl", tenantUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/SetPnPContextTests.cs b/Tests/Base/SetPnPContextTests.cs new file mode 100644 index 000000000..5c55cf714 --- /dev/null +++ b/Tests/Base/SetPnPContextTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class SetContextTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPContextTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ClientContext to set + var context = ""; + + var results = scope.ExecuteCommand("Set-PnPContext", + new CommandParameter("Context", context)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Base/SetPnPTraceLogTests.cs b/Tests/Base/SetPnPTraceLogTests.cs new file mode 100644 index 000000000..b13f5c352 --- /dev/null +++ b/Tests/Base/SetPnPTraceLogTests.cs @@ -0,0 +1,100 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Base +{ + [TestClass] + public class SetTraceLogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPTraceLogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Turn on tracing to log file + var on = ""; + // From Cmdlet Help: The path and filename of the file to write the trace log to. + var logFile = ""; + // From Cmdlet Help: Turn on console trace output. + var writeToConsole = ""; + // From Cmdlet Help: The level of events to capture. Possible values are 'Debug', 'Error', 'Warning', 'Information'. Defaults to 'Information'. + var level = ""; + // From Cmdlet Help: If specified the trace log entries will be delimited with this value. + var delimiter = ""; + // From Cmdlet Help: Indents in the tracelog will be with this amount of characters. Defaults to 4. + var indentSize = ""; + // From Cmdlet Help: Auto flush the trace log. Defaults to true. + var autoFlush = ""; + // This is a mandatory parameter + // From Cmdlet Help: Turn off tracing to log file. + var off = ""; + + var results = scope.ExecuteCommand("Set-PnPTraceLog", + new CommandParameter("On", on), + new CommandParameter("LogFile", logFile), + new CommandParameter("WriteToConsole", writeToConsole), + new CommandParameter("Level", level), + new CommandParameter("Delimiter", delimiter), + new CommandParameter("IndentSize", indentSize), + new CommandParameter("AutoFlush", autoFlush), + new CommandParameter("Off", off)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/AddPnPApplicationCustomizerTests.cs b/Tests/Branding/AddPnPApplicationCustomizerTests.cs new file mode 100644 index 000000000..e71f924c1 --- /dev/null +++ b/Tests/Branding/AddPnPApplicationCustomizerTests.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class AddApplicationCustomizerTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPApplicationCustomizerTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The title of the application customizer + var title = ""; + // From Cmdlet Help: The description of the application customizer + var description = ""; + // From Cmdlet Help: Sequence of this application customizer being injected. Use when you have a specific sequence with which to have multiple application customizers being added to the page. + var sequence = ""; + // From Cmdlet Help: The scope of the CustomAction to add to. Either Web or Site; defaults to Web. 'All' is not valid for this command. + var scopeVar = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client Side Component Id of the SharePoint Framework client side extension application customizer found in the manifest + var clientSideComponentId = ""; + // From Cmdlet Help: The Client Side Component Properties of the application customizer. Specify values as a json string : "{Property1 : 'Value1', Property2: 'Value2'}" + var clientSideComponentProperties = ""; + // From Cmdlet Help: The Client Side Host Properties of the application customizer. Specify values as a json string : "{'preAllocatedApplicationCustomizerTopHeight': '50', 'preAllocatedApplicationCustomizerBottomHeight': '50'}" + var clientSideHostProperties = ""; + + var results = scope.ExecuteCommand("Add-PnPApplicationCustomizer", + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Sequence", sequence), + new CommandParameter("Scope", scopeVar), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("ClientSideComponentProperties", clientSideComponentProperties), + new CommandParameter("ClientSideHostProperties", clientSideHostProperties)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/AddPnPCustomActionTests.cs b/Tests/Branding/AddPnPCustomActionTests.cs new file mode 100644 index 000000000..e220c5530 --- /dev/null +++ b/Tests/Branding/AddPnPCustomActionTests.cs @@ -0,0 +1,128 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class AddCustomActionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPCustomActionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the custom action + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The title of the custom action + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: The description of the custom action + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: The group where this custom action needs to be added like 'SiteActions' + var group = ""; + // This is a mandatory parameter + // From Cmdlet Help: The actual location where this custom action need to be added like 'CommandUI.Ribbon' + var location = ""; + // From Cmdlet Help: Sequence of this CustomAction being injected. Use when you have a specific sequence with which to have multiple CustomActions being added to the page. + var sequence = ""; + // From Cmdlet Help: The URL, URI or ECMAScript (JScript, JavaScript) function associated with the action + var url = ""; + // From Cmdlet Help: The URL of the image associated with the custom action + var imageUrl = ""; + // From Cmdlet Help: XML fragment that determines user interface properties of the custom action + var commandUIExtension = ""; + // From Cmdlet Help: The identifier of the object associated with the custom action. + var registrationId = ""; + // From Cmdlet Help: A string array that contain the permissions needed for the custom action + var rights = ""; + // From Cmdlet Help: Specifies the type of object associated with the custom action + var registrationType = ""; + // From Cmdlet Help: The scope of the CustomAction to add to. Either Web or Site; defaults to Web. 'All' is not valid for this command. + var scopeVar = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client Side Component Id of the custom action + var clientSideComponentId = ""; + // From Cmdlet Help: The Client Side Component Properties of the custom action. Specify values as a json string : "{Property1 : 'Value1', Property2: 'Value2'}" + var clientSideComponentProperties = ""; + // From Cmdlet Help: The Client Side Host Properties of the custom action. Specify values as a json string : "{'preAllocatedApplicationCustomizerTopHeight': '50', 'preAllocatedApplicationCustomizerBottomHeight': '50'}" + var clientSideHostProperties = ""; + + var results = scope.ExecuteCommand("Add-PnPCustomAction", + new CommandParameter("Name", name), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Group", group), + new CommandParameter("Location", location), + new CommandParameter("Sequence", sequence), + new CommandParameter("Url", url), + new CommandParameter("ImageUrl", imageUrl), + new CommandParameter("CommandUIExtension", commandUIExtension), + new CommandParameter("RegistrationId", registrationId), + new CommandParameter("Rights", rights), + new CommandParameter("RegistrationType", registrationType), + new CommandParameter("Scope", scopeVar), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("ClientSideComponentProperties", clientSideComponentProperties), + new CommandParameter("ClientSideHostProperties", clientSideHostProperties)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/AddPnPJavaScriptBlockTests.cs b/Tests/Branding/AddPnPJavaScriptBlockTests.cs new file mode 100644 index 000000000..fe7180a1b --- /dev/null +++ b/Tests/Branding/AddPnPJavaScriptBlockTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class AddJavaScriptBlockTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPJavaScriptBlockTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the script block. Can be used to identify the script with other cmdlets or coded solutions + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The javascript block to add to the specified scope + var script = ""; + // From Cmdlet Help: A sequence number that defines the order on the page + var sequence = ""; + var siteScoped = ""; + // From Cmdlet Help: The scope of the script to add to. Either Web or Site, defaults to Web. 'All' is not valid for this command. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Add-PnPJavaScriptBlock", + new CommandParameter("Name", name), + new CommandParameter("Script", script), + new CommandParameter("Sequence", sequence), + new CommandParameter("SiteScoped", siteScoped), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/AddPnPJavaScriptLinkTests.cs b/Tests/Branding/AddPnPJavaScriptLinkTests.cs new file mode 100644 index 000000000..b272c2aff --- /dev/null +++ b/Tests/Branding/AddPnPJavaScriptLinkTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class AddJavaScriptLinkTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPJavaScriptLinkTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Name under which to register the JavaScriptLink + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: URL to the JavaScript file to inject + var url = ""; + // From Cmdlet Help: Sequence of this JavaScript being injected. Use when you have a specific sequence with which to have JavaScript files being added to the page. I.e. jQuery library first and then jQueryUI. + var sequence = ""; + var siteScoped = ""; + // From Cmdlet Help: Defines if this JavaScript file will be injected to every page within the current site collection or web. All is not allowed in for this command. Default is web. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Add-PnPJavaScriptLink", + new CommandParameter("Name", name), + new CommandParameter("Url", url), + new CommandParameter("Sequence", sequence), + new CommandParameter("SiteScoped", siteScoped), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/AddPnPNavigationNodeTests.cs b/Tests/Branding/AddPnPNavigationNodeTests.cs new file mode 100644 index 000000000..f085c36a6 --- /dev/null +++ b/Tests/Branding/AddPnPNavigationNodeTests.cs @@ -0,0 +1,97 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class AddNavigationNodeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPNavigationNodeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The location where to add the navigation node to. Either TopNavigationBar, QuickLaunch, SearchNav or Footer. + var location = ""; + // This is a mandatory parameter + // From Cmdlet Help: The title of the node to add + var title = ""; + // From Cmdlet Help: The url to navigate to when clicking the new menu item. This can either be absolute or relative to the Web. Fragments are not supported. + var url = ""; + // From Cmdlet Help: The key of the parent. Leave empty to add to the top level + var parent = ""; + // From Cmdlet Help: Optional value of a header entry to add the menu item to + var header = ""; + // From Cmdlet Help: Add the new menu item to beginning of the collection + var first = ""; + // From Cmdlet Help: Indicates the destination URL is outside of the site collection + var external = ""; + + var results = scope.ExecuteCommand("Add-PnPNavigationNode", + new CommandParameter("Location", location), + new CommandParameter("Title", title), + new CommandParameter("Url", url), + new CommandParameter("Parent", parent), + new CommandParameter("Header", header), + new CommandParameter("First", first), + new CommandParameter("External", external)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/DisablePnPResponsiveUITests.cs b/Tests/Branding/DisablePnPResponsiveUITests.cs new file mode 100644 index 000000000..69b9c4727 --- /dev/null +++ b/Tests/Branding/DisablePnPResponsiveUITests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class DisableResponsiveUITests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPResponsiveUITest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Disable-PnPResponsiveUI"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/EnablePnPResponsiveUITests.cs b/Tests/Branding/EnablePnPResponsiveUITests.cs new file mode 100644 index 000000000..c87f5cfa6 --- /dev/null +++ b/Tests/Branding/EnablePnPResponsiveUITests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class EnableResponsiveUITests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPResponsiveUITest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: A full URL pointing to an infrastructure site. If specified, it will add a custom action pointing to the responsive UI JS code in that site. + var infrastructureSiteUrl = ""; + + var results = scope.ExecuteCommand("Enable-PnPResponsiveUI", + new CommandParameter("InfrastructureSiteUrl", infrastructureSiteUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPApplicationCustomizerTests.cs b/Tests/Branding/GetPnPApplicationCustomizerTests.cs new file mode 100644 index 000000000..598cf7c32 --- /dev/null +++ b/Tests/Branding/GetPnPApplicationCustomizerTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetApplicationCustomizerTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPApplicationCustomizerTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Identity of the SharePoint Framework client side extension application customizer to return. Omit to return all SharePoint Frameworkclient side extension application customizer. + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client Side Component Id of the SharePoint Framework client side extension application customizer found in the manifest for which existing custom action(s) should be removed + var clientSideComponentId = ""; + // From Cmdlet Help: Scope of the SharePoint Framework client side extension application customizer, either Web, Site or All to return both (all is the default) + var scopeVar = ""; + // From Cmdlet Help: Switch parameter if an exception should be thrown if the requested SharePoint Frameworkclient side extension application customizer does not exist (true) or if omitted, nothing will be returned in case the SharePoint Framework client side extension application customizer does not exist + var throwExceptionIfCustomActionNotFound = ""; + + var results = scope.ExecuteCommand("Get-PnPApplicationCustomizer", + new CommandParameter("Identity", identity), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("Scope", scopeVar), + new CommandParameter("ThrowExceptionIfCustomActionNotFound", throwExceptionIfCustomActionNotFound)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPCustomActionTests.cs b/Tests/Branding/GetPnPCustomActionTests.cs new file mode 100644 index 000000000..9fe7f60eb --- /dev/null +++ b/Tests/Branding/GetPnPCustomActionTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetCustomActionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPCustomActionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Identity of the CustomAction to return. Omit to return all CustomActions. + var identity = ""; + // From Cmdlet Help: Scope of the CustomAction, either Web, Site or All to return both + var scopeVar = ""; + // From Cmdlet Help: Switch parameter if an exception should be thrown if the requested CustomAction does not exist (true) or if omitted, nothing will be returned in case the CustomAction does not exist + var throwExceptionIfCustomActionNotFound = ""; + + var results = scope.ExecuteCommand("Get-PnPCustomAction", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar), + new CommandParameter("ThrowExceptionIfCustomActionNotFound", throwExceptionIfCustomActionNotFound)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPFooterTests.cs b/Tests/Branding/GetPnPFooterTests.cs new file mode 100644 index 000000000..f31088c6c --- /dev/null +++ b/Tests/Branding/GetPnPFooterTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GettFooterTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFooterTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPFooter"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPHomePageTests.cs b/Tests/Branding/GetPnPHomePageTests.cs new file mode 100644 index 000000000..0e0b3f67b --- /dev/null +++ b/Tests/Branding/GetPnPHomePageTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetHomePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPHomePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPHomePage"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPJavaScriptLinkTests.cs b/Tests/Branding/GetPnPJavaScriptLinkTests.cs new file mode 100644 index 000000000..38010f50c --- /dev/null +++ b/Tests/Branding/GetPnPJavaScriptLinkTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetJavaScriptLinkTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPJavaScriptLinkTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Name of the Javascript link. Omit this parameter to retrieve all script links + var name = ""; + // From Cmdlet Help: Scope of the action, either Web, Site or All to return both, defaults to Web + var scopeVar = ""; + // From Cmdlet Help: Switch parameter if an exception should be thrown if the requested JavaScriptLink does not exist (true) or if omitted, nothing will be returned in case the JavaScriptLink does not exist + var throwExceptionIfJavaScriptLinkNotFound = ""; + + var results = scope.ExecuteCommand("Get-PnPJavaScriptLink", + new CommandParameter("Name", name), + new CommandParameter("Scope", scopeVar), + new CommandParameter("ThrowExceptionIfJavaScriptLinkNotFound", throwExceptionIfJavaScriptLinkNotFound)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPMasterPageTests.cs b/Tests/Branding/GetPnPMasterPageTests.cs new file mode 100644 index 000000000..9080edf96 --- /dev/null +++ b/Tests/Branding/GetPnPMasterPageTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetMasterPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPMasterPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPMasterPage"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPNavigationNodeTests.cs b/Tests/Branding/GetPnPNavigationNodeTests.cs new file mode 100644 index 000000000..f41089831 --- /dev/null +++ b/Tests/Branding/GetPnPNavigationNodeTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetNavigationNodeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPNavigationNodeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The location of the nodes to retrieve. Either TopNavigationBar, QuickLaunch, SearchNav or Footer. + var location = ""; + // From Cmdlet Help: The Id of the node to retrieve + var id = ""; + // From Cmdlet Help: Show a tree view of all navigation nodes + var tree = ""; + + var results = scope.ExecuteCommand("Get-PnPNavigationNode", + new CommandParameter("Location", location), + new CommandParameter("Id", id), + new CommandParameter("Tree", tree)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/GetPnPThemeTests.cs b/Tests/Branding/GetPnPThemeTests.cs new file mode 100644 index 000000000..fc13bcd23 --- /dev/null +++ b/Tests/Branding/GetPnPThemeTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class GetThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specify this switch to not use the PnP Provisioning engine based composed look information but try to detect the current composed look as is. + var detectCurrentComposedLook = ""; + + var results = scope.ExecuteCommand("Get-PnPTheme", + new CommandParameter("DetectCurrentComposedLook", detectCurrentComposedLook)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/RemovePnPApplicationCustomizerTests.cs b/Tests/Branding/RemovePnPApplicationCustomizerTests.cs new file mode 100644 index 000000000..3fc8b1cff --- /dev/null +++ b/Tests/Branding/RemovePnPApplicationCustomizerTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class RemoveApplicationCustomizerTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPApplicationCustomizerTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The id or name of the CustomAction representing the client side extension registration that needs to be removed or a CustomAction instance itself + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client Side Component Id of the SharePoint Framework client side extension application customizer found in the manifest for which existing custom action(s) should be removed + var clientSideComponentId = ""; + // From Cmdlet Help: Define if the CustomAction representing the client side extension registration is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection (default). + var scopeVar = ""; + // From Cmdlet Help: Use the -Force flag to bypass the confirmation question + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPApplicationCustomizer", + new CommandParameter("Identity", identity), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/RemovePnPCustomActionTests.cs b/Tests/Branding/RemovePnPCustomActionTests.cs new file mode 100644 index 000000000..e14f0afef --- /dev/null +++ b/Tests/Branding/RemovePnPCustomActionTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class RemoveCustomActionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPCustomActionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The id or name of the CustomAction that needs to be removed or a CustomAction instance itself + var identity = ""; + // From Cmdlet Help: Define if the CustomAction is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection. + var scopeVar = ""; + // From Cmdlet Help: Use the -Force flag to bypass the confirmation question + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPCustomAction", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/RemovePnPJavaScriptLinkTests.cs b/Tests/Branding/RemovePnPJavaScriptLinkTests.cs new file mode 100644 index 000000000..15fe3259d --- /dev/null +++ b/Tests/Branding/RemovePnPJavaScriptLinkTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class RemoveJavaScriptLinkTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPJavaScriptLinkTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Name or id of the JavaScriptLink to remove. Omit if you want to remove all JavaScript Links. + var identity = ""; + var fromSite = ""; + // From Cmdlet Help: Use the -Force flag to bypass the confirmation question + var force = ""; + // From Cmdlet Help: Define if the JavaScriptLink is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Remove-PnPJavaScriptLink", + new CommandParameter("Identity", identity), + new CommandParameter("FromSite", fromSite), + new CommandParameter("Force", force), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/RemovePnPNavigationNodeTests.cs b/Tests/Branding/RemovePnPNavigationNodeTests.cs new file mode 100644 index 000000000..1dff956f1 --- /dev/null +++ b/Tests/Branding/RemovePnPNavigationNodeTests.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class RemoveNavigationNodeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPNavigationNodeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Id or node object to delete + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The location from where to remove the node. Either TopNavigationBar, QuickLaunch, SearchNav or Footer. + var location = ""; + // This is a mandatory parameter + // From Cmdlet Help: The title of the node that needs to be removed + var title = ""; + // From Cmdlet Help: The header where the node is located + var header = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifying the All parameter will remove all the nodes from specified Location. + var all = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPNavigationNode", + new CommandParameter("Identity", identity), + new CommandParameter("Location", location), + new CommandParameter("Title", title), + new CommandParameter("Header", header), + new CommandParameter("All", all), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPApplicationCustomizerTests.cs b/Tests/Branding/SetPnPApplicationCustomizerTests.cs new file mode 100644 index 000000000..12eb85ca9 --- /dev/null +++ b/Tests/Branding/SetPnPApplicationCustomizerTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetApplicationCustomizerTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPApplicationCustomizerTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The id or name of the CustomAction representing the client side extension registration that needs to be updated or a CustomAction instance itself + var identity = ""; + // From Cmdlet Help: The Client Side Component Id of the SharePoint Framework client side extension application customizer found in the manifest for which existing custom action(s) should be updated + var clientSideComponentId = ""; + // From Cmdlet Help: Define if the CustomAction representing the client side extension registration is to be found at the web or site collection scope. Specify All to update the component on both web and site collection level. + var scopeVar = ""; + // From Cmdlet Help: The title of the application customizer. Omit to not update this property. + var title = ""; + // From Cmdlet Help: The description of the application customizer. Omit to not update this property. + var description = ""; + // From Cmdlet Help: Sequence of this application customizer being injected. Use when you have a specific sequence with which to have multiple application customizers being added to the page. Omit to not update this property. + var sequence = ""; + // From Cmdlet Help: The Client Side Component Properties of the application customizer to update. Specify values as a json string : "{Property1 : 'Value1', Property2: 'Value2'}". Omit to not update this property. + var clientSideComponentProperties = ""; + + var results = scope.ExecuteCommand("Set-PnPApplicationCustomizer", + new CommandParameter("Identity", identity), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Sequence", sequence), + new CommandParameter("ClientSideComponentProperties", clientSideComponentProperties)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPFooterTests.cs b/Tests/Branding/SetPnPFooterTests.cs new file mode 100644 index 000000000..2a1493a69 --- /dev/null +++ b/Tests/Branding/SetPnPFooterTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetFooterTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPFooterTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Indicates if the footer should be shown on the current web ($true) or if it should be hidden ($false) + var enabled = ""; + // From Cmdlet Help: Defines how the footer should look like + var layoutVar = ""; + // From Cmdlet Help: Defines the background emphasis of the content in the footer + var backgroundTheme = ""; + // From Cmdlet Help: Defines the title displayed in the footer + var title = ""; + // From Cmdlet Help: Defines the server relative URL to the logo to be displayed in the footer. Provide an empty string to remove the current logo. + var logoUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPFooter", + new CommandParameter("Enabled", enabled), + new CommandParameter("Layout", layoutVar), + new CommandParameter("BackgroundTheme", backgroundTheme), + new CommandParameter("Title", title), + new CommandParameter("LogoUrl", logoUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPHomePageTests.cs b/Tests/Branding/SetPnPHomePageTests.cs new file mode 100644 index 000000000..898567059 --- /dev/null +++ b/Tests/Branding/SetPnPHomePageTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetHomePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPHomePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The root folder relative url of the homepage, e.g. 'sitepages/home.aspx' + var rootFolderRelativeUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPHomePage", + new CommandParameter("RootFolderRelativeUrl", rootFolderRelativeUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPMasterPageTests.cs b/Tests/Branding/SetPnPMasterPageTests.cs new file mode 100644 index 000000000..6af0052ec --- /dev/null +++ b/Tests/Branding/SetPnPMasterPageTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetMasterPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPMasterPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the Master page URL based on the server relative URL + var masterPageServerRelativeUrl = ""; + // From Cmdlet Help: Specifies the custom Master page URL based on the server relative URL + var customMasterPageServerRelativeUrl = ""; + // From Cmdlet Help: Specifies the Master page URL based on the site relative URL + var masterPageSiteRelativeUrl = ""; + // From Cmdlet Help: Specifies the custom Master page URL based on the site relative URL + var customMasterPageSiteRelativeUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPMasterPage", + new CommandParameter("MasterPageServerRelativeUrl", masterPageServerRelativeUrl), + new CommandParameter("CustomMasterPageServerRelativeUrl", customMasterPageServerRelativeUrl), + new CommandParameter("MasterPageSiteRelativeUrl", masterPageSiteRelativeUrl), + new CommandParameter("CustomMasterPageSiteRelativeUrl", customMasterPageSiteRelativeUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPMinimalDownloadStrategyTests.cs b/Tests/Branding/SetPnPMinimalDownloadStrategyTests.cs new file mode 100644 index 000000000..6aa0c8479 --- /dev/null +++ b/Tests/Branding/SetPnPMinimalDownloadStrategyTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetMinimalDownloadStrategyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPMinimalDownloadStrategyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Turn minimal download strategy on + var on = ""; + // This is a mandatory parameter + // From Cmdlet Help: Turn minimal download strategy off + var off = ""; + // From Cmdlet Help: Specifies whether to overwrite (when activating) or continue (when deactivating) an existing feature with the same feature identifier. This parameter is ignored if there are no errors. + var force = ""; + + var results = scope.ExecuteCommand("Set-PnPMinimalDownloadStrategy", + new CommandParameter("On", on), + new CommandParameter("Off", off), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPThemeTests.cs b/Tests/Branding/SetPnPThemeTests.cs new file mode 100644 index 000000000..91e8e68d3 --- /dev/null +++ b/Tests/Branding/SetPnPThemeTests.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the Color Palette Url based on the site or server relative url + var colorPaletteUrl = ""; + // From Cmdlet Help: Specifies the Font Scheme Url based on the site or server relative url + var fontSchemeUrl = ""; + // From Cmdlet Help: Specifies the Background Image Url based on the site or server relative url + var backgroundImageUrl = ""; + // From Cmdlet Help: true if the generated theme files should be placed in the root web, false to store them in this web. Default is false + var shareGenerated = ""; + // From Cmdlet Help: Resets subwebs to inherit the theme from the rootweb + var resetSubwebsToInherit = ""; + // From Cmdlet Help: Updates only the rootweb, even if subwebs are set to inherit the theme. + var updateRootWebOnly = ""; + + var results = scope.ExecuteCommand("Set-PnPTheme", + new CommandParameter("ColorPaletteUrl", colorPaletteUrl), + new CommandParameter("FontSchemeUrl", fontSchemeUrl), + new CommandParameter("BackgroundImageUrl", backgroundImageUrl), + new CommandParameter("ShareGenerated", shareGenerated), + new CommandParameter("ResetSubwebsToInherit", resetSubwebsToInherit), + new CommandParameter("UpdateRootWebOnly", updateRootWebOnly)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Branding/SetPnPWebThemeTests.cs b/Tests/Branding/SetPnPWebThemeTests.cs new file mode 100644 index 000000000..17012bfca --- /dev/null +++ b/Tests/Branding/SetPnPWebThemeTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Branding +{ + [TestClass] + public class SetWebThemeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPWebThemeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Specifies the Color Palette Url based on the site or server relative url + var theme = ""; + // From Cmdlet Help: The URL of the web to apply the theme to. If not specified it will default to the current web based upon the URL specified with Connect-PnPOnline. + var webUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPWebTheme", + new CommandParameter("Theme", theme), + new CommandParameter("WebUrl", webUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/AddPnPClientSidePageSectionTests.cs b/Tests/ClientSidePages/AddPnPClientSidePageSectionTests.cs new file mode 100644 index 000000000..f1bbd3de8 --- /dev/null +++ b/Tests/ClientSidePages/AddPnPClientSidePageSectionTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class AddClientSidePageSectionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPClientSidePageSectionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the columns template to use for the section. + var sectionTemplate = ""; + // From Cmdlet Help: Sets the order of the section. (Default = 1) + var order = ""; + // From Cmdlet Help: Sets the background of the section (default = 0) + var zoneEmphasis = ""; + + var results = scope.ExecuteCommand("Add-PnPClientSidePageSection", + new CommandParameter("Page", page), + new CommandParameter("SectionTemplate", sectionTemplate), + new CommandParameter("Order", order), + new CommandParameter("ZoneEmphasis", zoneEmphasis)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/AddPnPClientSidePageTests.cs b/Tests/ClientSidePages/AddPnPClientSidePageTests.cs new file mode 100644 index 000000000..1c47f3a68 --- /dev/null +++ b/Tests/ClientSidePages/AddPnPClientSidePageTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class AddClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the name of the page. + var name = ""; + // From Cmdlet Help: Specifies the layout type of the page. + var layoutVarType = ""; + // From Cmdlet Help: Allows to promote the page for a specific purpose (HomePage | NewsPage) + var promoteAs = ""; + // From Cmdlet Help: Specify either the name, ID or an actual content type. + var contentType = ""; + // From Cmdlet Help: Enables or Disables the comments on the page + var commentsEnabled = ""; + // From Cmdlet Help: Publishes the page once it is saved. Applicable to libraries set to create major and minor versions. + var publish = ""; + // From Cmdlet Help: Type of layout used for the header + var headerLayoutVarType = ""; + // From Cmdlet Help: Sets the message for publishing the page. + var publishMessage = ""; + + var results = scope.ExecuteCommand("Add-PnPClientSidePage", + new CommandParameter("Name", name), + new CommandParameter("LayoutType", layoutVarType), + new CommandParameter("PromoteAs", promoteAs), + new CommandParameter("ContentType", contentType), + new CommandParameter("CommentsEnabled", commentsEnabled), + new CommandParameter("Publish", publish), + new CommandParameter("HeaderLayoutType", headerLayoutVarType), + new CommandParameter("PublishMessage", publishMessage)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/AddPnPClientSideTextTests.cs b/Tests/ClientSidePages/AddPnPClientSideTextTests.cs new file mode 100644 index 000000000..a2c0fb79f --- /dev/null +++ b/Tests/ClientSidePages/AddPnPClientSideTextTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class AddClientSideTextTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPClientSideTextTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page. + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the text to display in the text area. + var text = ""; + // From Cmdlet Help: Sets the order of the text control. (Default = 1) + var order = ""; + // This is a mandatory parameter + // From Cmdlet Help: Sets the section where to insert the text control. + var section = ""; + // This is a mandatory parameter + // From Cmdlet Help: Sets the column where to insert the text control. + var column = ""; + + var results = scope.ExecuteCommand("Add-PnPClientSideText", + new CommandParameter("Page", page), + new CommandParameter("Text", text), + new CommandParameter("Order", order), + new CommandParameter("Section", section), + new CommandParameter("Column", column)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/ConvertToPnPClientSidePageTests.cs b/Tests/ClientSidePages/ConvertToPnPClientSidePageTests.cs new file mode 100644 index 000000000..08e5d0189 --- /dev/null +++ b/Tests/ClientSidePages/ConvertToPnPClientSidePageTests.cs @@ -0,0 +1,204 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class ConvertToClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ConvertToPnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page to convert + var identity = ""; + // From Cmdlet Help: The name of the library containing the page. If SitePages then please omit this parameter + var library = ""; + // From Cmdlet Help: The folder to load the provided page from. If not provided all folders are searched + var folder = ""; + // From Cmdlet Help: Path and name of the web part mapping file driving the transformation + var webPartMappingFile = ""; + // From Cmdlet Help: Overwrites page if already existing + var overwrite = ""; + // From Cmdlet Help: Created client side page takes name from previous classic page. Classic page gets renamed to previous_.aspx + var takeSourcePageName = ""; + // From Cmdlet Help: Replaces a home page with a default stock modern home page + var replaceHomePageWithDefault = ""; + // From Cmdlet Help: Adds the page accept banner web part. The actual web part is specified in webpartmapping.xml file + var addPageAcceptBanner = ""; + // From Cmdlet Help: By default the item level permissions on a page are copied to the created client side page. Use this switch to prevent the copy + var skipItemLevelPermissionCopyToClientSidePage = ""; + // From Cmdlet Help: If transforming cross site then by default urls in html and summarylinks are rewritten for the target site. Set this flag to prevent that + var skipUrlRewriting = ""; + // From Cmdlet Help: Set this flag to prevent the default URL rewriting while you still want to do URL rewriting using a custom URL mapping file + var skipDefaultUrlRewriting = ""; + // From Cmdlet Help: File holding custom URL mapping definitions + var urlMappingFile = ""; + // From Cmdlet Help: Clears the cache. Can be needed if you've installed a new web part to the site and want to use that in a custom webpartmapping file. Restarting your PS session has the same effect + var clearCache = ""; + // From Cmdlet Help: Copies the page metadata to the created modern page + var copyPageMetadata = ""; + // From Cmdlet Help: When an image lives inside a table/list then it's also created as separate image web part underneath that table/list by default. Use this switch set to $false to change that + var addTableListImageAsImageWebPart = ""; + // From Cmdlet Help: Uses the community script editor (https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-script-editor) as replacement for the classic script editor web part + var useCommunityScriptEditor = ""; + // From Cmdlet Help: By default summarylinks web parts are replaced by QuickLinks, but you can transform to plain html by setting this switch + var summaryLinksToHtml = ""; + // From Cmdlet Help: Url of the target web that will receive the modern page. Defaults to null which means in-place transformation + var targetWebUrl = ""; + // From Cmdlet Help: Allows to generate a transformation log (File | SharePoint) + var logType = ""; + // From Cmdlet Help: Folder in where the log file will be created (if LogType==File) + var logFolder = ""; + // From Cmdlet Help: By default each cmdlet invocation will result in a log file, use the -SkipLogFlush to delay the log flushing. The first call without -SkipLogFlush will then write all log entries to a single log + var logSkipFlush = ""; + // From Cmdlet Help: Configure logging to include verbose log entries + var logVerbose = ""; + // From Cmdlet Help: Don't publish the created modern page + var dontPublish = ""; + // From Cmdlet Help: Keep the author, editor, created and modified information from the source page (when source page lives in SPO) + var keepPageCreationModificationInformation = ""; + // From Cmdlet Help: Set's the author of the source page as author in the modern page header (when source page lives in SPO) + var setAuthorInPageHeader = ""; + // From Cmdlet Help: Post the created, and published, modern page as news + var postAsNews = ""; + // From Cmdlet Help: Disable comments for the created modern page + var disablePageComments = ""; + // From Cmdlet Help: I'm transforming a publishing page + var publishingPage = ""; + // From Cmdlet Help: I'm transforming a blog page + var blogPage = ""; + // From Cmdlet Help: I'm transforming a Delve blog page + var delveBlogPage = ""; + // From Cmdlet Help: Transform the possible sub title as topic header on the modern page + var delveKeepSubTitle = ""; + // From Cmdlet Help: Path and name of the page layout mapping file driving the publishing page transformation + var pageLayoutVarMapping = ""; + // From Cmdlet Help: Name for the target page (only applies to publishing page transformation) + var publishingTargetPageName = ""; + // From Cmdlet Help: Name for the target page (only applies when doing cross site page transformation) + var targetPageName = ""; + // From Cmdlet Help: Folder to create the target page in (will be used in conjunction with auto-generated folders that ensure page name uniqueness) + var targetPageFolder = ""; + // From Cmdlet Help: When setting a target page folder then the target page folder overrides possibly default folder path (e.g. in the source page lived in a folder) instead of being appended to it + var targetPageFolderOverridesDefaultFolder = ""; + // From Cmdlet Help: Remove empty sections and columns after transformation of the page + var removeEmptySectionsAndColumns = ""; + // From Cmdlet Help: Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + var targetConnection = ""; + // From Cmdlet Help: Disables user mapping during transformation + var skipUserMapping = ""; + // From Cmdlet Help: Specifies a user mapping file + var userMappingFile = ""; + // From Cmdlet Help: Specifies a taxonomy term mapping file + var termMappingFile = ""; + // From Cmdlet Help: Disables term mapping during transformation + var skipTermStoreMapping = ""; + // From Cmdlet Help: Specifies a LDAP connection string e.g. LDAP://OU=Users,DC=Contoso,DC=local + var lDAPConnectionString = ""; + + var results = scope.ExecuteCommand("ConvertTo-PnPClientSidePage", + new CommandParameter("Identity", identity), + new CommandParameter("Library", library), + new CommandParameter("Folder", folder), + new CommandParameter("WebPartMappingFile", webPartMappingFile), + new CommandParameter("Overwrite", overwrite), + new CommandParameter("TakeSourcePageName", takeSourcePageName), + new CommandParameter("ReplaceHomePageWithDefault", replaceHomePageWithDefault), + new CommandParameter("AddPageAcceptBanner", addPageAcceptBanner), + new CommandParameter("SkipItemLevelPermissionCopyToClientSidePage", skipItemLevelPermissionCopyToClientSidePage), + new CommandParameter("SkipUrlRewriting", skipUrlRewriting), + new CommandParameter("SkipDefaultUrlRewriting", skipDefaultUrlRewriting), + new CommandParameter("UrlMappingFile", urlMappingFile), + new CommandParameter("ClearCache", clearCache), + new CommandParameter("CopyPageMetadata", copyPageMetadata), + new CommandParameter("AddTableListImageAsImageWebPart", addTableListImageAsImageWebPart), + new CommandParameter("UseCommunityScriptEditor", useCommunityScriptEditor), + new CommandParameter("SummaryLinksToHtml", summaryLinksToHtml), + new CommandParameter("TargetWebUrl", targetWebUrl), + new CommandParameter("LogType", logType), + new CommandParameter("LogFolder", logFolder), + new CommandParameter("LogSkipFlush", logSkipFlush), + new CommandParameter("LogVerbose", logVerbose), + new CommandParameter("DontPublish", dontPublish), + new CommandParameter("KeepPageCreationModificationInformation", keepPageCreationModificationInformation), + new CommandParameter("SetAuthorInPageHeader", setAuthorInPageHeader), + new CommandParameter("PostAsNews", postAsNews), + new CommandParameter("DisablePageComments", disablePageComments), + new CommandParameter("PublishingPage", publishingPage), + new CommandParameter("BlogPage", blogPage), + new CommandParameter("DelveBlogPage", delveBlogPage), + new CommandParameter("DelveKeepSubTitle", delveKeepSubTitle), + new CommandParameter("PageLayoutMapping", pageLayoutVarMapping), + new CommandParameter("PublishingTargetPageName", publishingTargetPageName), + new CommandParameter("TargetPageName", targetPageName), + new CommandParameter("TargetPageFolder", targetPageFolder), + new CommandParameter("TargetPageFolderOverridesDefaultFolder", targetPageFolderOverridesDefaultFolder), + new CommandParameter("RemoveEmptySectionsAndColumns", removeEmptySectionsAndColumns), + new CommandParameter("TargetConnection", targetConnection), + new CommandParameter("SkipUserMapping", skipUserMapping), + new CommandParameter("UserMappingFile", userMappingFile), + new CommandParameter("TermMappingFile", termMappingFile), + new CommandParameter("SkipTermStoreMapping", skipTermStoreMapping), + new CommandParameter("LDAPConnectionString", lDAPConnectionString)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/ExportPnPClientSidePageMappingTests.cs b/Tests/ClientSidePages/ExportPnPClientSidePageMappingTests.cs new file mode 100644 index 000000000..b8940dfa2 --- /dev/null +++ b/Tests/ClientSidePages/ExportPnPClientSidePageMappingTests.cs @@ -0,0 +1,98 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class ExportClientSidePageMappingTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ExportPnPClientSidePageMappingTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Exports the builtin web part mapping file + var builtInWebPartMapping = ""; + // From Cmdlet Help: Exports the builtin pagelayout mapping file (only needed for publishing page transformation) + var builtInPageLayoutVarMapping = ""; + // From Cmdlet Help: Analyzes the pagelayouts in the current publishing portal and exports them as a pagelayout mapping file + var customPageLayoutVarMapping = ""; + // From Cmdlet Help: The name of the publishing page to export a page layout mapping file for + var publishingPage = ""; + // From Cmdlet Help: Set this flag if you also want to analyze the OOB page layouts...typically these are covered via the default mapping, but if you've updated these page layouts you might want to analyze them again + var analyzeOOBPageLayoutVars = ""; + // From Cmdlet Help: The folder to created the mapping file(s) in + var folder = ""; + // From Cmdlet Help: Overwrites existing mapping files + var overwrite = ""; + // From Cmdlet Help: Outputs analyser logging to the console + var logging = ""; + + var results = scope.ExecuteCommand("Export-PnPClientSidePageMapping", + new CommandParameter("BuiltInWebPartMapping", builtInWebPartMapping), + new CommandParameter("BuiltInPageLayoutMapping", builtInPageLayoutVarMapping), + new CommandParameter("CustomPageLayoutMapping", customPageLayoutVarMapping), + new CommandParameter("PublishingPage", publishingPage), + new CommandParameter("AnalyzeOOBPageLayouts", analyzeOOBPageLayoutVars), + new CommandParameter("Folder", folder), + new CommandParameter("Overwrite", overwrite), + new CommandParameter("Logging", logging)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/GetPnPAvailableClientSideComponentsTests.cs b/Tests/ClientSidePages/GetPnPAvailableClientSideComponentsTests.cs new file mode 100644 index 000000000..86b76c6d4 --- /dev/null +++ b/Tests/ClientSidePages/GetPnPAvailableClientSideComponentsTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class GetAvailableClientSideComponentsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAvailableClientSideComponentsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page. + var page = ""; + // From Cmdlet Help: Specifies the component instance or Id to look for. + var component = ""; + + var results = scope.ExecuteCommand("Get-PnPAvailableClientSideComponents", + new CommandParameter("Page", page), + new CommandParameter("Component", component)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/GetPnPClientSideComponentTests.cs b/Tests/ClientSidePages/GetPnPClientSideComponentTests.cs new file mode 100644 index 000000000..7bf2903f7 --- /dev/null +++ b/Tests/ClientSidePages/GetPnPClientSideComponentTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class GetClientSideControlTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPClientSideComponentTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // From Cmdlet Help: The instance id of the component + var instanceId = ""; + + var results = scope.ExecuteCommand("Get-PnPClientSideComponent", + new CommandParameter("Page", page), + new CommandParameter("InstanceId", instanceId)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/GetPnPClientSidePageTests.cs b/Tests/ClientSidePages/GetPnPClientSidePageTests.cs new file mode 100644 index 000000000..acb6af13c --- /dev/null +++ b/Tests/ClientSidePages/GetPnPClientSidePageTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class GetClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPClientSidePage", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/MovePnPClientSideComponentTests.cs b/Tests/ClientSidePages/MovePnPClientSideComponentTests.cs new file mode 100644 index 000000000..ce160e252 --- /dev/null +++ b/Tests/ClientSidePages/MovePnPClientSideComponentTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class MoveClientSideWebPartTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MovePnPClientSideComponentTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: The instance id of the control. Use Get-PnPClientSideControl retrieve the instance ids. + var instanceId = ""; + // This is a mandatory parameter + // From Cmdlet Help: The section to move the web part to + var section = ""; + // This is a mandatory parameter + // From Cmdlet Help: The column to move the web part to + var column = ""; + // From Cmdlet Help: Change to order of the web part in the column + var position = ""; + + var results = scope.ExecuteCommand("Move-PnPClientSideComponent", + new CommandParameter("Page", page), + new CommandParameter("InstanceId", instanceId), + new CommandParameter("Section", section), + new CommandParameter("Column", column), + new CommandParameter("Position", position)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/RemovePnPClientSideComponentTests.cs b/Tests/ClientSidePages/RemovePnPClientSideComponentTests.cs new file mode 100644 index 000000000..d18c6cfd8 --- /dev/null +++ b/Tests/ClientSidePages/RemovePnPClientSideComponentTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class RemoveClientSideComponentTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPClientSideComponentTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: The instance id of the component + var instanceId = ""; + // From Cmdlet Help: If specified you will not receive the confirmation question + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPClientSideComponent", + new CommandParameter("Page", page), + new CommandParameter("InstanceId", instanceId), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/RemovePnPClientSidePageTests.cs b/Tests/ClientSidePages/RemovePnPClientSidePageTests.cs new file mode 100644 index 000000000..3785b8605 --- /dev/null +++ b/Tests/ClientSidePages/RemovePnPClientSidePageTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class RemoveClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPClientSidePage", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/SavePnPClientSidePageConversionLogTests.cs b/Tests/ClientSidePages/SavePnPClientSidePageConversionLogTests.cs new file mode 100644 index 000000000..601bd291f --- /dev/null +++ b/Tests/ClientSidePages/SavePnPClientSidePageConversionLogTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class SaveClientSidePageConversionLogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SavePnPClientSidePageConversionLogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Save-PnPClientSidePageConversionLog"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/SetPnPClientSidePageTests.cs b/Tests/ClientSidePages/SetPnPClientSidePageTests.cs new file mode 100644 index 000000000..07007dc89 --- /dev/null +++ b/Tests/ClientSidePages/SetPnPClientSidePageTests.cs @@ -0,0 +1,108 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class SetClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name/identity of the page + var identity = ""; + // From Cmdlet Help: Sets the name of the page. + var name = ""; + // From Cmdlet Help: Sets the title of the page. + var title = ""; + // From Cmdlet Help: Sets the layout type of the page. (Default = Article) + var layoutVarType = ""; + // From Cmdlet Help: Allows to promote the page for a specific purpose (None | HomePage | NewsArticle | Template) + var promoteAs = ""; + // From Cmdlet Help: Enables or Disables the comments on the page + var commentsEnabled = ""; + // From Cmdlet Help: Publishes the page once it is saved. + var publish = ""; + // From Cmdlet Help: Sets the page header type + var headerType = ""; + // From Cmdlet Help: Specify either the name, ID or an actual content type. + var contentType = ""; + // From Cmdlet Help: Thumbnail Url + var thumbnailUrl = ""; + // From Cmdlet Help: Sets the message for publishing the page. + var publishMessage = ""; + + var results = scope.ExecuteCommand("Set-PnPClientSidePage", + new CommandParameter("Identity", identity), + new CommandParameter("Name", name), + new CommandParameter("Title", title), + new CommandParameter("LayoutType", layoutVarType), + new CommandParameter("PromoteAs", promoteAs), + new CommandParameter("CommentsEnabled", commentsEnabled), + new CommandParameter("Publish", publish), + new CommandParameter("HeaderType", headerType), + new CommandParameter("ContentType", contentType), + new CommandParameter("ThumbnailUrl", thumbnailUrl), + new CommandParameter("PublishMessage", publishMessage)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/SetPnPClientSideTextTests.cs b/Tests/ClientSidePages/SetPnPClientSideTextTests.cs new file mode 100644 index 000000000..4cf532f55 --- /dev/null +++ b/Tests/ClientSidePages/SetPnPClientSideTextTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class SetClientSideTextTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPClientSideTextTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: The instance id of the text component + var instanceId = ""; + // This is a mandatory parameter + // From Cmdlet Help: Text to set + var text = ""; + + var results = scope.ExecuteCommand("Set-PnPClientSideText", + new CommandParameter("Page", page), + new CommandParameter("InstanceId", instanceId), + new CommandParameter("Text", text)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ClientSidePages/SetPnPClientSideWebPartTests.cs b/Tests/ClientSidePages/SetPnPClientSideWebPartTests.cs new file mode 100644 index 000000000..5a49210d6 --- /dev/null +++ b/Tests/ClientSidePages/SetPnPClientSideWebPartTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ClientSidePages +{ + [TestClass] + public class SetClientSideWebPartTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPClientSideWebPartTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var page = ""; + // This is a mandatory parameter + // From Cmdlet Help: The identity of the web part. This can be the web part instance id or the title of a web part + var identity = ""; + // From Cmdlet Help: Sets the internal title of the web part. Notice that this will NOT set a visible title. + var title = ""; + // From Cmdlet Help: Sets the properties as a JSON string. + var propertiesJson = ""; + + var results = scope.ExecuteCommand("Set-PnPClientSideWebPart", + new CommandParameter("Page", page), + new CommandParameter("Identity", identity), + new CommandParameter("Title", title), + new CommandParameter("PropertiesJson", propertiesJson)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/AddPnPContentTypeTests.cs b/Tests/ContentTypes/AddPnPContentTypeTests.cs new file mode 100644 index 000000000..744ccf8b9 --- /dev/null +++ b/Tests/ContentTypes/AddPnPContentTypeTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class AddContentTypeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specify the name of the new content type + var name = ""; + // From Cmdlet Help: If specified, in the format of 0x0100233af432334r434343f32f3, will create a content type with the specific ID + var contentTypeId = ""; + // From Cmdlet Help: Specifies the description of the new content type + var description = ""; + // From Cmdlet Help: Specifies the group of the new content type + var group = ""; + // From Cmdlet Help: Specifies the parent of the new content type + var parentContentType = ""; + + var results = scope.ExecuteCommand("Add-PnPContentType", + new CommandParameter("Name", name), + new CommandParameter("ContentTypeId", contentTypeId), + new CommandParameter("Description", description), + new CommandParameter("Group", group), + new CommandParameter("ParentContentType", parentContentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/AddPnPContentTypeToListTests.cs b/Tests/ContentTypes/AddPnPContentTypeToListTests.cs new file mode 100644 index 000000000..97c92ffc7 --- /dev/null +++ b/Tests/ContentTypes/AddPnPContentTypeToListTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class AddContentTypeToListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPContentTypeToListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the list to which the content type needs to be added + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the content type that needs to be added to the list + var contentType = ""; + // From Cmdlet Help: Specify if the content type needs to be the default content type or not + var defaultContentType = ""; + + var results = scope.ExecuteCommand("Add-PnPContentTypeToList", + new CommandParameter("List", list), + new CommandParameter("ContentType", contentType), + new CommandParameter("DefaultContentType", defaultContentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/AddPnPFieldToContentTypeTests.cs b/Tests/ContentTypes/AddPnPFieldToContentTypeTests.cs new file mode 100644 index 000000000..47c94d0b3 --- /dev/null +++ b/Tests/ContentTypes/AddPnPFieldToContentTypeTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class AddFieldToContentTypeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFieldToContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the field that needs to be added to the content type + var field = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies which content type a field needs to be added to + var contentType = ""; + // From Cmdlet Help: Specifies whether the field is required or not + var required = ""; + // From Cmdlet Help: Specifies whether the field should be hidden or not + var hidden = ""; + + var results = scope.ExecuteCommand("Add-PnPFieldToContentType", + new CommandParameter("Field", field), + new CommandParameter("ContentType", contentType), + new CommandParameter("Required", required), + new CommandParameter("Hidden", hidden)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/GetPnPContentTypePublishingHubUrlTests.cs b/Tests/ContentTypes/GetPnPContentTypePublishingHubUrlTests.cs new file mode 100644 index 000000000..89b772299 --- /dev/null +++ b/Tests/ContentTypes/GetPnPContentTypePublishingHubUrlTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class GetContentTypePublishingHubTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPContentTypePublishingHubUrlTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPContentTypePublishingHubUrl"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/GetPnPContentTypeTests.cs b/Tests/ContentTypes/GetPnPContentTypeTests.cs new file mode 100644 index 000000000..520d33b38 --- /dev/null +++ b/Tests/ContentTypes/GetPnPContentTypeTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class GetContentTypeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Name or ID of the content type to retrieve + var identity = ""; + // From Cmdlet Help: List to query + var list = ""; + // From Cmdlet Help: Search site hierarchy for content types + var inSiteHierarchy = ""; + + var results = scope.ExecuteCommand("Get-PnPContentType", + new CommandParameter("Identity", identity), + new CommandParameter("List", list), + new CommandParameter("InSiteHierarchy", inSiteHierarchy)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/RemovePnPContentTypeFromListTests.cs b/Tests/ContentTypes/RemovePnPContentTypeFromListTests.cs new file mode 100644 index 000000000..ab53945ce --- /dev/null +++ b/Tests/ContentTypes/RemovePnPContentTypeFromListTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class RemoveContentTypeFromListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPContentTypeFromListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the list, its ID or an actual list object from where the content type needs to be removed from + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of a content type, its ID or an actual content type object that needs to be removed from the specified list. + var contentType = ""; + + var results = scope.ExecuteCommand("Remove-PnPContentTypeFromList", + new CommandParameter("List", list), + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/RemovePnPContentTypeTests.cs b/Tests/ContentTypes/RemovePnPContentTypeTests.cs new file mode 100644 index 000000000..4f2605e35 --- /dev/null +++ b/Tests/ContentTypes/RemovePnPContentTypeTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class RemoveContentTypeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name or ID of the content type to remove + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPContentType", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/RemovePnPFieldFromContentTypeTests.cs b/Tests/ContentTypes/RemovePnPFieldFromContentTypeTests.cs new file mode 100644 index 000000000..846ad967e --- /dev/null +++ b/Tests/ContentTypes/RemovePnPFieldFromContentTypeTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class RemoveFieldFromContentTypeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPFieldFromContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The field to remove + var field = ""; + // This is a mandatory parameter + // From Cmdlet Help: The content type where the field is to be removed from + var contentType = ""; + // From Cmdlet Help: If specified, inherited content types will not be updated + var doNotUpdateChildren = ""; + + var results = scope.ExecuteCommand("Remove-PnPFieldFromContentType", + new CommandParameter("Field", field), + new CommandParameter("ContentType", contentType), + new CommandParameter("DoNotUpdateChildren", doNotUpdateChildren)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ContentTypes/SetPnPDefaultContentTypeToListTests.cs b/Tests/ContentTypes/SetPnPDefaultContentTypeToListTests.cs new file mode 100644 index 000000000..ac0bea809 --- /dev/null +++ b/Tests/ContentTypes/SetPnPDefaultContentTypeToListTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class SetDefaultContentTypeToListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPDefaultContentTypeToListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of a list, an ID or the actual list object to update + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The content type object that needs to be set as the default content type on the list. Content Type needs to be present on the list. + var contentType = ""; + + var results = scope.ExecuteCommand("Set-PnPDefaultContentTypeToList", + new CommandParameter("List", list), + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Diagnostic/MeasurePnPListTests.cs b/Tests/Diagnostic/MeasurePnPListTests.cs new file mode 100644 index 000000000..2560f75f4 --- /dev/null +++ b/Tests/Diagnostic/MeasurePnPListTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Diagnostic +{ + [TestClass] + public class MeasurePnPListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MeasurePnPListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var identity = ""; + // From Cmdlet Help: Show item level statistics + var itemLevel = ""; + // From Cmdlet Help: Show items with broken permissions + var brokenPermissions = ""; + + var results = scope.ExecuteCommand("Measure-PnPList", + new CommandParameter("Identity", identity), + new CommandParameter("ItemLevel", itemLevel), + new CommandParameter("BrokenPermissions", brokenPermissions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Diagnostic/MeasurePnPResponseTimeTests.cs b/Tests/Diagnostic/MeasurePnPResponseTimeTests.cs new file mode 100644 index 000000000..059a53df0 --- /dev/null +++ b/Tests/Diagnostic/MeasurePnPResponseTimeTests.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Diagnostic +{ + [TestClass] + public class MeasureResponseTimeTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MeasurePnPResponseTimeTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var url = ""; + // From Cmdlet Help: Number of probe requests to send + var count = ""; + // From Cmdlet Help: Number of warm up requests to send before start calculating statistics + var warmUp = ""; + // From Cmdlet Help: Idle timeout between requests to avoid request throttling + var timeoutVar = ""; + // From Cmdlet Help: Number of buckets in histogram in output statistics + var histogram = ""; + // From Cmdlet Help: Response time measurement mode. RoundTrip - measures full request round trip. SPRequestDuration - measures server processing time only, based on SPRequestDuration HTTP header. Latency - difference between RoundTrip and SPRequestDuration + var mode = ""; + + var results = scope.ExecuteCommand("Measure-PnPResponseTime", + new CommandParameter("Url", url), + new CommandParameter("Count", count), + new CommandParameter("WarmUp", warmUp), + new CommandParameter("Timeout", timeoutVar), + new CommandParameter("Histogram", histogram), + new CommandParameter("Mode", mode)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Diagnostic/MeasurePnPWebTests.cs b/Tests/Diagnostic/MeasurePnPWebTests.cs new file mode 100644 index 000000000..8785a53f9 --- /dev/null +++ b/Tests/Diagnostic/MeasurePnPWebTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Diagnostic +{ + [TestClass] + public class MeasurePnPWebTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MeasurePnPWebTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var identity = ""; + // From Cmdlet Help: Iterate all sub webs recursively + var recursive = ""; + // From Cmdlet Help: Include hidden lists in statistics calculation + var includeHiddenList = ""; + + var results = scope.ExecuteCommand("Measure-PnPWeb", + new CommandParameter("Identity", identity), + new CommandParameter("Recursive", recursive), + new CommandParameter("IncludeHiddenList", includeHiddenList)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/DocumentSets/AddPnPContentTypeToDocumentSetTests.cs b/Tests/DocumentSets/AddPnPContentTypeToDocumentSetTests.cs new file mode 100644 index 000000000..01aa134a4 --- /dev/null +++ b/Tests/DocumentSets/AddPnPContentTypeToDocumentSetTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.DocumentSets +{ + [TestClass] + public class AddContentTypeToDocumentSetTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPContentTypeToDocumentSetTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The content type object, name or id to add. Either specify name, an id, or a content type object. + var contentType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The document set object or id to add the content type to. Either specify a name, a document set template object, an id, or a content type object + var documentSet = ""; + + var results = scope.ExecuteCommand("Add-PnPContentTypeToDocumentSet", + new CommandParameter("ContentType", contentType), + new CommandParameter("DocumentSet", documentSet)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/DocumentSets/AddPnPDocumentSetTests.cs b/Tests/DocumentSets/AddPnPDocumentSetTests.cs new file mode 100644 index 000000000..2d569a991 --- /dev/null +++ b/Tests/DocumentSets/AddPnPDocumentSetTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.DocumentSets +{ + [TestClass] + public class AddDocumentSetTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPDocumentSetTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the list, its ID or an actual list object from where the document set needs to be added + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the document set + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the content type, its ID or an actual content object referencing to the document set + var contentType = ""; + + var results = scope.ExecuteCommand("Add-PnPDocumentSet", + new CommandParameter("List", list), + new CommandParameter("Name", name), + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/DocumentSets/GetPnPDocumentSetTemplateTests.cs b/Tests/DocumentSets/GetPnPDocumentSetTemplateTests.cs new file mode 100644 index 000000000..087fc2b15 --- /dev/null +++ b/Tests/DocumentSets/GetPnPDocumentSetTemplateTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.DocumentSets +{ + [TestClass] + public class GetDocumentSetTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPDocumentSetTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Either specify a name, an id, a document set template object or a content type object + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPDocumentSetTemplate", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/DocumentSets/RemovePnPContentTypeFromDocumentSetTests.cs b/Tests/DocumentSets/RemovePnPContentTypeFromDocumentSetTests.cs new file mode 100644 index 000000000..2f1e38f11 --- /dev/null +++ b/Tests/DocumentSets/RemovePnPContentTypeFromDocumentSetTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.DocumentSets +{ + [TestClass] + public class RemoveContentTypeFromDocumentSetTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPContentTypeFromDocumentSetTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The content type to remove. Either specify name, an id, or a content type object. + var contentType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The document set to remove the content type from. Either specify a name, a document set template object, an id, or a content type object + var documentSet = ""; + + var results = scope.ExecuteCommand("Remove-PnPContentTypeFromDocumentSet", + new CommandParameter("ContentType", contentType), + new CommandParameter("DocumentSet", documentSet)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/DocumentSets/SetPnPDocumentSetFieldTests.cs b/Tests/DocumentSets/SetPnPDocumentSetFieldTests.cs new file mode 100644 index 000000000..dd9dd473f --- /dev/null +++ b/Tests/DocumentSets/SetPnPDocumentSetFieldTests.cs @@ -0,0 +1,94 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.DocumentSets +{ + [TestClass] + public class SetFieldInDocumentSetTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPDocumentSetFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The document set in which to set the field. Either specify a name, a document set template object, an id, or a content type object + var documentSet = ""; + // This is a mandatory parameter + // From Cmdlet Help: The field to set. The field needs to be available in one of the available content types. Either specify a name, an id or a field object + var field = ""; + // From Cmdlet Help: Set the field as a Shared Field + var setSharedField = ""; + // From Cmdlet Help: Set the field as a Welcome Page field + var setWelcomePageField = ""; + // From Cmdlet Help: Removes the field as a Shared Field + var removeSharedField = ""; + // From Cmdlet Help: Removes the field as a Welcome Page Field + var removeWelcomePageField = ""; + + var results = scope.ExecuteCommand("Set-PnPDocumentSetField", + new CommandParameter("DocumentSet", documentSet), + new CommandParameter("Field", field), + new CommandParameter("SetSharedField", setSharedField), + new CommandParameter("SetWelcomePageField", setWelcomePageField), + new CommandParameter("RemoveSharedField", removeSharedField), + new CommandParameter("RemoveWelcomePageField", removeWelcomePageField)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Events/AddPnPEventReceiverTests.cs b/Tests/Events/AddPnPEventReceiverTests.cs new file mode 100644 index 000000000..b8f4dc7d3 --- /dev/null +++ b/Tests/Events/AddPnPEventReceiverTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Events +{ + [TestClass] + public class AddEventReceiverTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPEventReceiverTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The list object or name where the remote event receiver needs to be added. If omitted, the remote event receiver will be added to the web. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the remote event receiver + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The URL of the remote event receiver web service + var url = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of the event receiver like ItemAdded, ItemAdding. See https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.eventreceivertype.aspx for the full list of available types. + var eventReceiverType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The synchronization type: Asynchronous or Synchronous + var synchronization = ""; + // From Cmdlet Help: The sequence number where this remote event receiver should be placed + var sequenceNumber = ""; + // From Cmdlet Help: Overwrites the output file if it exists. + var force = ""; + + var results = scope.ExecuteCommand("Add-PnPEventReceiver", + new CommandParameter("List", list), + new CommandParameter("Name", name), + new CommandParameter("Url", url), + new CommandParameter("EventReceiverType", eventReceiverType), + new CommandParameter("Synchronization", synchronization), + new CommandParameter("SequenceNumber", sequenceNumber), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Events/GetPnPEventReceiverTests.cs b/Tests/Events/GetPnPEventReceiverTests.cs new file mode 100644 index 000000000..95978c25c --- /dev/null +++ b/Tests/Events/GetPnPEventReceiverTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Events +{ + [TestClass] + public class GetEventReceiverTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPEventReceiverTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The list object from which to get the event receiver object + var list = ""; + // From Cmdlet Help: The Guid of the event receiver + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPEventReceiver", + new CommandParameter("List", list), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Events/RemovePnPEventReceiverTests.cs b/Tests/Events/RemovePnPEventReceiverTests.cs new file mode 100644 index 000000000..cfaf29dc0 --- /dev/null +++ b/Tests/Events/RemovePnPEventReceiverTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Events +{ + [TestClass] + public class RemoveEventReceiverTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPEventReceiverTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Guid of the event receiver on the list + var identity = ""; + // From Cmdlet Help: The list object from where to remove the event receiver object + var list = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPEventReceiver", + new CommandParameter("Identity", identity), + new CommandParameter("List", list), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Extensibility/NewPnPExtensibilityHandlerObjectTests.cs b/Tests/Extensibility/NewPnPExtensibilityHandlerObjectTests.cs new file mode 100644 index 000000000..2e89f1f79 --- /dev/null +++ b/Tests/Extensibility/NewPnPExtensibilityHandlerObjectTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Extensibility +{ + [TestClass] + public class NewExtensibilityHandlerObjectTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPExtensibilityHandlerObjectTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The full assembly name of the handler + var assembly = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of the handler + var type = ""; + // From Cmdlet Help: Any configuration data you want to send to the handler + var configuration = ""; + // From Cmdlet Help: If set, the handler will be disabled + var disabled = ""; + + var results = scope.ExecuteCommand("New-PnPExtensibilityHandlerObject", + new CommandParameter("Assembly", assembly), + new CommandParameter("Type", type), + new CommandParameter("Configuration", configuration), + new CommandParameter("Disabled", disabled)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Features/DisablePnPFeatureTests.cs b/Tests/Features/DisablePnPFeatureTests.cs new file mode 100644 index 000000000..aa9a6ad3a --- /dev/null +++ b/Tests/Features/DisablePnPFeatureTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Features +{ + [TestClass] + public class DisableFeatureTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPFeatureTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The id of the feature to disable. + var identity = ""; + // From Cmdlet Help: Specifies whether to continue if an error occurs when deactivating the feature. + var force = ""; + // From Cmdlet Help: Specify the scope of the feature to deactivate, either Web or Site. Defaults to Web. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Disable-PnPFeature", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Features/EnablePnPFeatureTests.cs b/Tests/Features/EnablePnPFeatureTests.cs new file mode 100644 index 000000000..b22df9a54 --- /dev/null +++ b/Tests/Features/EnablePnPFeatureTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Features +{ + [TestClass] + public class EnableFeatureTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPFeatureTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The id of the feature to enable. + var identity = ""; + // From Cmdlet Help: Specifies whether to overwrite an existing feature with the same feature identifier. This parameter is ignored if there are no errors. + var force = ""; + // From Cmdlet Help: Specify the scope of the feature to activate, either Web or Site. Defaults to Web. + var scopeVar = ""; + // From Cmdlet Help: Specify this parameter if the feature you're trying to activate is part of a sandboxed solution. + var sandboxed = ""; + + var results = scope.ExecuteCommand("Enable-PnPFeature", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Sandboxed", sandboxed)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Features/GetPnPFeatureTests.cs b/Tests/Features/GetPnPFeatureTests.cs new file mode 100644 index 000000000..7d4613db9 --- /dev/null +++ b/Tests/Features/GetPnPFeatureTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Features +{ + [TestClass] + public class GetFeatureTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFeatureTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The feature ID or name to query for, Querying by name is not supported in version 15 of the Client Side Object Model + var identity = ""; + // From Cmdlet Help: The scope of the feature. Defaults to Web. + var scopeVar = ""; + + var results = scope.ExecuteCommand("Get-PnPFeature", + new CommandParameter("Identity", identity), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/AddPnPFieldFromXmlTests.cs b/Tests/Fields/AddPnPFieldFromXmlTests.cs new file mode 100644 index 000000000..969ab2577 --- /dev/null +++ b/Tests/Fields/AddPnPFieldFromXmlTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class AddFieldFromXmlTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFieldFromXmlTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The name of the list, its ID or an actual list object where this field needs to be added + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: CAML snippet containing the field definition. See http://msdn.microsoft.com/en-us/library/office/ms437580(v=office.15).aspx + var fieldXml = ""; + + var results = scope.ExecuteCommand("Add-PnPFieldFromXml", + new CommandParameter("List", list), + new CommandParameter("FieldXml", fieldXml)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/AddPnPFieldTests.cs b/Tests/Fields/AddPnPFieldTests.cs new file mode 100644 index 000000000..ebc9d7ea0 --- /dev/null +++ b/Tests/Fields/AddPnPFieldTests.cs @@ -0,0 +1,111 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class AddFieldTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The name of the list, its ID or an actual list object where this field needs to be added + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the field, its ID or an actual field object that needs to be added + var field = ""; + // This is a mandatory parameter + // From Cmdlet Help: The display name of the field + var displayName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The internal name of the field + var internalName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of the field like Choice, Note, MultiChoice. For a complete list of field types visit https://docs.microsoft.com/dotnet/api/microsoft.sharepoint.client.fieldtype + var type = ""; + // From Cmdlet Help: The ID of the field, must be unique + var id = ""; + // From Cmdlet Help: Switch Parameter if this field must be added to the default view + var addToDefaultView = ""; + // From Cmdlet Help: Switch Parameter if the field is a required field + var required = ""; + // From Cmdlet Help: The group name to where this field belongs to + var group = ""; + // From Cmdlet Help: The Client Side Component Id to set to the field + var clientSideComponentId = ""; + // From Cmdlet Help: The Client Side Component Properties to set to the field + var clientSideComponentProperties = ""; + + var results = scope.ExecuteCommand("Add-PnPField", + new CommandParameter("List", list), + new CommandParameter("Field", field), + new CommandParameter("DisplayName", displayName), + new CommandParameter("InternalName", internalName), + new CommandParameter("Type", type), + new CommandParameter("Id", id), + new CommandParameter("AddToDefaultView", addToDefaultView), + new CommandParameter("Required", required), + new CommandParameter("Group", group), + new CommandParameter("ClientSideComponentId", clientSideComponentId), + new CommandParameter("ClientSideComponentProperties", clientSideComponentProperties)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/AddPnPTaxonomyFieldTests.cs b/Tests/Fields/AddPnPTaxonomyFieldTests.cs new file mode 100644 index 000000000..10e3aa8cc --- /dev/null +++ b/Tests/Fields/AddPnPTaxonomyFieldTests.cs @@ -0,0 +1,113 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class AddTaxonomyFieldTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTaxonomyFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The list object or name where this field needs to be added + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The display name of the field + var displayName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The internal name of the field + var internalName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The path to the term that this needs to be bound + var termSetPath = ""; + // From Cmdlet Help: The ID of the Taxonomy item + var taxonomyItemId = ""; + // From Cmdlet Help: The path delimiter to be used, by default this is '|' + var termPathDelimiter = ""; + // From Cmdlet Help: The group name to where this field belongs to + var group = ""; + // From Cmdlet Help: The ID for the field, must be unique + var id = ""; + // From Cmdlet Help: Switch Parameter if this field must be added to the default view + var addToDefaultView = ""; + // From Cmdlet Help: Switch Parameter if this Taxonomy field can hold multiple values + var multiValue = ""; + // From Cmdlet Help: Switch Parameter if the field is a required field + var required = ""; + // From Cmdlet Help: Specifies the control settings while adding a field. See https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.addfieldoptions.aspx for details + var fieldOptions = ""; + + var results = scope.ExecuteCommand("Add-PnPTaxonomyField", + new CommandParameter("List", list), + new CommandParameter("DisplayName", displayName), + new CommandParameter("InternalName", internalName), + new CommandParameter("TermSetPath", termSetPath), + new CommandParameter("TaxonomyItemId", taxonomyItemId), + new CommandParameter("TermPathDelimiter", termPathDelimiter), + new CommandParameter("Group", group), + new CommandParameter("Id", id), + new CommandParameter("AddToDefaultView", addToDefaultView), + new CommandParameter("MultiValue", multiValue), + new CommandParameter("Required", required), + new CommandParameter("FieldOptions", fieldOptions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/GetPnPFieldTests.cs b/Tests/Fields/GetPnPFieldTests.cs new file mode 100644 index 000000000..8d2875fd0 --- /dev/null +++ b/Tests/Fields/GetPnPFieldTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class GetFieldTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The list object or name where to get the field from + var list = ""; + // From Cmdlet Help: The field object or name to get + var identity = ""; + // From Cmdlet Help: Filter to the specified group + var group = ""; + // From Cmdlet Help: Search site hierarchy for fields + var inSiteHierarchy = ""; + + var results = scope.ExecuteCommand("Get-PnPField", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Group", group), + new CommandParameter("InSiteHierarchy", inSiteHierarchy)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/RemovePnPFieldTests.cs b/Tests/Fields/RemovePnPFieldTests.cs new file mode 100644 index 000000000..40fcc5dd8 --- /dev/null +++ b/Tests/Fields/RemovePnPFieldTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class RemoveFieldTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The field object or name to remove + var identity = ""; + // From Cmdlet Help: The list object or name where to remove the field from + var list = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPField", + new CommandParameter("Identity", identity), + new CommandParameter("List", list), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/SetPnPFieldTests.cs b/Tests/Fields/SetPnPFieldTests.cs new file mode 100644 index 000000000..0ce8f84fa --- /dev/null +++ b/Tests/Fields/SetPnPFieldTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class SetFieldTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPFieldTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The list object, name or id where to update the field. If omitted the field will be updated on the web. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The field object, internal field name (case sensitive) or field id to update + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: Hashtable of properties to update on the field. Use the syntax @{property1="value";property2="value"}. + var values = ""; + // From Cmdlet Help: If provided, the field will be updated on existing lists that use it as well. If not provided or set to $false, existing lists using the field will remain unchanged but new lists will get the updated field. + var updateExistingLists = ""; + + var results = scope.ExecuteCommand("Set-PnPField", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Values", values), + new CommandParameter("UpdateExistingLists", updateExistingLists)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Fields/SetPnPViewTests.cs b/Tests/Fields/SetPnPViewTests.cs new file mode 100644 index 000000000..649921f33 --- /dev/null +++ b/Tests/Fields/SetPnPViewTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Fields +{ + [TestClass] + public class SetViewTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPViewTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The Id, Title or Url of the list + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Id, Title or instance of the view + var identity = ""; + // From Cmdlet Help: Hashtable of properties to update on the view. Use the syntax @{property1="value";property2="value"}. + var values = ""; + // From Cmdlet Help: An array of fields to use in the view. Notice that specifying this value will remove the existing fields + var fields = ""; + // From Cmdlet Help: A valid XML fragment containing one or more Aggregations + var aggregations = ""; + + var results = scope.ExecuteCommand("Set-PnPView", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Values", values), + new CommandParameter("Fields", fields), + new CommandParameter("Aggregations", aggregations)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/AddPnPFileTests.cs b/Tests/Files/AddPnPFileTests.cs new file mode 100644 index 000000000..2074ea8a2 --- /dev/null +++ b/Tests/Files/AddPnPFileTests.cs @@ -0,0 +1,138 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class AddFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The local file path + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: The destination folder in the site + var folder = ""; + // This is a mandatory parameter + // From Cmdlet Help: Name for file + var fileName = ""; + // From Cmdlet Help: Filename to give the file on SharePoint + var newFileName = ""; + // This is a mandatory parameter + // From Cmdlet Help: Stream with the file contents + var stream = ""; + // From Cmdlet Help: If versioning is enabled, this will check out the file first if it exists, upload the file, then check it in again + var checkoutVar = ""; + // From Cmdlet Help: The comment added to the checkin + var checkInComment = ""; + // From Cmdlet Help: Will auto approve the uploaded file + var approve = ""; + // From Cmdlet Help: The comment added to the approval + var approveComment = ""; + // From Cmdlet Help: Will auto publish the file + var publish = ""; + // From Cmdlet Help: The comment added to the publish action + var publishComment = ""; + var useWebDav = ""; + // From Cmdlet Help: Use the internal names of the fields when specifying field names. + // Single line of text: -Values @{"Title" = "Title New"} + // Multiple lines of text: -Values @{"MultiText" = "New text\n\nMore text"} + // Rich text: -Values @{"MultiText" = "New text"} + // Choice: -Values @{"Choice" = "Value 1"} + // Number: -Values @{"Number" = "10"} + // Currency: -Values @{"Number" = "10"} + // Currency: -Values @{"Currency" = "10"} + // Date and Time: -Values @{"DateAndTime" = "03/10/2015 14:16"} + // Lookup (id of lookup value): -Values @{"Lookup" = "2"} + // Multi value lookup (id of lookup values as array 1): -Values @{"MultiLookupField" = "1","2"} + // Multi value lookup (id of lookup values as array 2): -Values @{"MultiLookupField" = 1,2} + // Multi value lookup (id of lookup values as string): -Values @{"MultiLookupField" = "1,2"} + // Yes/No: -Values @{"YesNo" = $false} + // Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{"Person" = "user1@domain.com","21"} + // Managed Metadata (single value with path to term): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE"} + // Managed Metadata (single value with id of term): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818"} with Id of term + // Managed Metadata (multiple values with paths to terms): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE","CORPORATE|DEPARTMENTS|HR"} + // Managed Metadata (multiple values with ids of terms): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818","52d88107-c2a8-4bf0-adfa-04bc2305b593"} + // Hyperlink or Picture: -Values @{"Hyperlink" = "https://github.com/OfficeDev/, OfficePnp"} + var values = ""; + // From Cmdlet Help: Use to assign a ContentType to the file + var contentType = ""; + + var results = scope.ExecuteCommand("Add-PnPFile", + new CommandParameter("Path", path), + new CommandParameter("Folder", folder), + new CommandParameter("FileName", fileName), + new CommandParameter("NewFileName", newFileName), + new CommandParameter("Stream", stream), + new CommandParameter("Checkout", checkoutVar), + new CommandParameter("CheckInComment", checkInComment), + new CommandParameter("Approve", approve), + new CommandParameter("ApproveComment", approveComment), + new CommandParameter("Publish", publish), + new CommandParameter("PublishComment", publishComment), + new CommandParameter("UseWebDav", useWebDav), + new CommandParameter("Values", values), + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/AddPnPFolderTests.cs b/Tests/Files/AddPnPFolderTests.cs new file mode 100644 index 000000000..3a7ff2aaa --- /dev/null +++ b/Tests/Files/AddPnPFolderTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class AddFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The folder name + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The parent folder in the site + var folder = ""; + + var results = scope.ExecuteCommand("Add-PnPFolder", + new CommandParameter("Name", name), + new CommandParameter("Folder", folder)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/CopyPnPFileTests.cs b/Tests/Files/CopyPnPFileTests.cs new file mode 100644 index 000000000..04ced9266 --- /dev/null +++ b/Tests/Files/CopyPnPFileTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class CopyFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void CopyPnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Server relative Url specifying the file or folder to copy. + var serverRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Site relative Url specifying the file or folder to copy. + var sourceUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Server relative Url where to copy the file or folder to. + var targetUrl = ""; + // From Cmdlet Help: If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the copy operation will be canceled if the file already exists at the TargetUrl location. + var overwriteIfAlreadyExists = ""; + // From Cmdlet Help: If provided, no confirmation will be requested and the action will be performed + var force = ""; + // From Cmdlet Help: If the source is a folder, the source folder name will not be created, only the contents within it. + var skipSourceFolderName = ""; + + var results = scope.ExecuteCommand("Copy-PnPFile", + new CommandParameter("ServerRelativeUrl", serverRelativeUrl), + new CommandParameter("SourceUrl", sourceUrl), + new CommandParameter("TargetUrl", targetUrl), + new CommandParameter("OverwriteIfAlreadyExists", overwriteIfAlreadyExists), + new CommandParameter("Force", force), + new CommandParameter("SkipSourceFolderName", skipSourceFolderName)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/FindPnPFileTests.cs b/Tests/Files/FindPnPFileTests.cs new file mode 100644 index 000000000..cf0abc525 --- /dev/null +++ b/Tests/Files/FindPnPFileTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class FindFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void FindPnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Wildcard query + var match = ""; + // This is a mandatory parameter + // From Cmdlet Help: List title, url or an actual List object to query + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: Folder object or relative url of a folder to query + var folder = ""; + + var results = scope.ExecuteCommand("Find-PnPFile", + new CommandParameter("Match", match), + new CommandParameter("List", list), + new CommandParameter("Folder", folder)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/GetPnPFileTests.cs b/Tests/Files/GetPnPFileTests.cs new file mode 100644 index 000000000..1f7c92731 --- /dev/null +++ b/Tests/Files/GetPnPFileTests.cs @@ -0,0 +1,102 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class GetFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The URL (server or site relative) to the file + var url = ""; + // From Cmdlet Help: Local path where the file should be saved + var path = ""; + // From Cmdlet Help: Name for the local file + var filename = ""; + // This is a mandatory parameter + var asFile = ""; + // From Cmdlet Help: Returns the file as a listitem showing all its properties + var asListItem = ""; + // From Cmdlet Help: If provided in combination with -AsListItem, a System.ArgumentException will be thrown if the file specified in the -Url argument does not exist. Otherwise it will return nothing instead. + var throwExceptionIfFileNotFound = ""; + // From Cmdlet Help: Retrieve the file contents as a string + var asString = ""; + // From Cmdlet Help: Overwrites the file if it exists. + var force = ""; + // From Cmdlet Help: Retrieve the file contents as a file object. + var asFileObject = ""; + + var results = scope.ExecuteCommand("Get-PnPFile", + new CommandParameter("Url", url), + new CommandParameter("Path", path), + new CommandParameter("Filename", filename), + new CommandParameter("AsFile", asFile), + new CommandParameter("AsListItem", asListItem), + new CommandParameter("ThrowExceptionIfFileNotFound", throwExceptionIfFileNotFound), + new CommandParameter("AsString", asString), + new CommandParameter("Force", force), + new CommandParameter("AsFileObject", asFileObject)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/GetPnPFolderItemTests.cs b/Tests/Files/GetPnPFolderItemTests.cs new file mode 100644 index 000000000..fdfb0e70d --- /dev/null +++ b/Tests/Files/GetPnPFolderItemTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class GetFolderItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFolderItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The site relative URL of the folder to retrieve + var folderSiteRelativeUrl = ""; + // From Cmdlet Help: A folder instance to the folder to retrieve + var identity = ""; + // From Cmdlet Help: The type of contents to retrieve, either File, Folder or All (default) + var itemType = ""; + // From Cmdlet Help: Optional name of the item to retrieve + var itemName = ""; + // From Cmdlet Help: A switch parameter to include contents of all subfolders in the specified folder + var recursive = ""; + + var results = scope.ExecuteCommand("Get-PnPFolderItem", + new CommandParameter("FolderSiteRelativeUrl", folderSiteRelativeUrl), + new CommandParameter("Identity", identity), + new CommandParameter("ItemType", itemType), + new CommandParameter("ItemName", itemName), + new CommandParameter("Recursive", recursive)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/GetPnPFolderTests.cs b/Tests/Files/GetPnPFolderTests.cs new file mode 100644 index 000000000..c3db98937 --- /dev/null +++ b/Tests/Files/GetPnPFolderTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class GetFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Site or server relative URL of the folder to retrieve. In the case of a server relative url, make sure that the url starts with the managed path as the current web. + var url = ""; + // This is a mandatory parameter + // From Cmdlet Help: Name, ID or instance of a list or document library to retrieve the folders residing in it for. + var list = ""; + + var results = scope.ExecuteCommand("Get-PnPFolder", + new CommandParameter("Url", url), + new CommandParameter("List", list)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/MovePnPFileTests.cs b/Tests/Files/MovePnPFileTests.cs new file mode 100644 index 000000000..8a91c7162 --- /dev/null +++ b/Tests/Files/MovePnPFileTests.cs @@ -0,0 +1,105 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class MoveFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MovePnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Server relative Url specifying the file to move. Must include the file name. + var serverRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Site relative Url specifying the file to move. Must include the file name. + var siteRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Server relative Url where to move the file to. Must include the file name. + var targetUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Server relative url of a document library where to move the file to. Must not include the file name. + var targetServerRelativeLibrary = ""; + // From Cmdlet Help: If provided, if a file already exists at the TargetUrl, it will be overwritten. If omitted, the move operation will be canceled if the file already exists at the TargetUrl location. + var overwriteIfAlreadyExists = ""; + // From Cmdlet Help: If provided and the target document library specified using TargetServerRelativeLibrary has different fields than the document library where the document is being moved from, the move will succeed. If not provided, it will fail to protect against data loss of metadata stored in fields that cannot be moved along. + var allowSchemaMismatch = ""; + // From Cmdlet Help: If provided and the target document library specified using TargetServerRelativeLibrary is configured to keep less historical versions of documents than the document library where the document is being moved from, the move will succeed. If not provided, it will fail to protect against data loss of historical versions that cannot be moved along. + var allowSmallerVersionLimitOnDestination = ""; + // From Cmdlet Help: If provided, only the latest version of the document will be moved and its history will be discared. If not provided, all historical versions will be moved along. + var ignoreVersionHistory = ""; + // From Cmdlet Help: If provided, no confirmation will be requested and the action will be performed + var force = ""; + + var results = scope.ExecuteCommand("Move-PnPFile", + new CommandParameter("ServerRelativeUrl", serverRelativeUrl), + new CommandParameter("SiteRelativeUrl", siteRelativeUrl), + new CommandParameter("TargetUrl", targetUrl), + new CommandParameter("TargetServerRelativeLibrary", targetServerRelativeLibrary), + new CommandParameter("OverwriteIfAlreadyExists", overwriteIfAlreadyExists), + new CommandParameter("AllowSchemaMismatch", allowSchemaMismatch), + new CommandParameter("AllowSmallerVersionLimitOnDestination", allowSmallerVersionLimitOnDestination), + new CommandParameter("IgnoreVersionHistory", ignoreVersionHistory), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/MovePnPFolderTests.cs b/Tests/Files/MovePnPFolderTests.cs new file mode 100644 index 000000000..dd765d158 --- /dev/null +++ b/Tests/Files/MovePnPFolderTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class MoveFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MovePnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The folder to move + var folder = ""; + // This is a mandatory parameter + // From Cmdlet Help: The new parent location to which the folder should be moved to + var targetFolder = ""; + + var results = scope.ExecuteCommand("Move-PnPFolder", + new CommandParameter("Folder", folder), + new CommandParameter("TargetFolder", targetFolder)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/RemovePnPFileTests.cs b/Tests/Files/RemovePnPFileTests.cs new file mode 100644 index 000000000..967e9c6d9 --- /dev/null +++ b/Tests/Files/RemovePnPFileTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class RemoveFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Server relative URL to the file + var serverRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Site relative URL to the file + var siteRelativeUrl = ""; + var recycle = ""; + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPFile", + new CommandParameter("ServerRelativeUrl", serverRelativeUrl), + new CommandParameter("SiteRelativeUrl", siteRelativeUrl), + new CommandParameter("Recycle", recycle), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/RemovePnPFolderTests.cs b/Tests/Files/RemovePnPFolderTests.cs new file mode 100644 index 000000000..756e2b646 --- /dev/null +++ b/Tests/Files/RemovePnPFolderTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class RemoveFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The folder name + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The parent folder in the site + var folder = ""; + var recycle = ""; + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPFolder", + new CommandParameter("Name", name), + new CommandParameter("Folder", folder), + new CommandParameter("Recycle", recycle), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/RenamePnPFileTests.cs b/Tests/Files/RenamePnPFileTests.cs new file mode 100644 index 000000000..8a86fdbb7 --- /dev/null +++ b/Tests/Files/RenamePnPFileTests.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class RenameFileTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RenamePnPFileTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Server relative Url specifying the file to rename. Must include the file name. + var serverRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Site relative Url specifying the file to rename. Must include the file name. + var siteRelativeUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: File name to rename the file to. Should only be the file name and not include the path to its location. Use Move-PnPFile to move the file to another location. + var targetFileName = ""; + // From Cmdlet Help: If provided, if a file already exist with the provided TargetFileName, it will be overwritten. If omitted, the rename operation will be canceled if a file already exists with the TargetFileName file name. + var overwriteIfAlreadyExists = ""; + // From Cmdlet Help: If provided, no confirmation will be requested and the action will be performed + var force = ""; + + var results = scope.ExecuteCommand("Rename-PnPFile", + new CommandParameter("ServerRelativeUrl", serverRelativeUrl), + new CommandParameter("SiteRelativeUrl", siteRelativeUrl), + new CommandParameter("TargetFileName", targetFileName), + new CommandParameter("OverwriteIfAlreadyExists", overwriteIfAlreadyExists), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/RenamePnPFolderTests.cs b/Tests/Files/RenamePnPFolderTests.cs new file mode 100644 index 000000000..34da4abc1 --- /dev/null +++ b/Tests/Files/RenamePnPFolderTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class RenameFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RenamePnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The folder to rename + var folder = ""; + // This is a mandatory parameter + // From Cmdlet Help: The new folder name + var targetFolderName = ""; + + var results = scope.ExecuteCommand("Rename-PnPFolder", + new CommandParameter("Folder", folder), + new CommandParameter("TargetFolderName", targetFolderName)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/ResetPnPFileVersionTests.cs b/Tests/Files/ResetPnPFileVersionTests.cs new file mode 100644 index 000000000..d9f28eea6 --- /dev/null +++ b/Tests/Files/ResetPnPFileVersionTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class ResetFileVersionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ResetPnPFileVersionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative URL of the file. + var serverRelativeUrl = ""; + // From Cmdlet Help: The check in type to use. Defaults to Major. + var checkinType = ""; + // From Cmdlet Help: The comment added to the checkin. Defaults to 'Restored to previous version'. + var checkInComment = ""; + + var results = scope.ExecuteCommand("Reset-PnPFileVersion", + new CommandParameter("ServerRelativeUrl", serverRelativeUrl), + new CommandParameter("CheckinType", checkinType), + new CommandParameter("CheckInComment", checkInComment)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/ResolvePnPFolderTests.cs b/Tests/Files/ResolvePnPFolderTests.cs new file mode 100644 index 000000000..80b2c2b9c --- /dev/null +++ b/Tests/Files/ResolvePnPFolderTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class ResolveFolderTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ResolvePnPFolderTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Site Relative Folder Path + var siteRelativePath = ""; + + var results = scope.ExecuteCommand("Resolve-PnPFolder", + new CommandParameter("SiteRelativePath", siteRelativePath)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/SetPnPFileCheckedInTests.cs b/Tests/Files/SetPnPFileCheckedInTests.cs new file mode 100644 index 000000000..dd98f5fcb --- /dev/null +++ b/Tests/Files/SetPnPFileCheckedInTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class SetFileCheckedInTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPFileCheckedInTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative url of the file to check in + var url = ""; + // From Cmdlet Help: The check in type to use. Defaults to Major + var checkinType = ""; + // From Cmdlet Help: The check in comment + var comment = ""; + // From Cmdlet Help: Approve file + var approve = ""; + + var results = scope.ExecuteCommand("Set-PnPFileCheckedIn", + new CommandParameter("Url", url), + new CommandParameter("CheckinType", checkinType), + new CommandParameter("Comment", comment), + new CommandParameter("Approve", approve)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/SetPnPFileCheckedOutTests.cs b/Tests/Files/SetPnPFileCheckedOutTests.cs new file mode 100644 index 000000000..4d5ebf96c --- /dev/null +++ b/Tests/Files/SetPnPFileCheckedOutTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class SetFileCheckedOutTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPFileCheckedOutTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative url of the file to check out + var url = ""; + + var results = scope.ExecuteCommand("Set-PnPFileCheckedOut", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Files/SetPnPFolderPermissionTests.cs b/Tests/Files/SetPnPFolderPermissionTests.cs new file mode 100644 index 000000000..03995b05b --- /dev/null +++ b/Tests/Files/SetPnPFolderPermissionTests.cs @@ -0,0 +1,103 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Files +{ + [TestClass] + public class SetFolderPermissionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPFolderPermissionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list the folder is part of + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the folder, the server relative URL to the folder or actual Folder object + var identity = ""; + // This is a mandatory parameter + var group = ""; + // This is a mandatory parameter + var user = ""; + // From Cmdlet Help: The role that must be assigned to the group or user + var addRole = ""; + // From Cmdlet Help: The role that must be removed from the group or user + var removeRole = ""; + // From Cmdlet Help: Clear all existing permissions + var clearExisting = ""; + // From Cmdlet Help: Inherit permissions from the parent, removing unique permissions + var inheritPermissions = ""; + // From Cmdlet Help: Update the folder permissions without creating a new version or triggering MS Flow. + var systemUpdate = ""; + + var results = scope.ExecuteCommand("Set-PnPFolderPermission", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Group", group), + new CommandParameter("User", user), + new CommandParameter("AddRole", addRole), + new CommandParameter("RemoveRole", removeRole), + new CommandParameter("ClearExisting", clearExisting), + new CommandParameter("InheritPermissions", inheritPermissions), + new CommandParameter("SystemUpdate", systemUpdate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/AddPnPSiteClassificationTests.cs b/Tests/Graph/AddPnPSiteClassificationTests.cs new file mode 100644 index 000000000..627fa2a6b --- /dev/null +++ b/Tests/Graph/AddPnPSiteClassificationTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class AddSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var classifications = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteClassification", + new CommandParameter("Classifications", classifications)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/DisablePnPSiteClassificationTests.cs b/Tests/Graph/DisablePnPSiteClassificationTests.cs new file mode 100644 index 000000000..46b799260 --- /dev/null +++ b/Tests/Graph/DisablePnPSiteClassificationTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class DisableSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Disable-PnPSiteClassification"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/EnablePnPSiteClassificationTests.cs b/Tests/Graph/EnablePnPSiteClassificationTests.cs new file mode 100644 index 000000000..69b8e3ce2 --- /dev/null +++ b/Tests/Graph/EnablePnPSiteClassificationTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class EnableSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var classifications = ""; + // This is a mandatory parameter + var defaultClassification = ""; + var usageGuidelinesUrl = ""; + + var results = scope.ExecuteCommand("Enable-PnPSiteClassification", + new CommandParameter("Classifications", classifications), + new CommandParameter("DefaultClassification", defaultClassification), + new CommandParameter("UsageGuidelinesUrl", usageGuidelinesUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPAADUserTests.cs b/Tests/Graph/GetPnPAADUserTests.cs new file mode 100644 index 000000000..1e66a919f --- /dev/null +++ b/Tests/Graph/GetPnPAADUserTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetAADUserTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAADUserTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the user with the provided user id + var identity = ""; + // From Cmdlet Help: Includes a filter to the retrieval of the users. Use OData instructions to construct the filter, i.e. "startswith(DisplayName, 'John')". + var filter = ""; + // From Cmdlet Help: Includes a custom sorting instruction to the retrieval of the users. Use OData syntax to construct the orderby, i.e. "DisplayName desc". + var orderBy = ""; + // From Cmdlet Help: Allows providing an array with the property names of specific properties to return. If not provided, the default properties will be returned. + var select = ""; + // This is a mandatory parameter + // From Cmdlet Help: Retrieves all users and provides a SkipToken delta token to allow to query for changes since this run when querying again by adding -DeltaToken to the command + var delta = ""; + // From Cmdlet Help: The change token provided during the previous run with -Delta to query for the changes to user objects made in Azure Active Directory since that run + var deltaToken = ""; + + var results = scope.ExecuteCommand("Get-PnPAADUser", + new CommandParameter("Identity", identity), + new CommandParameter("Filter", filter), + new CommandParameter("OrderBy", orderBy), + new CommandParameter("Select", select), + new CommandParameter("Delta", delta), + new CommandParameter("DeltaToken", deltaToken)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPDeletedUnifiedGroupTests.cs b/Tests/Graph/GetPnPDeletedUnifiedGroupTests.cs new file mode 100644 index 000000000..289be366f --- /dev/null +++ b/Tests/Graph/GetPnPDeletedUnifiedGroupTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetDeletedUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPDeletedUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The Identity of the Microsoft 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPDeletedUnifiedGroup", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPGraphSubscriptionTests.cs b/Tests/Graph/GetPnPGraphSubscriptionTests.cs new file mode 100644 index 000000000..660baa330 --- /dev/null +++ b/Tests/Graph/GetPnPGraphSubscriptionTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetGraphSubscriptionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPGraphSubscriptionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the subscription with the provided subscription id + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPGraphSubscription", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPSiteClassificationTests.cs b/Tests/Graph/GetPnPSiteClassificationTests.cs new file mode 100644 index 000000000..6aef7851f --- /dev/null +++ b/Tests/Graph/GetPnPSiteClassificationTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPSiteClassification"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPUnifiedGroupMembersTests.cs b/Tests/Graph/GetPnPUnifiedGroupMembersTests.cs new file mode 100644 index 000000000..5e3bfde1a --- /dev/null +++ b/Tests/Graph/GetPnPUnifiedGroupMembersTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetUnifiedGroupMembersTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPUnifiedGroupMembersTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the Microsoft 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPUnifiedGroupMembers", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPUnifiedGroupOwnersTests.cs b/Tests/Graph/GetPnPUnifiedGroupOwnersTests.cs new file mode 100644 index 000000000..f8a39c1c2 --- /dev/null +++ b/Tests/Graph/GetPnPUnifiedGroupOwnersTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetUnifiedGroupOwnersTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPUnifiedGroupOwnersTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the Microsoft 365 Group. + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPUnifiedGroupOwners", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/GetPnPUnifiedGroupTests.cs b/Tests/Graph/GetPnPUnifiedGroupTests.cs new file mode 100644 index 000000000..75323cc15 --- /dev/null +++ b/Tests/Graph/GetPnPUnifiedGroupTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class GetUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The Identity of the Microsoft 365 Group + var identity = ""; + // From Cmdlet Help: Exclude fetching the site URL for Microsoft 365 Groups. This speeds up large listings. + var excludeSiteUrl = ""; + // From Cmdlet Help: Include Classification value of Microsoft 365 Groups + var includeClassification = ""; + // From Cmdlet Help: Include a flag for every Microsoft 365 Group if it has a Microsoft Team provisioned for it. This will slow down the retrieval of Microsoft 365 Groups so only use it if you need it. + var includeHasTeam = ""; + + var results = scope.ExecuteCommand("Get-PnPUnifiedGroup", + new CommandParameter("Identity", identity), + new CommandParameter("ExcludeSiteUrl", excludeSiteUrl), + new CommandParameter("IncludeClassification", includeClassification), + new CommandParameter("IncludeHasTeam", includeHasTeam)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/NewPnPGraphSubscriptionTests.cs b/Tests/Graph/NewPnPGraphSubscriptionTests.cs new file mode 100644 index 000000000..9029bf20e --- /dev/null +++ b/Tests/Graph/NewPnPGraphSubscriptionTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class NewGraphSubscriptionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPGraphSubscriptionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The event(s) the subscription should trigger on + var changeType = ""; + // This is a mandatory parameter + // From Cmdlet Help: The URL that should be called when an event matching this subscription occurs + var notificationUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: The resource to monitor for changes. See https://docs.microsoft.com/graph/api/subscription-post-subscriptions#resources-examples for the list with supported options. + var resource = ""; + // From Cmdlet Help: The datetime defining how long this subscription should stay alive before which it needs to get extended to stay alive. See https://docs.microsoft.com/graph/api/resources/subscription#maximum-length-of-subscription-per-resource-type for the supported maximum lifetime of the subscriber endpoints. + var expirationDateTime = ""; + // From Cmdlet Help: Specifies the value of the clientState property sent by the service in each notification. The maximum length is 128 characters. The client can check that the notification came from the service by comparing the value of the clientState property sent with the subscription with the value of the clientState property received with each notification. + var clientState = ""; + // From Cmdlet Help: Specifies the latest version of Transport Layer Security (TLS) that the notification endpoint, specified by NotificationUrl, supports. If not provided, TLS 1.2 will be assumed. + var latestSupportedTlsVersion = ""; + + var results = scope.ExecuteCommand("New-PnPGraphSubscription", + new CommandParameter("ChangeType", changeType), + new CommandParameter("NotificationUrl", notificationUrl), + new CommandParameter("Resource", resource), + new CommandParameter("ExpirationDateTime", expirationDateTime), + new CommandParameter("ClientState", clientState), + new CommandParameter("LatestSupportedTlsVersion", latestSupportedTlsVersion)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/NewPnPUnifiedGroupTests.cs b/Tests/Graph/NewPnPUnifiedGroupTests.cs new file mode 100644 index 000000000..0312f647b --- /dev/null +++ b/Tests/Graph/NewPnPUnifiedGroupTests.cs @@ -0,0 +1,104 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class NewPnPUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Display Name of the Microsoft 365 Group + var displayName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Description of the Microsoft 365 Group + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Mail Nickname of the Microsoft 365 Group. Cannot contain spaces. + var mailNickname = ""; + // From Cmdlet Help: The array UPN values of the group's owners + var owners = ""; + // From Cmdlet Help: The array UPN values of the group's members + var members = ""; + // From Cmdlet Help: Makes the group private when selected + var isPrivate = ""; + // From Cmdlet Help: The path to the logo file of to set + var groupLogoPath = ""; + // From Cmdlet Help: Creates a Microsoft Teams team associated with created group + var createTeam = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("New-PnPUnifiedGroup", + new CommandParameter("DisplayName", displayName), + new CommandParameter("Description", description), + new CommandParameter("MailNickname", mailNickname), + new CommandParameter("Owners", owners), + new CommandParameter("Members", members), + new CommandParameter("IsPrivate", isPrivate), + new CommandParameter("GroupLogoPath", groupLogoPath), + new CommandParameter("CreateTeam", createTeam), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/RemovePnPDeletedUnifiedGroupTests.cs b/Tests/Graph/RemovePnPDeletedUnifiedGroupTests.cs new file mode 100644 index 000000000..bb7aeeaa1 --- /dev/null +++ b/Tests/Graph/RemovePnPDeletedUnifiedGroupTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class RemoveDeletedUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPDeletedUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the deleted Microsoft 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Remove-PnPDeletedUnifiedGroup", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/RemovePnPGraphSubscriptionTests.cs b/Tests/Graph/RemovePnPGraphSubscriptionTests.cs new file mode 100644 index 000000000..e24a6d48e --- /dev/null +++ b/Tests/Graph/RemovePnPGraphSubscriptionTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class RemoveGraphSubscriptionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPGraphSubscriptionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The unique id or an instance of a Microsoft Graph Subscription + var identity = ""; + + var results = scope.ExecuteCommand("Remove-PnPGraphSubscription", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/RemovePnPSiteClassificationTests.cs b/Tests/Graph/RemovePnPSiteClassificationTests.cs new file mode 100644 index 000000000..f57669ac1 --- /dev/null +++ b/Tests/Graph/RemovePnPSiteClassificationTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class RemoveSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var classifications = ""; + // From Cmdlet Help: Specifying the Confirm parameter will allow the confirmation question to be skipped + var confirm = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteClassification", + new CommandParameter("Classifications", classifications), + new CommandParameter("Confirm", confirm)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/RemovePnPUnifiedGroupTests.cs b/Tests/Graph/RemovePnPUnifiedGroupTests.cs new file mode 100644 index 000000000..d472a1689 --- /dev/null +++ b/Tests/Graph/RemovePnPUnifiedGroupTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class RemoveUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the Microsoft 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Remove-PnPUnifiedGroup", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/ResetPnPUnifiedGroupExpirationTests.cs b/Tests/Graph/ResetPnPUnifiedGroupExpirationTests.cs new file mode 100644 index 000000000..30fd3643c --- /dev/null +++ b/Tests/Graph/ResetPnPUnifiedGroupExpirationTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class ResetUnifiedGroupExpirationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ResetPnPUnifiedGroupExpirationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the Office 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Reset-PnPUnifiedGroupExpiration", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/RestorePnPDeletedUnifiedGroupTests.cs b/Tests/Graph/RestorePnPDeletedUnifiedGroupTests.cs new file mode 100644 index 000000000..8ec2ff5d0 --- /dev/null +++ b/Tests/Graph/RestorePnPDeletedUnifiedGroupTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class RestoreDeletedUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RestorePnPDeletedUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the deleted Microsoft 365 Group + var identity = ""; + + var results = scope.ExecuteCommand("Restore-PnPDeletedUnifiedGroup", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/SetPnPGraphSubscriptionTests.cs b/Tests/Graph/SetPnPGraphSubscriptionTests.cs new file mode 100644 index 000000000..98238a7ea --- /dev/null +++ b/Tests/Graph/SetPnPGraphSubscriptionTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class SetGraphSubscriptionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPGraphSubscriptionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The unique id or an instance of a Microsoft Graph Subscription + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: Date and time to set the expiration to. Take notice of the maximum allowed lifetime of the subscription endponts as documented at https://docs.microsoft.com/graph/api/resources/subscription#maximum-length-of-subscription-per-resource-type + var expirationDate = ""; + + var results = scope.ExecuteCommand("Set-PnPGraphSubscription", + new CommandParameter("Identity", identity), + new CommandParameter("ExpirationDate", expirationDate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/SetPnPUnifiedGroupTests.cs b/Tests/Graph/SetPnPUnifiedGroupTests.cs new file mode 100644 index 000000000..b363c938d --- /dev/null +++ b/Tests/Graph/SetPnPUnifiedGroupTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class SetUnifiedGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPUnifiedGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Identity of the Microsoft 365 Group + var identity = ""; + // From Cmdlet Help: The DisplayName of the group to set + var displayName = ""; + // From Cmdlet Help: The Description of the group to set + var description = ""; + // From Cmdlet Help: The array UPN values of owners to set to the group. Note: Will replace owners. + var owners = ""; + // From Cmdlet Help: The array UPN values of members to set to the group. Note: Will replace members. + var members = ""; + // From Cmdlet Help: Makes the group private when selected + var isPrivate = ""; + // From Cmdlet Help: The path to the logo file of to set + var groupLogoPath = ""; + // From Cmdlet Help: Creates a Microsoft Teams team associated with created group + var createTeam = ""; + + var results = scope.ExecuteCommand("Set-PnPUnifiedGroup", + new CommandParameter("Identity", identity), + new CommandParameter("DisplayName", displayName), + new CommandParameter("Description", description), + new CommandParameter("Owners", owners), + new CommandParameter("Members", members), + new CommandParameter("IsPrivate", isPrivate), + new CommandParameter("GroupLogoPath", groupLogoPath), + new CommandParameter("CreateTeam", createTeam)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Graph/UpdatePnPSiteClassificationTests.cs b/Tests/Graph/UpdatePnPSiteClassificationTests.cs new file mode 100644 index 000000000..2fe82cba3 --- /dev/null +++ b/Tests/Graph/UpdatePnPSiteClassificationTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Graph +{ + [TestClass] + public class UpdateSiteClassificationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UpdatePnPSiteClassificationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: A settings object retrieved by Get-PnPSiteClassification + var settings = ""; + // From Cmdlet Help: A list of classifications, separated by commas. E.g. "HBI","LBI","Top Secret" + var classifications = ""; + // From Cmdlet Help: The default classification to be used. The value needs to be present in the list of possible classifications + var defaultClassification = ""; + // From Cmdlet Help: The UsageGuidelinesUrl. Set to "" to clear. + var usageGuidelinesUrl = ""; + + var results = scope.ExecuteCommand("Update-PnPSiteClassification", + new CommandParameter("Settings", settings), + new CommandParameter("Classifications", classifications), + new CommandParameter("DefaultClassification", defaultClassification), + new CommandParameter("UsageGuidelinesUrl", usageGuidelinesUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/GetPnPLabelTests.cs b/Tests/InformationManagement/GetPnPLabelTests.cs new file mode 100644 index 000000000..e8d64ebe7 --- /dev/null +++ b/Tests/InformationManagement/GetPnPLabelTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class GetLabelTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPLabelTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list + var list = ""; + // From Cmdlet Help: If provided, the results will be returned as values instead of in written text and will include more detailed information + var valuesOnly = ""; + + var results = scope.ExecuteCommand("Get-PnPLabel", + new CommandParameter("List", list), + new CommandParameter("ValuesOnly", valuesOnly)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/GetPnPListInformationRightsManagementTests.cs b/Tests/InformationManagement/GetPnPListInformationRightsManagementTests.cs new file mode 100644 index 000000000..edd8810de --- /dev/null +++ b/Tests/InformationManagement/GetPnPListInformationRightsManagementTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class GetListInformationRightsManagementTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPListInformationRightsManagementTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var list = ""; + + var results = scope.ExecuteCommand("Get-PnPListInformationRightsManagement", + new CommandParameter("List", list)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/GetPnPSiteClosureTests.cs b/Tests/InformationManagement/GetPnPSiteClosureTests.cs new file mode 100644 index 000000000..59c64b4a7 --- /dev/null +++ b/Tests/InformationManagement/GetPnPSiteClosureTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class GetSiteClosureTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteClosureTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPSiteClosure"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/GetPnPSitePolicyTests.cs b/Tests/InformationManagement/GetPnPSitePolicyTests.cs new file mode 100644 index 000000000..83c814d33 --- /dev/null +++ b/Tests/InformationManagement/GetPnPSitePolicyTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class GetSitePolicyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSitePolicyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Retrieve all available site policies + var allAvailable = ""; + // From Cmdlet Help: Retrieves a site policy with a specific name + var name = ""; + + var results = scope.ExecuteCommand("Get-PnPSitePolicy", + new CommandParameter("AllAvailable", allAvailable), + new CommandParameter("Name", name)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/ResetPnPLabelTests.cs b/Tests/InformationManagement/ResetPnPLabelTests.cs new file mode 100644 index 000000000..3999c9c02 --- /dev/null +++ b/Tests/InformationManagement/ResetPnPLabelTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class ResetLabelTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ResetPnPLabelTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list + var list = ""; + // From Cmdlet Help: Reset label on existing items in the library + var syncToItems = ""; + + var results = scope.ExecuteCommand("Reset-PnPLabel", + new CommandParameter("List", list), + new CommandParameter("SyncToItems", syncToItems)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/SetPnPLabelTests.cs b/Tests/InformationManagement/SetPnPLabelTests.cs new file mode 100644 index 000000000..758d0a084 --- /dev/null +++ b/Tests/InformationManagement/SetPnPLabelTests.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class SetLabelTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPLabelTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the retention label + var label = ""; + // From Cmdlet Help: Apply label to existing items in the library + var syncToItems = ""; + // From Cmdlet Help: Block deletion of items in the library + var blockDeletion = ""; + // From Cmdlet Help: Block editing of items in the library + var blockEdit = ""; + + var results = scope.ExecuteCommand("Set-PnPLabel", + new CommandParameter("List", list), + new CommandParameter("Label", label), + new CommandParameter("SyncToItems", syncToItems), + new CommandParameter("BlockDeletion", blockDeletion), + new CommandParameter("BlockEdit", blockEdit)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/SetPnPListInformationRightsManagementTests.cs b/Tests/InformationManagement/SetPnPListInformationRightsManagementTests.cs new file mode 100644 index 000000000..d1385e5ce --- /dev/null +++ b/Tests/InformationManagement/SetPnPListInformationRightsManagementTests.cs @@ -0,0 +1,131 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class SetListInformationRightsManagementTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListInformationRightsManagementTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The list to set Information Rights Management (IRM) settings for. + var list = ""; + // From Cmdlet Help: Specifies whether Information Rights Management (IRM) is enabled for the list. + var enable = ""; + // From Cmdlet Help: Specifies whether Information Rights Management (IRM) expiration is enabled for the list. + var enableExpiration = ""; + // From Cmdlet Help: Specifies whether Information Rights Management (IRM) rejection is enabled for the list. + var enableRejection = ""; + // From Cmdlet Help: Sets a value indicating whether the viewer can print the downloaded document. + var allowPrint = ""; + // From Cmdlet Help: Sets a value indicating whether the viewer can run a script on the downloaded document. + var allowScript = ""; + // From Cmdlet Help: Sets a value indicating whether the viewer can write on a copy of the downloaded document. + var allowWriteCopy = ""; + // From Cmdlet Help: Sets a value indicating whether to block Office Web Application Companion applications (WACs) from showing this document. + var disableDocumentBrowserView = ""; + // From Cmdlet Help: Sets the number of days after which the downloaded document will expire. + var documentAccessExpireDays = ""; + // From Cmdlet Help: Sets the date after which the Information Rights Management (IRM) protection of this document library will stop. + var documentLibraryProtectionExpireDate = ""; + // From Cmdlet Help: Sets a value indicating whether the downloaded document will expire. + var enableDocumentAccessExpire = ""; + // From Cmdlet Help: Sets a value indicating whether to enable Office Web Application Companion applications (WACs) to publishing view. + var enableDocumentBrowserPublishingView = ""; + // From Cmdlet Help: Sets a value indicating whether the permission of the downloaded document is applicable to a group. + var enableGroupProtection = ""; + // From Cmdlet Help: Sets whether a user must verify their credentials after some interval. + var enableLicenseCacheExpire = ""; + // From Cmdlet Help: Sets the number of days that the application that opens the document caches the IRM license. When these elapse, the application will connect to the IRM server to validate the license. + var licenseCacheExpireDays = ""; + // From Cmdlet Help: Sets the group name (email address) that the permission is also applicable to. + var groupName = ""; + // From Cmdlet Help: Sets the permission policy description. + var policyDescription = ""; + // From Cmdlet Help: Sets the permission policy title. + var policyTitle = ""; + var templateId = ""; + + var results = scope.ExecuteCommand("Set-PnPListInformationRightsManagement", + new CommandParameter("List", list), + new CommandParameter("Enable", enable), + new CommandParameter("EnableExpiration", enableExpiration), + new CommandParameter("EnableRejection", enableRejection), + new CommandParameter("AllowPrint", allowPrint), + new CommandParameter("AllowScript", allowScript), + new CommandParameter("AllowWriteCopy", allowWriteCopy), + new CommandParameter("DisableDocumentBrowserView", disableDocumentBrowserView), + new CommandParameter("DocumentAccessExpireDays", documentAccessExpireDays), + new CommandParameter("DocumentLibraryProtectionExpireDate", documentLibraryProtectionExpireDate), + new CommandParameter("EnableDocumentAccessExpire", enableDocumentAccessExpire), + new CommandParameter("EnableDocumentBrowserPublishingView", enableDocumentBrowserPublishingView), + new CommandParameter("EnableGroupProtection", enableGroupProtection), + new CommandParameter("EnableLicenseCacheExpire", enableLicenseCacheExpire), + new CommandParameter("LicenseCacheExpireDays", licenseCacheExpireDays), + new CommandParameter("GroupName", groupName), + new CommandParameter("PolicyDescription", policyDescription), + new CommandParameter("PolicyTitle", policyTitle), + new CommandParameter("TemplateId", templateId)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/SetPnPSiteClosureTests.cs b/Tests/InformationManagement/SetPnPSiteClosureTests.cs new file mode 100644 index 000000000..51f969134 --- /dev/null +++ b/Tests/InformationManagement/SetPnPSiteClosureTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class SetSiteClosureTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSiteClosureTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The state of the site + var state = ""; + + var results = scope.ExecuteCommand("Set-PnPSiteClosure", + new CommandParameter("State", state)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/InformationManagement/SetPnPSitePolicyTests.cs b/Tests/InformationManagement/SetPnPSitePolicyTests.cs new file mode 100644 index 000000000..c18b0f269 --- /dev/null +++ b/Tests/InformationManagement/SetPnPSitePolicyTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.InformationManagement +{ + [TestClass] + public class ApplySitePolicyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSitePolicyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the site policy to apply + var name = ""; + + var results = scope.ExecuteCommand("Set-PnPSitePolicy", + new CommandParameter("Name", name)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/AddPnPListItemTests.cs b/Tests/Lists/AddPnPListItemTests.cs new file mode 100644 index 000000000..912ec40db --- /dev/null +++ b/Tests/Lists/AddPnPListItemTests.cs @@ -0,0 +1,109 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class AddListItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPListItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // From Cmdlet Help: Specify either the name, ID or an actual content type. + var contentType = ""; + // From Cmdlet Help: Use the internal names of the fields when specifying field names. + // Single line of text: -Values @{"Title" = "Title New"} + // Multiple lines of text: -Values @{"MultiText" = "New text\n\nMore text"} + // Rich text: -Values @{"MultiText" = "New text"} + // Choice: -Values @{"Choice" = "Value 1"} + // Number: -Values @{"Number" = "10"} + // Currency: -Values @{"Number" = "10"} + // Currency: -Values @{"Currency" = "10"} + // Date and Time: -Values @{"DateAndTime" = "03/13/2015 14:16"} + // Lookup (id of lookup value): -Values @{"Lookup" = "2"} + // Multi value lookup (id of lookup values as array 1): -Values @{"MultiLookupField" = "1","2"} + // Multi value lookup (id of lookup values as array 2): -Values @{"MultiLookupField" = 1,2} + // Multi value lookup (id of lookup values as string): -Values @{"MultiLookupField" = "1,2"} + // Yes/No: -Values @{"YesNo" = $false} + // Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{"Person" = "user1@domain.com","21"} + // Managed Metadata (single value with path to term): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE"} + // Managed Metadata (single value with id of term): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818"} with Id of term + // Managed Metadata (multiple values with paths to terms): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE","CORPORATE|DEPARTMENTS|HR"} + // Managed Metadata (multiple values with ids of terms): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818","52d88107-c2a8-4bf0-adfa-04bc2305b593"} + // Hyperlink or Picture: -Values @{"Hyperlink" = "https://github.com/OfficeDev/, OfficePnp"} + var values = ""; + // From Cmdlet Help: The list relative URL of a folder. E.g. "MyFolder" for a folder located in the root of the list, or "MyFolder/SubFolder" for a folder located in the MyFolder folder which is located in the root of the list. + var folder = ""; + // From Cmdlet Help: The name of the retention label. + var label = ""; + + var results = scope.ExecuteCommand("Add-PnPListItem", + new CommandParameter("List", list), + new CommandParameter("ContentType", contentType), + new CommandParameter("Values", values), + new CommandParameter("Folder", folder), + new CommandParameter("Label", label)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/AddPnPViewTests.cs b/Tests/Lists/AddPnPViewTests.cs new file mode 100644 index 000000000..1c3971d29 --- /dev/null +++ b/Tests/Lists/AddPnPViewTests.cs @@ -0,0 +1,107 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class AddViewTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPViewTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The title of the view. + var title = ""; + // From Cmdlet Help: A valid CAML Query. + var query = ""; + // This is a mandatory parameter + // From Cmdlet Help: A list of fields to add. + var fields = ""; + // From Cmdlet Help: The type of view to add. + var viewType = ""; + // From Cmdlet Help: The row limit for the view. Defaults to 30. + var rowLimit = ""; + // From Cmdlet Help: If specified, a personal view will be created. + var personal = ""; + // From Cmdlet Help: If specified, the view will be set as the default view for the list. + var setAsDefault = ""; + // From Cmdlet Help: If specified, the view will have paging. + var paged = ""; + // From Cmdlet Help: A valid XML fragment containing one or more Aggregations + var aggregations = ""; + + var results = scope.ExecuteCommand("Add-PnPView", + new CommandParameter("List", list), + new CommandParameter("Title", title), + new CommandParameter("Query", query), + new CommandParameter("Fields", fields), + new CommandParameter("ViewType", viewType), + new CommandParameter("RowLimit", rowLimit), + new CommandParameter("Personal", personal), + new CommandParameter("SetAsDefault", setAsDefault), + new CommandParameter("Paged", paged), + new CommandParameter("Aggregations", aggregations)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/ClearPnPDefaultColumnValuesTests.cs b/Tests/Lists/ClearPnPDefaultColumnValuesTests.cs new file mode 100644 index 000000000..729565d4e --- /dev/null +++ b/Tests/Lists/ClearPnPDefaultColumnValuesTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class ClearDefaultColumnValuesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ClearPnPDefaultColumnValuesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Name or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The internal name, id or a reference to a field + var field = ""; + // From Cmdlet Help: A library relative folder path, if not specified it will set the default column values on the root folder of the library ('/') + var folder = ""; + + var results = scope.ExecuteCommand("Clear-PnPDefaultColumnValues", + new CommandParameter("List", list), + new CommandParameter("Field", field), + new CommandParameter("Folder", folder)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/GetPnPDefaultColumnValuesTests.cs b/Tests/Lists/GetPnPDefaultColumnValuesTests.cs new file mode 100644 index 000000000..061c1e753 --- /dev/null +++ b/Tests/Lists/GetPnPDefaultColumnValuesTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class GetDefaultColumnValuesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPDefaultColumnValuesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Name or Url of the list. + var list = ""; + + var results = scope.ExecuteCommand("Get-PnPDefaultColumnValues", + new CommandParameter("List", list)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/GetPnPListItemTests.cs b/Tests/Lists/GetPnPListItemTests.cs new file mode 100644 index 000000000..405a2b773 --- /dev/null +++ b/Tests/Lists/GetPnPListItemTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class GetListItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPListItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The list to query + var list = ""; + // From Cmdlet Help: The ID of the item to retrieve + var id = ""; + // From Cmdlet Help: The unique id (GUID) of the item to retrieve + var uniqueId = ""; + // From Cmdlet Help: The CAML query to execute against the list + var query = ""; + // From Cmdlet Help: The server relative URL of a list folder from which results will be returned. + var folderServerRelativeUrl = ""; + // From Cmdlet Help: The fields to retrieve. If not specified all fields will be loaded in the returned list object. + var fields = ""; + // From Cmdlet Help: The number of items to retrieve per page request. + var pageSize = ""; + // From Cmdlet Help: The script block to run after every page request. + var scriptBlock = ""; + + var results = scope.ExecuteCommand("Get-PnPListItem", + new CommandParameter("List", list), + new CommandParameter("Id", id), + new CommandParameter("UniqueId", uniqueId), + new CommandParameter("Query", query), + new CommandParameter("FolderServerRelativeUrl", folderServerRelativeUrl), + new CommandParameter("Fields", fields), + new CommandParameter("PageSize", pageSize), + new CommandParameter("ScriptBlock", scriptBlock)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/GetPnPListTests.cs b/Tests/Lists/GetPnPListTests.cs new file mode 100644 index 000000000..3c7461310 --- /dev/null +++ b/Tests/Lists/GetPnPListTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class GetListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The ID, name or Url (Lists/MyList) of the list + var identity = ""; + // From Cmdlet Help: Switch parameter if an exception should be thrown if the requested list does not exist (true) or if omitted, nothing will be returned in case the list does not exist + var throwExceptionIfListNotFound = ""; + + var results = scope.ExecuteCommand("Get-PnPList", + new CommandParameter("Identity", identity), + new CommandParameter("ThrowExceptionIfListNotFound", throwExceptionIfListNotFound)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/GetPnPViewTests.cs b/Tests/Lists/GetPnPViewTests.cs new file mode 100644 index 000000000..1e32b50bb --- /dev/null +++ b/Tests/Lists/GetPnPViewTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class GetViewTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPViewTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list. + var list = ""; + // From Cmdlet Help: The ID or name of the view + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPView", + new CommandParameter("List", list), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/MovePnPListItemToRecycleBinTests.cs b/Tests/Lists/MovePnPListItemToRecycleBinTests.cs new file mode 100644 index 000000000..d54d211e0 --- /dev/null +++ b/Tests/Lists/MovePnPListItemToRecycleBinTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class MoveListItemToRecycleBinTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MovePnPListItemToRecycleBinTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Move-PnPListItemToRecycleBin", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/NewPnPListTests.cs b/Tests/Lists/NewPnPListTests.cs new file mode 100644 index 000000000..b5a7920cc --- /dev/null +++ b/Tests/Lists/NewPnPListTests.cs @@ -0,0 +1,100 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class NewListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Title of the list + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: The type of list to create. + var template = ""; + // From Cmdlet Help: If set, will override the url of the list. + var url = ""; + // From Cmdlet Help: Switch parameter if list should be hidden from the SharePoint UI + var hidden = ""; + // From Cmdlet Help: Switch parameter if versioning should be enabled + var enableVersioning = ""; + // From Cmdlet Help: Obsolete + var quickLaunchOptions = ""; + // From Cmdlet Help: Switch parameter if content types should be enabled on this list + var enableContentTypes = ""; + // From Cmdlet Help: Switch parameter if this list should be visible on the QuickLaunch + var onQuickLaunch = ""; + + var results = scope.ExecuteCommand("New-PnPList", + new CommandParameter("Title", title), + new CommandParameter("Template", template), + new CommandParameter("Url", url), + new CommandParameter("Hidden", hidden), + new CommandParameter("EnableVersioning", enableVersioning), + new CommandParameter("QuickLaunchOptions", quickLaunchOptions), + new CommandParameter("EnableContentTypes", enableContentTypes), + new CommandParameter("OnQuickLaunch", onQuickLaunch)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/RemovePnPListItemTests.cs b/Tests/Lists/RemovePnPListItemTests.cs new file mode 100644 index 000000000..378c23201 --- /dev/null +++ b/Tests/Lists/RemovePnPListItemTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class RemoveListItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPListItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + var recycle = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPListItem", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Recycle", recycle), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/RemovePnPListTests.cs b/Tests/Lists/RemovePnPListTests.cs new file mode 100644 index 000000000..eb51d6d48 --- /dev/null +++ b/Tests/Lists/RemovePnPListTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class RemoveListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Title of the list. + var identity = ""; + // From Cmdlet Help: Defines if the list should be moved to recycle bin or directly deleted. + var recycle = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPList", + new CommandParameter("Identity", identity), + new CommandParameter("Recycle", recycle), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/RemovePnPViewTests.cs b/Tests/Lists/RemovePnPViewTests.cs new file mode 100644 index 000000000..bf72ea488 --- /dev/null +++ b/Tests/Lists/RemovePnPViewTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class RemoveViewTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPViewTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Title of the view. + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID or Url of the list. + var list = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPView", + new CommandParameter("Identity", identity), + new CommandParameter("List", list), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/RequestPnPReIndexListTests.cs b/Tests/Lists/RequestPnPReIndexListTests.cs new file mode 100644 index 000000000..31620fdae --- /dev/null +++ b/Tests/Lists/RequestPnPReIndexListTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class RequestReIndexListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RequestPnPReIndexListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var identity = ""; + + var results = scope.ExecuteCommand("Request-PnPReIndexList", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/SetPnPDefaultColumnValuesTests.cs b/Tests/Lists/SetPnPDefaultColumnValuesTests.cs new file mode 100644 index 000000000..50887f675 --- /dev/null +++ b/Tests/Lists/SetPnPDefaultColumnValuesTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class SetDefaultColumnValuesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPDefaultColumnValuesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Name or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The internal name, id or a reference to a field + var field = ""; + // This is a mandatory parameter + // From Cmdlet Help: A list of values. In case of a text field the values will be concatenated, separated by a semi-colon. In case of a taxonomy field multiple values will added. In case of people field multiple values will be added. + var value = ""; + // From Cmdlet Help: A library relative folder path, if not specified it will set the default column values on the root folder of the library ('/') + var folder = ""; + + var results = scope.ExecuteCommand("Set-PnPDefaultColumnValues", + new CommandParameter("List", list), + new CommandParameter("Field", field), + new CommandParameter("Value", value), + new CommandParameter("Folder", folder)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/SetPnPListItemPermissionTests.cs b/Tests/Lists/SetPnPListItemPermissionTests.cs new file mode 100644 index 000000000..085dcf52c --- /dev/null +++ b/Tests/Lists/SetPnPListItemPermissionTests.cs @@ -0,0 +1,103 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class SetListItemPermissionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListItemPermissionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + // This is a mandatory parameter + var group = ""; + // This is a mandatory parameter + var user = ""; + // From Cmdlet Help: The role that must be assigned to the group or user + var addRole = ""; + // From Cmdlet Help: The role that must be removed from the group or user + var removeRole = ""; + // From Cmdlet Help: Clear all existing permissions + var clearExisting = ""; + // From Cmdlet Help: Inherit permissions from the list, removing unique permissions + var inheritPermissions = ""; + // From Cmdlet Help: Update the item permissions without creating a new version or triggering MS Flow. + var systemUpdate = ""; + + var results = scope.ExecuteCommand("Set-PnPListItemPermission", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("Group", group), + new CommandParameter("User", user), + new CommandParameter("AddRole", addRole), + new CommandParameter("RemoveRole", removeRole), + new CommandParameter("ClearExisting", clearExisting), + new CommandParameter("InheritPermissions", inheritPermissions), + new CommandParameter("SystemUpdate", systemUpdate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/SetPnPListItemTests.cs b/Tests/Lists/SetPnPListItemTests.cs new file mode 100644 index 000000000..9213ed169 --- /dev/null +++ b/Tests/Lists/SetPnPListItemTests.cs @@ -0,0 +1,113 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class SetListItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + // From Cmdlet Help: Specify either the name, ID or an actual content type + var contentType = ""; + // From Cmdlet Help: Use the internal names of the fields when specifying field names. + // Single line of text: -Values @{"TextField" = "Title New"} + // Multiple lines of text: -Values @{"MultiTextField" = "New text\n\nMore text"} + // Rich text: -Values @{"MultiTextField" = "New text"} + // Choice: -Values @{"ChoiceField" = "Value 1"} + // Number: -Values @{"NumberField" = "10"} + // Currency: -Values @{"NumberField" = "10"} + // Currency: -Values @{"CurrencyField" = "10"} + // Date and Time: -Values @{"DateAndTimeField" = "03/13/2015 14:16"} + // Lookup (id of lookup value): -Values @{"LookupField" = "2"} + // Multi value lookup (id of lookup values as array 1): -Values @{"MultiLookupField" = "1","2"} + // Multi value lookup (id of lookup values as array 2): -Values @{"MultiLookupField" = 1,2} + // Multi value lookup (id of lookup values as string): -Values @{"MultiLookupField" = "1,2"} + // Yes/No: -Values @{"YesNoField" = $false} + // Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{"PersonField" = "user1@domain.com","21"} + // Managed Metadata (single value with path to term): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE"} + // Managed Metadata (single value with id of term): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818"} with Id of term + // Managed Metadata (multiple values with paths to terms): -Values @{"MetadataField" = ("CORPORATE|DEPARTMENTS|FINANCE","CORPORATE|DEPARTMENTS|HR")} + // Managed Metadata (multiple values with ids of terms): -Values @{"MetadataField" = ("fe40a95b-2144-4fa2-b82a-0b3d0299d818","52d88107-c2a8-4bf0-adfa-04bc2305b593")} + // Hyperlink or Picture: -Values @{"HyperlinkField" = "https://github.com/OfficeDev/, OfficePnp"} + var values = ""; + // From Cmdlet Help: Update the item without creating a new version. + var systemUpdate = ""; + // From Cmdlet Help: The name of the retention label. + var label = ""; + + var results = scope.ExecuteCommand("Set-PnPListItem", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("ContentType", contentType), + new CommandParameter("Values", values), + new CommandParameter("SystemUpdate", systemUpdate), + new CommandParameter("Label", label)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/SetPnPListPermissionTests.cs b/Tests/Lists/SetPnPListPermissionTests.cs new file mode 100644 index 000000000..7c96ff1d1 --- /dev/null +++ b/Tests/Lists/SetPnPListPermissionTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class SetListPermissionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListPermissionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID or Title of the list. + var identity = ""; + // This is a mandatory parameter + var group = ""; + // This is a mandatory parameter + var user = ""; + // From Cmdlet Help: The role that must be assigned to the group or user + var addRole = ""; + // From Cmdlet Help: The role that must be removed from the group or user + var removeRole = ""; + + var results = scope.ExecuteCommand("Set-PnPListPermission", + new CommandParameter("Identity", identity), + new CommandParameter("Group", group), + new CommandParameter("User", user), + new CommandParameter("AddRole", addRole), + new CommandParameter("RemoveRole", removeRole)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Lists/SetPnPListTests.cs b/Tests/Lists/SetPnPListTests.cs new file mode 100644 index 000000000..17a1bded0 --- /dev/null +++ b/Tests/Lists/SetPnPListTests.cs @@ -0,0 +1,129 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Lists +{ + [TestClass] + public class SetListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var identity = ""; + // From Cmdlet Help: Set to $true to enable content types, set to $false to disable content types + var enableContentTypes = ""; + // From Cmdlet Help: If used the security inheritance is broken for this list + var breakRoleInheritance = ""; + // From Cmdlet Help: If used the security inheritance is reset for this list (inherited from parent) + var resetRoleInheritance = ""; + // From Cmdlet Help: If used the roles are copied from the parent web + var copyRoleAssignments = ""; + // From Cmdlet Help: If used the unique permissions are cleared from child objects and they can inherit role assignments from this object + var clearSubscopeVars = ""; + // From Cmdlet Help: The title of the list + var title = ""; + // From Cmdlet Help: The description of the list + var description = ""; + // From Cmdlet Help: Hide the list from the SharePoint UI. Set to $true to hide, $false to show. + var hidden = ""; + // From Cmdlet Help: Enable or disable force checkout. Set to $true to enable, $false to disable. + var forceCheckoutVar = ""; + // From Cmdlet Help: Set the list experience: Auto, NewExperience or ClassicExperience + var listExperience = ""; + // From Cmdlet Help: Enable or disable attachments. Set to $true to enable, $false to disable. + var enableAttachments = ""; + // From Cmdlet Help: Enable or disable folder creation. Set to $true to enable, $false to disable. + var enableFolderCreation = ""; + // From Cmdlet Help: Enable or disable versioning. Set to $true to enable, $false to disable. + var enableVersioning = ""; + // From Cmdlet Help: Enable or disable minor versions versioning. Set to $true to enable, $false to disable. + var enableMinorVersions = ""; + // From Cmdlet Help: Maximum major versions to keep + var majorVersions = ""; + // From Cmdlet Help: Maximum minor versions to keep + var minorVersions = ""; + // From Cmdlet Help: Enable or disable whether content approval is enabled for the list. Set to $true to enable, $false to disable. + var enableModeration = ""; + + var results = scope.ExecuteCommand("Set-PnPList", + new CommandParameter("Identity", identity), + new CommandParameter("EnableContentTypes", enableContentTypes), + new CommandParameter("BreakRoleInheritance", breakRoleInheritance), + new CommandParameter("ResetRoleInheritance", resetRoleInheritance), + new CommandParameter("CopyRoleAssignments", copyRoleAssignments), + new CommandParameter("ClearSubscopes", clearSubscopeVars), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Hidden", hidden), + new CommandParameter("ForceCheckout", forceCheckoutVar), + new CommandParameter("ListExperience", listExperience), + new CommandParameter("EnableAttachments", enableAttachments), + new CommandParameter("EnableFolderCreation", enableFolderCreation), + new CommandParameter("EnableVersioning", enableVersioning), + new CommandParameter("EnableMinorVersions", enableMinorVersions), + new CommandParameter("MajorVersions", majorVersions), + new CommandParameter("MinorVersions", minorVersions), + new CommandParameter("EnableModeration", enableModeration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPManagementApiAccessTokenTests.cs b/Tests/ManagementApi/GetPnPManagementApiAccessTokenTests.cs new file mode 100644 index 000000000..54e6c6490 --- /dev/null +++ b/Tests/ManagementApi/GetPnPManagementApiAccessTokenTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetManagementApiAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPManagementApiAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Tenant ID to connect to the Office 365 Management API + var tenantId = ""; + // This is a mandatory parameter + // From Cmdlet Help: The App\Client ID of the app which gives you access to the Office 365 Management API + var clientId = ""; + // This is a mandatory parameter + // From Cmdlet Help: The Client Secret of the app which gives you access to the Office 365 Management API + var clientSecret = ""; + + var results = scope.ExecuteCommand("Get-PnPManagementApiAccessToken", + new CommandParameter("TenantId", tenantId), + new CommandParameter("ClientId", clientId), + new CommandParameter("ClientSecret", clientSecret)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPOffice365CurrentServiceStatusTests.cs b/Tests/ManagementApi/GetPnPOffice365CurrentServiceStatusTests.cs new file mode 100644 index 000000000..db998bf6b --- /dev/null +++ b/Tests/ManagementApi/GetPnPOffice365CurrentServiceStatusTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetOffice365CurrentServiceStatusTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOffice365CurrentServiceStatusTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Allows retrieval of the current service status of only one particular service. If not provided, the current service status of all services will be returned. + var workload = ""; + + var results = scope.ExecuteCommand("Get-PnPOffice365CurrentServiceStatus", + new CommandParameter("Workload", workload)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPOffice365HistoricalServiceStatusTests.cs b/Tests/ManagementApi/GetPnPOffice365HistoricalServiceStatusTests.cs new file mode 100644 index 000000000..8771152f5 --- /dev/null +++ b/Tests/ManagementApi/GetPnPOffice365HistoricalServiceStatusTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetOffice365HistoricalServiceStatusTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOffice365HistoricalServiceStatusTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Allows retrieval of the historical service status of only one particular service. If not provided, the historical service status of all services will be returned. + var workload = ""; + + var results = scope.ExecuteCommand("Get-PnPOffice365HistoricalServiceStatus", + new CommandParameter("Workload", workload)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPOffice365ServiceMessageTests.cs b/Tests/ManagementApi/GetPnPOffice365ServiceMessageTests.cs new file mode 100644 index 000000000..1ce98f798 --- /dev/null +++ b/Tests/ManagementApi/GetPnPOffice365ServiceMessageTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetOffice365ServiceMessageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOffice365ServiceMessageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Allows retrieval of the service messages for only one particular service. If not provided, the service messages of all services will be returned. + var workload = ""; + + var results = scope.ExecuteCommand("Get-PnPOffice365ServiceMessage", + new CommandParameter("Workload", workload)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPOffice365ServicesTests.cs b/Tests/ManagementApi/GetPnPOffice365ServicesTests.cs new file mode 100644 index 000000000..977f1ff9a --- /dev/null +++ b/Tests/ManagementApi/GetPnPOffice365ServicesTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetOffice365ServicesTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOffice365ServicesTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPOffice365Services"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPOfficeManagementApiAccessTokenTests.cs b/Tests/ManagementApi/GetPnPOfficeManagementApiAccessTokenTests.cs new file mode 100644 index 000000000..8b30bdb59 --- /dev/null +++ b/Tests/ManagementApi/GetPnPOfficeManagementApiAccessTokenTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetOfficeManagementApiAccessTokenTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPOfficeManagementApiAccessTokenTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns the access token in a decoded manner + var decoded = ""; + + var results = scope.ExecuteCommand("Get-PnPOfficeManagementApiAccessToken", + new CommandParameter("Decoded", decoded)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/ManagementApi/GetPnPUnifiedAuditLogTests.cs b/Tests/ManagementApi/GetPnPUnifiedAuditLogTests.cs new file mode 100644 index 000000000..d5ebaf952 --- /dev/null +++ b/Tests/ManagementApi/GetPnPUnifiedAuditLogTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.ManagementApi +{ + [TestClass] + public class GetUnifiedAuditLogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPUnifiedAuditLogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Content type of logs to be retrieved, should be one of the following: AzureActiveDirectory, Exchange, SharePoint, General, DLP. + var contentType = ""; + // From Cmdlet Help: Start time of logs to be retrieved. Start time and end time must both be specified (or both omitted) and must be less than or equal to 24 hours apart, with the start time prior to end time and start time no more than 7 days in the past. + var startTime = ""; + // From Cmdlet Help: End time of logs to be retrieved. Start time and end time must both be specified (or both omitted) and must be less than or equal to 24 hours apart. + var endTime = ""; + + var results = scope.ExecuteCommand("Get-PnPUnifiedAuditLog", + new CommandParameter("ContentType", contentType), + new CommandParameter("StartTime", startTime), + new CommandParameter("EndTime", endTime)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/AdminTests.cs b/Tests/OriginalTests/AdminTests.cs similarity index 100% rename from Tests/AdminTests.cs rename to Tests/OriginalTests/AdminTests.cs diff --git a/Tests/BaseTests.cs b/Tests/OriginalTests/BaseTests.cs similarity index 100% rename from Tests/BaseTests.cs rename to Tests/OriginalTests/BaseTests.cs diff --git a/Tests/BrandingTests.cs b/Tests/OriginalTests/BrandingTests.cs similarity index 100% rename from Tests/BrandingTests.cs rename to Tests/OriginalTests/BrandingTests.cs diff --git a/Tests/ClientSidePagesTests.cs b/Tests/OriginalTests/ClientSidePagesTests.cs similarity index 100% rename from Tests/ClientSidePagesTests.cs rename to Tests/OriginalTests/ClientSidePagesTests.cs diff --git a/Tests/ContentTypeTests.cs b/Tests/OriginalTests/ContentTypeTests.cs similarity index 100% rename from Tests/ContentTypeTests.cs rename to Tests/OriginalTests/ContentTypeTests.cs diff --git a/Tests/DiagnosticTests.cs b/Tests/OriginalTests/DiagnosticTests.cs similarity index 100% rename from Tests/DiagnosticTests.cs rename to Tests/OriginalTests/DiagnosticTests.cs diff --git a/Tests/EventReceiverTests.cs b/Tests/OriginalTests/EventReceiverTests.cs similarity index 100% rename from Tests/EventReceiverTests.cs rename to Tests/OriginalTests/EventReceiverTests.cs diff --git a/Tests/FeatureTests.cs b/Tests/OriginalTests/FeatureTests.cs similarity index 100% rename from Tests/FeatureTests.cs rename to Tests/OriginalTests/FeatureTests.cs diff --git a/Tests/FieldsTests.cs b/Tests/OriginalTests/FieldsTests.cs similarity index 100% rename from Tests/FieldsTests.cs rename to Tests/OriginalTests/FieldsTests.cs diff --git a/Tests/FilesTest.cs b/Tests/OriginalTests/FilesTest.cs similarity index 96% rename from Tests/FilesTest.cs rename to Tests/OriginalTests/FilesTest.cs index d1c1d5e06..df3beee64 100644 --- a/Tests/FilesTest.cs +++ b/Tests/OriginalTests/FilesTest.cs @@ -12,15 +12,15 @@ namespace SharePointPnP.PowerShell.Tests [TestClass] public class FilesTests { - private string _site1Id; - private string _site2Id; - private string _site1Url; - private string _site2Url; - private string _site1RelativeUrl; - private string _site2RelativeUrl; + private static string _site1Id; + private static string _site2Id; + private static string _site1Url; + private static string _site2Url; + private static string _site1RelativeUrl; + private static string _site2RelativeUrl; - private string Site1RelativeFolderUrl + private static string Site1RelativeFolderUrl { get { @@ -52,12 +52,13 @@ private string Site2RelativeFolderUrl private const string EmptyFolderName = "EmptyFolder"; private const string TargetFileNameWithAmpersand = "Test & file.txt"; private const string TargetFileNameWithHashtag = "Test & file.txt"; - - [TestInitialize] - public void Initialize() + + [ClassInitialize] + public static void Initialize(TestContext testContext) { using (var ctx = TestCommon.CreateClientContext()) { + _site1Id = Guid.NewGuid().ToString(); _site2Id = Guid.NewGuid().ToString(); @@ -130,15 +131,16 @@ public void Initialize() } - [TestCleanup] - public void Cleanup() + [ClassCleanup] + public static void Cleanup() { using (var ctx = TestCommon.CreateTenantClientContext()) { Tenant tenant = new Tenant(ctx); - tenant.DeleteSiteCollection(_site1Url, false); - tenant.DeleteSiteCollection(_site2Url, false); + // For any accidents lets allow for recoverability + tenant.DeleteSiteCollection(_site1Url, true); + tenant.DeleteSiteCollection(_site2Url, true); } } diff --git a/Tests/GraphTests.cs b/Tests/OriginalTests/GraphTests.cs similarity index 67% rename from Tests/GraphTests.cs rename to Tests/OriginalTests/GraphTests.cs index aae6275ed..3ccb6e23c 100644 --- a/Tests/GraphTests.cs +++ b/Tests/OriginalTests/GraphTests.cs @@ -16,14 +16,14 @@ public void Initialize() { var random = new Random(); - var group = scope.ExecuteCommand("New-PnPUnifiedGroup", - new CommandParameter("DisplayName", "PnPDeletedUnifiedGroup test"), - new CommandParameter("Description", "PnPDeletedUnifiedGroup test"), + var group = scope.ExecuteCommand("New-PnPMicrosoft365Group", + new CommandParameter("DisplayName", "PnPDeletedMicrosoft365Group test"), + new CommandParameter("Description", "PnPDeletedMicrosoft365Group test"), new CommandParameter("MailNickname", $"pnp-unit-test-{random.Next(1, 1000)}"), new CommandParameter("Force")); _groupId = group[0].Properties["GroupId"].Value.ToString(); - scope.ExecuteCommand("Remove-PnPUnifiedGroup", new CommandParameter("Identity", _groupId)); + scope.ExecuteCommand("Remove-PnPMicrosoft365Group", new CommandParameter("Identity", _groupId)); } } @@ -34,7 +34,7 @@ public void Cleanup() { try { - scope.ExecuteCommand("Remove-PnPUnifiedGroup", new CommandParameter("Identity", _groupId)); + scope.ExecuteCommand("Remove-PnPMicrosoft365Group", new CommandParameter("Identity", _groupId)); } catch (Exception) { @@ -42,7 +42,7 @@ public void Cleanup() } try { - scope.ExecuteCommand("Remove-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); + scope.ExecuteCommand("Remove-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId)); } catch (Exception) { @@ -52,49 +52,49 @@ public void Cleanup() } [TestMethod] - public void GetDeletedUnifiedGroups() + public void GetDeletedMicrosoft365Groups() { using (var scope = new PSTestScope()) { - var results = scope.ExecuteCommand("Get-PnPDeletedUnifiedGroup"); + var results = scope.ExecuteCommand("Get-PnPDeletedMicrosoft365Group"); Assert.IsTrue(results.Count > 0); } } [TestMethod] - public void GetDeletedUnifiedGroup() + public void GetDeletedMicrosoft365Group() { using (var scope = new PSTestScope()) { - var results = scope.ExecuteCommand("Get-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); + var results = scope.ExecuteCommand("Get-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId)); Assert.IsTrue(results != null && results[0].Properties["GroupId"].Value.ToString() == _groupId); } } [TestMethod] - public void RestoreDeletedUnifiedGroup() + public void RestoreDeletedMicrosoft365Group() { using (var scope = new PSTestScope()) { - scope.ExecuteCommand("Restore-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); - var results = scope.ExecuteCommand("Get-PnPUnifiedGroup", new CommandParameter("Identity", _groupId)); + scope.ExecuteCommand("Restore-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId)); + var results = scope.ExecuteCommand("Get-PnPMicrosoft365Group", new CommandParameter("Identity", _groupId)); Assert.IsTrue(results != null && results[0].Properties["GroupId"].Value.ToString() == _groupId); } } [TestMethod] - public void RemoveDeletedUnifiedGroup() + public void RemoveDeletedMicrosoft365Group() { using (var scope = new PSTestScope()) { - scope.ExecuteCommand("Remove-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); + scope.ExecuteCommand("Remove-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId)); // The group should no longer be found in deleted groups try { - var results = scope.ExecuteCommand("Get-PnPDeletedUnifiedGroup", new CommandParameter("Identity", _groupId)); + var results = scope.ExecuteCommand("Get-PnPDeletedMicrosoft365Group", new CommandParameter("Identity", _groupId)); Assert.IsFalse(results != null); } catch (Exception) diff --git a/Tests/InvokeWebActionTest.cs b/Tests/OriginalTests/InvokeWebActionTest.cs similarity index 100% rename from Tests/InvokeWebActionTest.cs rename to Tests/OriginalTests/InvokeWebActionTest.cs diff --git a/Tests/ListDataRowProvisioningTemplate.cs b/Tests/OriginalTests/ListDataRowProvisioningTemplate.cs similarity index 100% rename from Tests/ListDataRowProvisioningTemplate.cs rename to Tests/OriginalTests/ListDataRowProvisioningTemplate.cs diff --git a/Tests/ListsTests.cs b/Tests/OriginalTests/ListsTests.cs similarity index 100% rename from Tests/ListsTests.cs rename to Tests/OriginalTests/ListsTests.cs diff --git a/Tests/PrincipalsTests.cs b/Tests/OriginalTests/PrincipalsTests.cs similarity index 100% rename from Tests/PrincipalsTests.cs rename to Tests/OriginalTests/PrincipalsTests.cs diff --git a/Tests/ProvisioningTemplateFromFolderTest.cs b/Tests/OriginalTests/ProvisioningTemplateFromFolderTest.cs similarity index 100% rename from Tests/ProvisioningTemplateFromFolderTest.cs rename to Tests/OriginalTests/ProvisioningTemplateFromFolderTest.cs diff --git a/Tests/ProvisioningTemplateTests.cs b/Tests/OriginalTests/ProvisioningTemplateTests.cs similarity index 100% rename from Tests/ProvisioningTemplateTests.cs rename to Tests/OriginalTests/ProvisioningTemplateTests.cs diff --git a/Tests/WebPartsTests.cs b/Tests/OriginalTests/WebPartsTests.cs similarity index 100% rename from Tests/WebPartsTests.cs rename to Tests/OriginalTests/WebPartsTests.cs diff --git a/Tests/WebTests.cs b/Tests/OriginalTests/WebTests.cs similarity index 100% rename from Tests/WebTests.cs rename to Tests/OriginalTests/WebTests.cs diff --git a/Tests/WebhookSubscriptionsTests.cs b/Tests/OriginalTests/WebhookSubscriptionsTests.cs similarity index 100% rename from Tests/WebhookSubscriptionsTests.cs rename to Tests/OriginalTests/WebhookSubscriptionsTests.cs diff --git a/Tests/Principals/AddPnPAlertTests.cs b/Tests/Principals/AddPnPAlertTests.cs new file mode 100644 index 000000000..abf5917f4 --- /dev/null +++ b/Tests/Principals/AddPnPAlertTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class AddAlertTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPAlertTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // From Cmdlet Help: Alert title + var title = ""; + // From Cmdlet Help: User to create the alert for (User ID, login name or actual User object). Skip this parameter to create an alert for the current user. Note: Only site owners can create alerts for other users. + var user = ""; + // From Cmdlet Help: Alert delivery method + var deliveryMethod = ""; + // From Cmdlet Help: Alert change type + var changeType = ""; + // From Cmdlet Help: Alert frequency + var frequency = ""; + // From Cmdlet Help: Alert filter + var filter = ""; + // From Cmdlet Help: Alert time (if frequency is not immediate) + var time = ""; + + var results = scope.ExecuteCommand("Add-PnPAlert", + new CommandParameter("List", list), + new CommandParameter("Title", title), + new CommandParameter("User", user), + new CommandParameter("DeliveryMethod", deliveryMethod), + new CommandParameter("ChangeType", changeType), + new CommandParameter("Frequency", frequency), + new CommandParameter("Filter", filter), + new CommandParameter("Time", time)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/AddPnPUserToGroupTests.cs b/Tests/Principals/AddPnPUserToGroupTests.cs new file mode 100644 index 000000000..c279b1f7f --- /dev/null +++ b/Tests/Principals/AddPnPUserToGroupTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class AddUserToGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPUserToGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The login name of the user + var loginName = ""; + // This is a mandatory parameter + // From Cmdlet Help: The group id, group name or group object to add the user to. + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: The email address of the user + var emailAddress = ""; + var sendEmail = ""; + var emailBody = ""; + + var results = scope.ExecuteCommand("Add-PnPUserToGroup", + new CommandParameter("LoginName", loginName), + new CommandParameter("Identity", identity), + new CommandParameter("EmailAddress", emailAddress), + new CommandParameter("SendEmail", sendEmail), + new CommandParameter("EmailBody", emailBody)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/GetPnPAlertTests.cs b/Tests/Principals/GetPnPAlertTests.cs new file mode 100644 index 000000000..7e6ccf825 --- /dev/null +++ b/Tests/Principals/GetPnPAlertTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class GetAlertTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAlertTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // From Cmdlet Help: User to retrieve the alerts for (User ID, login name or actual User object). Skip this parameter to retrieve the alerts for the current user. Note: Only site owners can retrieve alerts for other users. + var user = ""; + // From Cmdlet Help: Retrieve alerts with this title. Title comparison is case sensitive. + var title = ""; + + var results = scope.ExecuteCommand("Get-PnPAlert", + new CommandParameter("List", list), + new CommandParameter("User", user), + new CommandParameter("Title", title)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/GetPnPGroupMembersTests.cs b/Tests/Principals/GetPnPGroupMembersTests.cs new file mode 100644 index 000000000..15ae17d41 --- /dev/null +++ b/Tests/Principals/GetPnPGroupMembersTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class GetGroupMembersTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPGroupMembersTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: A group object, an ID or a name of a group + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPGroupMembers", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/GetPnPGroupPermissionsTests.cs b/Tests/Principals/GetPnPGroupPermissionsTests.cs new file mode 100644 index 000000000..7525a995e --- /dev/null +++ b/Tests/Principals/GetPnPGroupPermissionsTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class GetGroupPermissionsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPGroupPermissionsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Get the permissions of a specific group by name + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPGroupPermissions", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/GetPnPGroupTests.cs b/Tests/Principals/GetPnPGroupTests.cs new file mode 100644 index 000000000..d5b0c2988 --- /dev/null +++ b/Tests/Principals/GetPnPGroupTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class GetGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Get a specific group by name + var identity = ""; + // From Cmdlet Help: Retrieve the associated member group + var associatedMemberGroup = ""; + // From Cmdlet Help: Retrieve the associated visitor group + var associatedVisitorGroup = ""; + // From Cmdlet Help: Retrieve the associated owner group + var associatedOwnerGroup = ""; + + var results = scope.ExecuteCommand("Get-PnPGroup", + new CommandParameter("Identity", identity), + new CommandParameter("AssociatedMemberGroup", associatedMemberGroup), + new CommandParameter("AssociatedVisitorGroup", associatedVisitorGroup), + new CommandParameter("AssociatedOwnerGroup", associatedOwnerGroup)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/GetPnPUserTests.cs b/Tests/Principals/GetPnPUserTests.cs new file mode 100644 index 000000000..e4cf05e80 --- /dev/null +++ b/Tests/Principals/GetPnPUserTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class GetUserTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPUserTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: User ID or login name + var identity = ""; + // From Cmdlet Help: If provided, only users that currently have any kinds of access rights assigned to the current site collection will be returned. Otherwise all users, even those who previously had rights assigned, but not anymore at the moment, will be returned as the information is pulled from the User Information List. Only works if you don't provide an -Identity. + var withRightsAssigned = ""; + + var results = scope.ExecuteCommand("Get-PnPUser", + new CommandParameter("Identity", identity), + new CommandParameter("WithRightsAssigned", withRightsAssigned)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/NewPnPGroupTests.cs b/Tests/Principals/NewPnPGroupTests.cs new file mode 100644 index 000000000..90ad8852f --- /dev/null +++ b/Tests/Principals/NewPnPGroupTests.cs @@ -0,0 +1,104 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class NewGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Title of the group + var title = ""; + // From Cmdlet Help: The description for the group + var description = ""; + // From Cmdlet Help: The owner for the group, which can be a user or another group + var owner = ""; + // From Cmdlet Help: A switch parameter that specifies whether to allow users to request membership in the group and to allow users to request to leave the group + var allowRequestToJoinLeave = ""; + // From Cmdlet Help: A switch parameter that specifies whether users are automatically added or removed when they make a request + var autoAcceptRequestToJoinLeave = ""; + // From Cmdlet Help: A switch parameter that specifies whether group members can modify membership in the group + var allowMembersEditMembership = ""; + // From Cmdlet Help: A switch parameter that specifies whether only group members are allowed to view the list of members in the group + var onlyAllowMembersViewMembership = ""; + // From Cmdlet Help: A switch parameter that disallows group members to view membership. + var disallowMembersViewMembership = ""; + // From Cmdlet Help: The e-mail address to which membership requests are sent + var requestToJoinEmail = ""; + var setAssociatedGroup = ""; + + var results = scope.ExecuteCommand("New-PnPGroup", + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Owner", owner), + new CommandParameter("AllowRequestToJoinLeave", allowRequestToJoinLeave), + new CommandParameter("AutoAcceptRequestToJoinLeave", autoAcceptRequestToJoinLeave), + new CommandParameter("AllowMembersEditMembership", allowMembersEditMembership), + new CommandParameter("OnlyAllowMembersViewMembership", onlyAllowMembersViewMembership), + new CommandParameter("DisallowMembersViewMembership", disallowMembersViewMembership), + new CommandParameter("RequestToJoinEmail", requestToJoinEmail), + new CommandParameter("SetAssociatedGroup", setAssociatedGroup)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/NewPnPUserTests.cs b/Tests/Principals/NewPnPUserTests.cs new file mode 100644 index 000000000..f5fe7406f --- /dev/null +++ b/Tests/Principals/NewPnPUserTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class NewUserTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPUserTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The users login name (user@company.com) + var loginName = ""; + + var results = scope.ExecuteCommand("New-PnPUser", + new CommandParameter("LoginName", loginName)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/RemovePnPAlertTests.cs b/Tests/Principals/RemovePnPAlertTests.cs new file mode 100644 index 000000000..6d63a2811 --- /dev/null +++ b/Tests/Principals/RemovePnPAlertTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class RemoveAlertTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPAlertTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: User to remove the alert for (User ID, login name or actual User object). Skip this parameter to use the current user. Note: Only site owners can remove alerts for other users. + var user = ""; + // This is a mandatory parameter + // From Cmdlet Help: The alert id, or the actual alert object to remove. + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPAlert", + new CommandParameter("User", user), + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/RemovePnPGroupTests.cs b/Tests/Principals/RemovePnPGroupTests.cs new file mode 100644 index 000000000..cf0a9f539 --- /dev/null +++ b/Tests/Principals/RemovePnPGroupTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class RemoveGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: A group object, an ID or a name of a group to remove + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPGroup", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/RemovePnPUserFromGroupTests.cs b/Tests/Principals/RemovePnPUserFromGroupTests.cs new file mode 100644 index 000000000..2ffd2a762 --- /dev/null +++ b/Tests/Principals/RemovePnPUserFromGroupTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class RemoveUserFromGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPUserFromGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: A valid login name of a user (user@company.com) + var loginName = ""; + // This is a mandatory parameter + // From Cmdlet Help: A group object, an ID or a name of a group + var identity = ""; + + var results = scope.ExecuteCommand("Remove-PnPUserFromGroup", + new CommandParameter("LoginName", loginName), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/RemovePnPUserTests.cs b/Tests/Principals/RemovePnPUserTests.cs new file mode 100644 index 000000000..9109166fc --- /dev/null +++ b/Tests/Principals/RemovePnPUserTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class RemoveUserTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPUserTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: User ID or login name + var identity = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question + var force = ""; + // From Cmdlet Help: Specifying the Confirm parameter will allow the confirmation question to be skipped + var confirm = ""; + + var results = scope.ExecuteCommand("Remove-PnPUser", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force), + new CommandParameter("Confirm", confirm)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/SetPnPGroupPermissionsTests.cs b/Tests/Principals/SetPnPGroupPermissionsTests.cs new file mode 100644 index 000000000..89737119c --- /dev/null +++ b/Tests/Principals/SetPnPGroupPermissionsTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class SetGroupPermissionsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPGroupPermissionsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Get the permissions of a specific group by name + var identity = ""; + // From Cmdlet Help: The list to apply the command to. + var list = ""; + // From Cmdlet Help: Name of the permission set to add to this SharePoint group + var addRole = ""; + // From Cmdlet Help: Name of the permission set to remove from this SharePoint group + var removeRole = ""; + + var results = scope.ExecuteCommand("Set-PnPGroupPermissions", + new CommandParameter("Identity", identity), + new CommandParameter("List", list), + new CommandParameter("AddRole", addRole), + new CommandParameter("RemoveRole", removeRole)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Principals/SetPnPGroupTests.cs b/Tests/Principals/SetPnPGroupTests.cs new file mode 100644 index 000000000..e0183c61a --- /dev/null +++ b/Tests/Principals/SetPnPGroupTests.cs @@ -0,0 +1,111 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Principals +{ + [TestClass] + public class SetGroupTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPGroupTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: A group object, an ID or a name of a group + var identity = ""; + // From Cmdlet Help: One of the associated group types (Visitors, Members, Owners + var setAssociatedGroup = ""; + // From Cmdlet Help: Name of the permission set to add to this SharePoint group + var addRole = ""; + // From Cmdlet Help: Name of the permission set to remove from this SharePoint group + var removeRole = ""; + // From Cmdlet Help: The title for the group + var title = ""; + // From Cmdlet Help: The owner for the group, which can be a user or another group + var owner = ""; + // From Cmdlet Help: The description for the group + var description = ""; + // From Cmdlet Help: A switch parameter that specifies whether to allow users to request membership in the group and to allow users to request to leave the group + var allowRequestToJoinLeave = ""; + // From Cmdlet Help: A switch parameter that specifies whether users are automatically added or removed when they make a request + var autoAcceptRequestToJoinLeave = ""; + // From Cmdlet Help: A switch parameter that specifies whether group members can modify membership in the group + var allowMembersEditMembership = ""; + // From Cmdlet Help: A switch parameter that specifies whether only group members are allowed to view the list of members in the group + var onlyAllowMembersViewMembership = ""; + // From Cmdlet Help: The e-mail address to which membership requests are sent + var requestToJoinEmail = ""; + + var results = scope.ExecuteCommand("Set-PnPGroup", + new CommandParameter("Identity", identity), + new CommandParameter("SetAssociatedGroup", setAssociatedGroup), + new CommandParameter("AddRole", addRole), + new CommandParameter("RemoveRole", removeRole), + new CommandParameter("Title", title), + new CommandParameter("Owner", owner), + new CommandParameter("Description", description), + new CommandParameter("AllowRequestToJoinLeave", allowRequestToJoinLeave), + new CommandParameter("AutoAcceptRequestToJoinLeave", autoAcceptRequestToJoinLeave), + new CommandParameter("AllowMembersEditMembership", allowMembersEditMembership), + new CommandParameter("OnlyAllowMembersViewMembership", onlyAllowMembersViewMembership), + new CommandParameter("RequestToJoinEmail", requestToJoinEmail)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/AddPnPDataRowsToProvisioningTemplateTests.cs b/Tests/Provisioning.Site/AddPnPDataRowsToProvisioningTemplateTests.cs new file mode 100644 index 000000000..faf0f716c --- /dev/null +++ b/Tests/Provisioning.Site/AddPnPDataRowsToProvisioningTemplateTests.cs @@ -0,0 +1,97 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class AddDataRowsToProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPDataRowsToProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Filename of the .PNP Open XML site template to read from, optionally including full path. + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: The list to query + var list = ""; + // From Cmdlet Help: The CAML query to execute against the list. Defaults to all items. + var query = ""; + // From Cmdlet Help: The fields to retrieve. If not specified all fields will be loaded in the returned list object. + var fields = ""; + // From Cmdlet Help: A switch to include ObjectSecurity information. + var includeSecurity = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while loading the template. + var templateProviderExtensions = ""; + // From Cmdlet Help: If set, this switch will try to tokenize the values with web and site related tokens + var tokenizeUrls = ""; + + var results = scope.ExecuteCommand("Add-PnPDataRowsToProvisioningTemplate", + new CommandParameter("Path", path), + new CommandParameter("List", list), + new CommandParameter("Query", query), + new CommandParameter("Fields", fields), + new CommandParameter("IncludeSecurity", includeSecurity), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions), + new CommandParameter("TokenizeUrls", tokenizeUrls)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/AddPnPFileToProvisioningTemplateTests.cs b/Tests/Provisioning.Site/AddPnPFileToProvisioningTemplateTests.cs new file mode 100644 index 000000000..8f23a2570 --- /dev/null +++ b/Tests/Provisioning.Site/AddPnPFileToProvisioningTemplateTests.cs @@ -0,0 +1,102 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class AddFileToProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPFileToProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Filename of the .PNP Open XML site template to read from, optionally including full path. + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: The file to add to the in-memory template, optionally including full path. + var source = ""; + // This is a mandatory parameter + // From Cmdlet Help: The file to add to the in-memory template, specifying its url in the current connected Web. + var sourceUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: The target Folder for the file to add to the in-memory template. + var folder = ""; + // From Cmdlet Help: The target Container for the file to add to the in-memory template, optional argument. + var container = ""; + // From Cmdlet Help: The level of the files to add. Defaults to Published + var fileLevel = ""; + // From Cmdlet Help: Set to overwrite in site, Defaults to true + var fileOverwrite = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while loading the template. + var templateProviderExtensions = ""; + + var results = scope.ExecuteCommand("Add-PnPFileToProvisioningTemplate", + new CommandParameter("Path", path), + new CommandParameter("Source", source), + new CommandParameter("SourceUrl", sourceUrl), + new CommandParameter("Folder", folder), + new CommandParameter("Container", container), + new CommandParameter("FileLevel", fileLevel), + new CommandParameter("FileOverwrite", fileOverwrite), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/AddPnPListFoldersToProvisioningTemplateTests.cs b/Tests/Provisioning.Site/AddPnPListFoldersToProvisioningTemplateTests.cs new file mode 100644 index 000000000..ea1a2d20e --- /dev/null +++ b/Tests/Provisioning.Site/AddPnPListFoldersToProvisioningTemplateTests.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class AddListFoldersToProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPListFoldersToProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Filename of the .PNP Open XML site template to read from, optionally including full path. + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: The list to query + var list = ""; + // From Cmdlet Help: A switch parameter to include all folders in the list, or just top level folders. + var recursive = ""; + // From Cmdlet Help: A switch to include ObjectSecurity information. + var includeSecurity = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while loading the template. + var templateProviderExtensions = ""; + + var results = scope.ExecuteCommand("Add-PnPListFoldersToProvisioningTemplate", + new CommandParameter("Path", path), + new CommandParameter("List", list), + new CommandParameter("Recursive", recursive), + new CommandParameter("IncludeSecurity", includeSecurity), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/ApplyPnPProvisioningTemplateTests.cs b/Tests/Provisioning.Site/ApplyPnPProvisioningTemplateTests.cs new file mode 100644 index 000000000..37aed0a5e --- /dev/null +++ b/Tests/Provisioning.Site/ApplyPnPProvisioningTemplateTests.cs @@ -0,0 +1,117 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class ApplyProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ApplyPnPProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the xml or pnp file containing the provisioning template. + var path = ""; + // From Cmdlet Help: ID of the template to use from the xml file containing the provisioning template. If not specified and multiple ProvisioningTemplate elements exist, the last one will be used. + var templateId = ""; + // From Cmdlet Help: Root folder where resources/files that are being referenced in the template are located. If not specified the same folder as where the provisioning template is located will be used. + var resourceFolder = ""; + // From Cmdlet Help: Specify this parameter if you want to overwrite and/or create properties that are known to be system entries (starting with vti_, dlc_, etc.) + var overwriteSystemPropertyBagValues = ""; + // From Cmdlet Help: Ignore duplicate data row errors when the data row in the template already exists. + var ignoreDuplicateDataRowErrors = ""; + // From Cmdlet Help: If set content types will be provisioned if the target web is a subweb. + var provisionContentTypesToSubWebs = ""; + // From Cmdlet Help: If set fields will be provisioned if the target web is a subweb. + var provisionFieldsToSubWebs = ""; + // From Cmdlet Help: Override the RemoveExistingNodes attribute in the Navigation elements of the template. If you specify this value the navigation nodes will always be removed before adding the nodes in the template + var clearNavigation = ""; + // From Cmdlet Help: Allows you to specify parameters that can be referred to in the template by means of the {parameter:} token. See examples on how to use this parameter. + var parameters = ""; + // From Cmdlet Help: Allows you to only process a specific part of the template. Notice that this might fail, as some of the handlers require other artifacts in place if they are not part of what your applying. Visit https://docs.microsoft.com/dotnet/api/officedevpnp.core.framework.provisioning.model.handlers for possible values. + var handlers = ""; + // From Cmdlet Help: Allows you to run all handlers, excluding the ones specified. + var excludeHandlers = ""; + // From Cmdlet Help: Allows you to specify ExtensbilityHandlers to execute while applying a template + var extensibilityHandlers = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while applying a template. + var templateProviderExtensions = ""; + // From Cmdlet Help: Allows you to provide an in-memory instance of the ProvisioningTemplate type of the PnP Core Component. When using this parameter, the -Path parameter refers to the path of any supporting file for the template. + var inputInstance = ""; + + var results = scope.ExecuteCommand("Apply-PnPProvisioningTemplate", + new CommandParameter("Path", path), + new CommandParameter("TemplateId", templateId), + new CommandParameter("ResourceFolder", resourceFolder), + new CommandParameter("OverwriteSystemPropertyBagValues", overwriteSystemPropertyBagValues), + new CommandParameter("IgnoreDuplicateDataRowErrors", ignoreDuplicateDataRowErrors), + new CommandParameter("ProvisionContentTypesToSubWebs", provisionContentTypesToSubWebs), + new CommandParameter("ProvisionFieldsToSubWebs", provisionFieldsToSubWebs), + new CommandParameter("ClearNavigation", clearNavigation), + new CommandParameter("Parameters", parameters), + new CommandParameter("Handlers", handlers), + new CommandParameter("ExcludeHandlers", excludeHandlers), + new CommandParameter("ExtensibilityHandlers", extensibilityHandlers), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions), + new CommandParameter("InputInstance", inputInstance)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/ExportPnPListToProvisioningTemplateTests.cs b/Tests/Provisioning.Site/ExportPnPListToProvisioningTemplateTests.cs new file mode 100644 index 000000000..70dec9037 --- /dev/null +++ b/Tests/Provisioning.Site/ExportPnPListToProvisioningTemplateTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class ExportListToProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ExportPnPListToProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specify the lists to extract, either providing their ID or their Title. + var list = ""; + // From Cmdlet Help: Filename to write to, optionally including full path + var outVar = ""; + // From Cmdlet Help: The schema of the output to use, defaults to the latest schema + var schema = ""; + // From Cmdlet Help: Overwrites the output file if it exists. + var force = ""; + // From Cmdlet Help: Returns the template as an in-memory object, which is an instance of the ProvisioningTemplate type of the PnP Core Component. It cannot be used together with the -Out parameter. + var outVarputInstance = ""; + + var results = scope.ExecuteCommand("Export-PnPListToProvisioningTemplate", + new CommandParameter("List", list), + new CommandParameter("Out", outVar), + new CommandParameter("Schema", schema), + new CommandParameter("Force", force), + new CommandParameter("OutputInstance", outVarputInstance)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/GetPnPProvisioningTemplateTests.cs b/Tests/Provisioning.Site/GetPnPProvisioningTemplateTests.cs new file mode 100644 index 000000000..91c068a9f --- /dev/null +++ b/Tests/Provisioning.Site/GetPnPProvisioningTemplateTests.cs @@ -0,0 +1,167 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class GetProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Filename to write to, optionally including full path + var outVar = ""; + // From Cmdlet Help: The schema of the output to use, defaults to the latest schema + var schema = ""; + // From Cmdlet Help: If specified, all term groups will be included. Overrides IncludeSiteCollectionTermGroup. + var includeAllTermGroups = ""; + // From Cmdlet Help: If specified, all the site collection term groups will be included. Overridden by IncludeAllTermGroups. + var includeSiteCollectionTermGroup = ""; + // From Cmdlet Help: If specified all site groups will be included. + var includeSiteGroups = ""; + // From Cmdlet Help: If specified all the managers and contributors of term groups will be included. + var includeTermGroupsSecurity = ""; + // From Cmdlet Help: If specified the template will contain the current search configuration of the site. + var includeSearchConfiguration = ""; + // From Cmdlet Help: If specified the files used for masterpages, sitelogo, alternate CSS and the files that make up the composed look will be saved. + var persistBrandingFiles = ""; + // From Cmdlet Help: If specified the files making up the composed look (background image, font file and color file) will be saved. + var persistComposedLookFiles = ""; + // From Cmdlet Help: If specified the files used for the publishing feature will be saved. + var persistPublishingFiles = ""; + // From Cmdlet Help: If specified, out of the box / native publishing files will be saved. + var includeNativePublishingFiles = ""; + // From Cmdlet Help: If specified hidden lists will be included in the template + var includeHiddenLists = ""; + // From Cmdlet Help: If specified all client side pages will be included + var includeAllClientSidePages = ""; + // From Cmdlet Help: During extraction the version of the server will be checked for certain actions. If you specify this switch, this check will be skipped. + var skipVersionCheck = ""; + // From Cmdlet Help: If specified, resource values for applicable artifacts will be persisted to a resource file + var persistMultiLanguageResources = ""; + // From Cmdlet Help: If specified, resource files will be saved with the specified prefix instead of using the template name specified. If no template name is specified the files will be called PnP-Resources..resx. See examples for more info. + var resourceFilePrefix = ""; + // From Cmdlet Help: Allows you to only process a specific type of artifact in the site. Notice that this might result in a non-working template, as some of the handlers require other artifacts in place if they are not part of what your extracting. For possible values for this parameter visit https://docs.microsoft.com/dotnet/api/officedevpnp.core.framework.provisioning.model.handlers + var handlers = ""; + // From Cmdlet Help: Allows you to run all handlers, excluding the ones specified. + var excludeHandlers = ""; + // From Cmdlet Help: Allows you to specify ExtensibilityHandlers to execute while extracting a template. + var extensibilityHandlers = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while extracting a template. + var templateProviderExtensions = ""; + // From Cmdlet Help: Allows you to specify from which content type group(s) the content types should be included into the template. + var contentTypeGroups = ""; + // From Cmdlet Help: Overwrites the output file if it exists. + var force = ""; + // From Cmdlet Help: Exports the template without the use of a base template, causing all OOTB artifacts to be included. Using this switch is generally not required/recommended. + var noBaseTemplate = ""; + // From Cmdlet Help: The encoding type of the XML file, Unicode is default + var encoding = ""; + // From Cmdlet Help: It can be used to specify the DisplayName of the template file that will be extracted. + var templateDisplayName = ""; + // From Cmdlet Help: It can be used to specify the ImagePreviewUrl of the template file that will be extracted. + var templateImagePreviewUrl = ""; + // From Cmdlet Help: It can be used to specify custom Properties for the template file that will be extracted. + var templateProperties = ""; + // From Cmdlet Help: Returns the template as an in-memory object, which is an instance of the ProvisioningTemplate type of the PnP Core Component. It cannot be used together with the -Out parameter. + var outVarputInstance = ""; + // From Cmdlet Help: Specify whether or not content types issued from a content hub should be exported. By default, these content types are included. + var excludeContentTypesFromSyndication = ""; + // From Cmdlet Help: Specify the lists to extract, either providing their ID or their Title. + var listsToExtract = ""; + // From Cmdlet Help: Specify a JSON configuration file to configure the extraction progress. + var configuration = ""; + + var results = scope.ExecuteCommand("Get-PnPProvisioningTemplate", + new CommandParameter("Out", outVar), + new CommandParameter("Schema", schema), + new CommandParameter("IncludeAllTermGroups", includeAllTermGroups), + new CommandParameter("IncludeSiteCollectionTermGroup", includeSiteCollectionTermGroup), + new CommandParameter("IncludeSiteGroups", includeSiteGroups), + new CommandParameter("IncludeTermGroupsSecurity", includeTermGroupsSecurity), + new CommandParameter("IncludeSearchConfiguration", includeSearchConfiguration), + new CommandParameter("PersistBrandingFiles", persistBrandingFiles), + new CommandParameter("PersistComposedLookFiles", persistComposedLookFiles), + new CommandParameter("PersistPublishingFiles", persistPublishingFiles), + new CommandParameter("IncludeNativePublishingFiles", includeNativePublishingFiles), + new CommandParameter("IncludeHiddenLists", includeHiddenLists), + new CommandParameter("IncludeAllClientSidePages", includeAllClientSidePages), + new CommandParameter("SkipVersionCheck", skipVersionCheck), + new CommandParameter("PersistMultiLanguageResources", persistMultiLanguageResources), + new CommandParameter("ResourceFilePrefix", resourceFilePrefix), + new CommandParameter("Handlers", handlers), + new CommandParameter("ExcludeHandlers", excludeHandlers), + new CommandParameter("ExtensibilityHandlers", extensibilityHandlers), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions), + new CommandParameter("ContentTypeGroups", contentTypeGroups), + new CommandParameter("Force", force), + new CommandParameter("NoBaseTemplate", noBaseTemplate), + new CommandParameter("Encoding", encoding), + new CommandParameter("TemplateDisplayName", templateDisplayName), + new CommandParameter("TemplateImagePreviewUrl", templateImagePreviewUrl), + new CommandParameter("TemplateProperties", templateProperties), + new CommandParameter("OutputInstance", outVarputInstance), + new CommandParameter("ExcludeContentTypesFromSyndication", excludeContentTypesFromSyndication), + new CommandParameter("ListsToExtract", listsToExtract), + new CommandParameter("Configuration", configuration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/GetPnPTenantTemplateTests.cs b/Tests/Provisioning.Site/GetPnPTenantTemplateTests.cs new file mode 100644 index 000000000..e8ed92c71 --- /dev/null +++ b/Tests/Provisioning.Site/GetPnPTenantTemplateTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class GetTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var siteUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Filename to write to, optionally including full path + var outVar = ""; + // From Cmdlet Help: Overwrites the output file if it exists. + var force = ""; + // This is a mandatory parameter + // From Cmdlet Help: Returns the template as an in-memory object, which is an instance of the ProvisioningHierarchy type of the PnP Core Component. It cannot be used together with the -Out parameter. + var asInstance = ""; + // From Cmdlet Help: Specify a JSON configuration file to configure the extraction progress. + var configuration = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantTemplate", + new CommandParameter("SiteUrl", siteUrl), + new CommandParameter("Out", outVar), + new CommandParameter("Force", force), + new CommandParameter("AsInstance", asInstance), + new CommandParameter("Configuration", configuration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/RemovePnPFileFromProvisioningTemplateTests.cs b/Tests/Provisioning.Site/RemovePnPFileFromProvisioningTemplateTests.cs new file mode 100644 index 000000000..f923a754b --- /dev/null +++ b/Tests/Provisioning.Site/RemovePnPFileFromProvisioningTemplateTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class RemoveFileFromProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPFileFromProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Filename to read the template from, optionally including full path. + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: The relative File Path of the file to remove from the in-memory template + var filePath = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while saving the template. + var templateProviderExtensions = ""; + + var results = scope.ExecuteCommand("Remove-PnPFileFromProvisioningTemplate", + new CommandParameter("Path", path), + new CommandParameter("FilePath", filePath), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Site/SetPnPProvisioningTemplateMetadataTests.cs b/Tests/Provisioning.Site/SetPnPProvisioningTemplateMetadataTests.cs new file mode 100644 index 000000000..8f7c5ec1f --- /dev/null +++ b/Tests/Provisioning.Site/SetPnPProvisioningTemplateMetadataTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Site +{ + [TestClass] + public class SetProvisioningTemplateMetadataTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPProvisioningTemplateMetadataTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the xml or pnp file containing the site template. + var path = ""; + // From Cmdlet Help: It can be used to specify the DisplayName of the template file that will be updated. + var templateDisplayName = ""; + // From Cmdlet Help: It can be used to specify the ImagePreviewUrl of the template file that will be updated. + var templateImagePreviewUrl = ""; + // From Cmdlet Help: It can be used to specify custom Properties for the template file that will be updated. + var templateProperties = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while extracting a template. + var templateProviderExtensions = ""; + + var results = scope.ExecuteCommand("Set-PnPProvisioningTemplateMetadata", + new CommandParameter("Path", path), + new CommandParameter("TemplateDisplayName", templateDisplayName), + new CommandParameter("TemplateImagePreviewUrl", templateImagePreviewUrl), + new CommandParameter("TemplateProperties", templateProperties), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/AddPnPProvisioningTemplateTests.cs b/Tests/Provisioning.Tenant/AddPnPProvisioningTemplateTests.cs new file mode 100644 index 000000000..dbb49a7e5 --- /dev/null +++ b/Tests/Provisioning.Tenant/AddPnPProvisioningTemplateTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class AddProvisioningTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPProvisioningTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The template to add to the tenant template + var siteTemplate = ""; + // This is a mandatory parameter + // From Cmdlet Help: The tenant template to add the template to + var tenantTemplate = ""; + + var results = scope.ExecuteCommand("Add-PnPProvisioningTemplate", + new CommandParameter("SiteTemplate", siteTemplate), + new CommandParameter("TenantTemplate", tenantTemplate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/AddPnPTenantSequenceSiteTests.cs b/Tests/Provisioning.Tenant/AddPnPTenantSequenceSiteTests.cs new file mode 100644 index 000000000..882b521a3 --- /dev/null +++ b/Tests/Provisioning.Tenant/AddPnPTenantSequenceSiteTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class AddTenantSequenceSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTenantSequenceSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var site = ""; + // This is a mandatory parameter + // From Cmdlet Help: The sequence to add the site to + var sequence = ""; + + var results = scope.ExecuteCommand("Add-PnPTenantSequenceSite", + new CommandParameter("Site", site), + new CommandParameter("Sequence", sequence)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/AddPnPTenantSequenceSubSiteTests.cs b/Tests/Provisioning.Tenant/AddPnPTenantSequenceSubSiteTests.cs new file mode 100644 index 000000000..085646385 --- /dev/null +++ b/Tests/Provisioning.Tenant/AddPnPTenantSequenceSubSiteTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class AddTenantSequenceSubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTenantSequenceSubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The subsite to add + var subSite = ""; + // This is a mandatory parameter + // From Cmdlet Help: The site to add the subsite to + var site = ""; + + var results = scope.ExecuteCommand("Add-PnPTenantSequenceSubSite", + new CommandParameter("SubSite", subSite), + new CommandParameter("Site", site)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/AddPnPTenantSequenceTests.cs b/Tests/Provisioning.Tenant/AddPnPTenantSequenceTests.cs new file mode 100644 index 000000000..003d17ef7 --- /dev/null +++ b/Tests/Provisioning.Tenant/AddPnPTenantSequenceTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class AddTenantSequenceTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTenantSequenceTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The template to add the sequence to + var template = ""; + // This is a mandatory parameter + // From Cmdlet Help: Optional Id of the sequence + var sequence = ""; + + var results = scope.ExecuteCommand("Add-PnPTenantSequence", + new CommandParameter("Template", template), + new CommandParameter("Sequence", sequence)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/ApplyPnPTenantTemplateTests.cs b/Tests/Provisioning.Tenant/ApplyPnPTenantTemplateTests.cs new file mode 100644 index 000000000..812a1b42a --- /dev/null +++ b/Tests/Provisioning.Tenant/ApplyPnPTenantTemplateTests.cs @@ -0,0 +1,119 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class ApplyTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ApplyPnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the xml or pnp file containing the tenant template. + var path = ""; + // This is a mandatory parameter + var template = ""; + var sequenceId = ""; + // From Cmdlet Help: Root folder where resources/files that are being referenced in the template are located. If not specified the same folder as where the tenant template is located will be used. + var resourceFolder = ""; + // From Cmdlet Help: Allows you to only process a specific part of the template. Notice that this might fail, as some of the handlers require other artifacts in place if they are not part of what your applying. + var handlers = ""; + // From Cmdlet Help: Allows you to run all handlers, excluding the ones specified. + var excludeHandlers = ""; + // From Cmdlet Help: Allows you to specify ExtensbilityHandlers to execute while applying a template + var extensibilityHandlers = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while applying a template. + var templateProviderExtensions = ""; + // From Cmdlet Help: Allows you to specify parameters that can be referred to in the tenant template by means of the {parameter:} token. See examples on how to use this parameter. + var parameters = ""; + // From Cmdlet Help: Specify this parameter if you want to overwrite and/or create properties that are known to be system entries (starting with vti_, dlc_, etc.) + var overwriteSystemPropertyBagValues = ""; + // From Cmdlet Help: Ignore duplicate data row errors when the data row in the template already exists. + var ignoreDuplicateDataRowErrors = ""; + // From Cmdlet Help: If set content types will be provisioned if the target web is a subweb. + var provisionContentTypesToSubWebs = ""; + // From Cmdlet Help: If set fields will be provisioned if the target web is a subweb. + var provisionFieldsToSubWebs = ""; + // From Cmdlet Help: Override the RemoveExistingNodes attribute in the Navigation elements of the template. If you specify this value the navigation nodes will always be removed before adding the nodes in the template + var clearNavigation = ""; + // From Cmdlet Help: Specify a JSON configuration file to configure the extraction progress. + var configuration = ""; + + var results = scope.ExecuteCommand("Apply-PnPTenantTemplate", + new CommandParameter("Path", path), + new CommandParameter("Template", template), + new CommandParameter("SequenceId", sequenceId), + new CommandParameter("ResourceFolder", resourceFolder), + new CommandParameter("Handlers", handlers), + new CommandParameter("ExcludeHandlers", excludeHandlers), + new CommandParameter("ExtensibilityHandlers", extensibilityHandlers), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions), + new CommandParameter("Parameters", parameters), + new CommandParameter("OverwriteSystemPropertyBagValues", overwriteSystemPropertyBagValues), + new CommandParameter("IgnoreDuplicateDataRowErrors", ignoreDuplicateDataRowErrors), + new CommandParameter("ProvisionContentTypesToSubWebs", provisionContentTypesToSubWebs), + new CommandParameter("ProvisionFieldsToSubWebs", provisionFieldsToSubWebs), + new CommandParameter("ClearNavigation", clearNavigation), + new CommandParameter("Configuration", configuration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/ExportPnPClientSidePageTests.cs b/Tests/Provisioning.Tenant/ExportPnPClientSidePageTests.cs new file mode 100644 index 000000000..5dacd48ae --- /dev/null +++ b/Tests/Provisioning.Tenant/ExportPnPClientSidePageTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class ExportClientSidePageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ExportPnPClientSidePageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page + var identity = ""; + // From Cmdlet Help: If specified referenced files will be exported to the current folder. + var persistBrandingFiles = ""; + // From Cmdlet Help: If specified the template will be saved to the file specified with this parameter. + var outVar = ""; + // From Cmdlet Help: Specify to override the question to overwrite a file if it already exists. + var force = ""; + // From Cmdlet Help: Specify a JSON configuration file to configure the extraction progress. + var configuration = ""; + + var results = scope.ExecuteCommand("Export-PnPClientSidePage", + new CommandParameter("Identity", identity), + new CommandParameter("PersistBrandingFiles", persistBrandingFiles), + new CommandParameter("Out", outVar), + new CommandParameter("Force", force), + new CommandParameter("Configuration", configuration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/GetPnPTenantSequenceSiteTests.cs b/Tests/Provisioning.Tenant/GetPnPTenantSequenceSiteTests.cs new file mode 100644 index 000000000..f8df3b170 --- /dev/null +++ b/Tests/Provisioning.Tenant/GetPnPTenantSequenceSiteTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class GetTenantSequenceSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantSequenceSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The sequence to retrieve the site from + var sequence = ""; + // From Cmdlet Help: Optional Id of the site + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantSequenceSite", + new CommandParameter("Sequence", sequence), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/GetPnPTenantSequenceTests.cs b/Tests/Provisioning.Tenant/GetPnPTenantSequenceTests.cs new file mode 100644 index 000000000..c17256bfd --- /dev/null +++ b/Tests/Provisioning.Tenant/GetPnPTenantSequenceTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class GetTenantSequenceTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantSequenceTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The template to retrieve the sequence from + var template = ""; + // From Cmdlet Help: Optional Id of the sequence + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPTenantSequence", + new CommandParameter("Template", template), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantSequenceCommunicationSiteTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantSequenceCommunicationSiteTests.cs new file mode 100644 index 000000000..996ac4356 --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantSequenceCommunicationSiteTests.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantSequenceCommunicationSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSequenceCommunicationSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var url = ""; + // This is a mandatory parameter + var title = ""; + var language = ""; + var owner = ""; + var description = ""; + var classification = ""; + var siteDesignId = ""; + var hubSite = ""; + var allowFileSharingForGuestUsers = ""; + var templateIds = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSequenceCommunicationSite", + new CommandParameter("Url", url), + new CommandParameter("Title", title), + new CommandParameter("Language", language), + new CommandParameter("Owner", owner), + new CommandParameter("Description", description), + new CommandParameter("Classification", classification), + new CommandParameter("SiteDesignId", siteDesignId), + new CommandParameter("HubSite", hubSite), + new CommandParameter("AllowFileSharingForGuestUsers", allowFileSharingForGuestUsers), + new CommandParameter("TemplateIds", templateIds)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSiteTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSiteTests.cs new file mode 100644 index 000000000..89d4b738f --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSiteTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantSequenceTeamNoGroupSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSequenceTeamNoGroupSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var url = ""; + // This is a mandatory parameter + var title = ""; + // This is a mandatory parameter + var timeZoneId = ""; + var language = ""; + var owner = ""; + var description = ""; + var hubSite = ""; + var templateIds = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSequenceTeamNoGroupSite", + new CommandParameter("Url", url), + new CommandParameter("Title", title), + new CommandParameter("TimeZoneId", timeZoneId), + new CommandParameter("Language", language), + new CommandParameter("Owner", owner), + new CommandParameter("Description", description), + new CommandParameter("HubSite", hubSite), + new CommandParameter("TemplateIds", templateIds)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSubSiteTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSubSiteTests.cs new file mode 100644 index 000000000..c056b4cb3 --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamNoGroupSubSiteTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantSequenceTeamNoGroupSubSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSequenceTeamNoGroupSubSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var url = ""; + // This is a mandatory parameter + var title = ""; + // This is a mandatory parameter + var timeZoneId = ""; + var language = ""; + var description = ""; + var templateIds = ""; + var quickLaunchDisabled = ""; + var useDifferentPermissionsFromParentSite = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSequenceTeamNoGroupSubSite", + new CommandParameter("Url", url), + new CommandParameter("Title", title), + new CommandParameter("TimeZoneId", timeZoneId), + new CommandParameter("Language", language), + new CommandParameter("Description", description), + new CommandParameter("TemplateIds", templateIds), + new CommandParameter("QuickLaunchDisabled", quickLaunchDisabled), + new CommandParameter("UseDifferentPermissionsFromParentSite", useDifferentPermissionsFromParentSite)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamSiteTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamSiteTests.cs new file mode 100644 index 000000000..5499ed7eb --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTeamSiteTests.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantSequenceTeamSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSequenceTeamSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var alias = ""; + // This is a mandatory parameter + var title = ""; + var description = ""; + var displayName = ""; + var classification = ""; + var publicVar = ""; + var hubSite = ""; + var templateIds = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSequenceTeamSite", + new CommandParameter("Alias", alias), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("DisplayName", displayName), + new CommandParameter("Classification", classification), + new CommandParameter("Public", publicVar), + new CommandParameter("HubSite", hubSite), + new CommandParameter("TemplateIds", templateIds)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantSequenceTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTests.cs new file mode 100644 index 000000000..b1c2f8eb0 --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantSequenceTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantSequenceTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantSequenceTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Optional Id of the sequence + var id = ""; + + var results = scope.ExecuteCommand("New-PnPTenantSequence", + new CommandParameter("Id", id)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/NewPnPTenantTemplateTests.cs b/Tests/Provisioning.Tenant/NewPnPTenantTemplateTests.cs new file mode 100644 index 000000000..7d3b34a16 --- /dev/null +++ b/Tests/Provisioning.Tenant/NewPnPTenantTemplateTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class NewTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var author = ""; + var description = ""; + var displayName = ""; + var generator = ""; + + var results = scope.ExecuteCommand("New-PnPTenantTemplate", + new CommandParameter("Author", author), + new CommandParameter("Description", description), + new CommandParameter("DisplayName", displayName), + new CommandParameter("Generator", generator)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/ReadPnPTenantTemplateTests.cs b/Tests/Provisioning.Tenant/ReadPnPTenantTemplateTests.cs new file mode 100644 index 000000000..6f810a3e9 --- /dev/null +++ b/Tests/Provisioning.Tenant/ReadPnPTenantTemplateTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class ReadTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ReadPnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Filename to read from, optionally including full path. + var path = ""; + // From Cmdlet Help: Allows you to specify ITemplateProviderExtension to execute while loading the template. + var templateProviderExtensions = ""; + + var results = scope.ExecuteCommand("Read-PnPTenantTemplate", + new CommandParameter("Path", path), + new CommandParameter("TemplateProviderExtensions", templateProviderExtensions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/SavePnPTenantTemplateTests.cs b/Tests/Provisioning.Tenant/SavePnPTenantTemplateTests.cs new file mode 100644 index 000000000..9e918e2eb --- /dev/null +++ b/Tests/Provisioning.Tenant/SavePnPTenantTemplateTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class SaveTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SavePnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Allows you to provide an in-memory instance of a Tenant Template or a filename of a template file in XML format. When using this parameter, the -Out parameter refers to the path for saving the template and storing any supporting file for the template. + var template = ""; + // This is a mandatory parameter + // From Cmdlet Help: Filename to write to, optionally including full path. + var outVar = ""; + // From Cmdlet Help: The optional schema to use when creating the PnP file. Always defaults to the latest schema. + var schema = ""; + // From Cmdlet Help: Specifying the Force parameter will skip the confirmation question. + var force = ""; + + var results = scope.ExecuteCommand("Save-PnPTenantTemplate", + new CommandParameter("Template", template), + new CommandParameter("Out", outVar), + new CommandParameter("Schema", schema), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Provisioning.Tenant/TestPnPTenantTemplateTests.cs b/Tests/Provisioning.Tenant/TestPnPTenantTemplateTests.cs new file mode 100644 index 000000000..5508eadc3 --- /dev/null +++ b/Tests/Provisioning.Tenant/TestPnPTenantTemplateTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Provisioning.Tenant +{ + [TestClass] + public class TestTenantTemplateTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void TestPnPTenantTemplateTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The in-memory template to test + var template = ""; + + var results = scope.ExecuteCommand("Test-PnPTenantTemplate", + new CommandParameter("Template", template)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPHtmlPublishingPageLayoutTests.cs b/Tests/Publishing/AddPnPHtmlPublishingPageLayoutTests.cs new file mode 100644 index 000000000..5ed11885b --- /dev/null +++ b/Tests/Publishing/AddPnPHtmlPublishingPageLayoutTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddHtmlPublishingPageLayoutTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPHtmlPublishingPageLayoutTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the file which will be uploaded + var sourceFilePath = ""; + // This is a mandatory parameter + // From Cmdlet Help: Title for the page layout + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: Description for the page layout + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: Associated content type ID + var associatedContentTypeID = ""; + // From Cmdlet Help: Folder hierarchy where the HTML page layouts will be deployed + var destinationFolderHierarchy = ""; + + var results = scope.ExecuteCommand("Add-PnPHtmlPublishingPageLayout", + new CommandParameter("SourceFilePath", sourceFilePath), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("AssociatedContentTypeID", associatedContentTypeID), + new CommandParameter("DestinationFolderHierarchy", destinationFolderHierarchy)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPMasterPageTests.cs b/Tests/Publishing/AddPnPMasterPageTests.cs new file mode 100644 index 000000000..75473a56d --- /dev/null +++ b/Tests/Publishing/AddPnPMasterPageTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddMasterPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPMasterPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the file which will be uploaded + var sourceFilePath = ""; + // This is a mandatory parameter + // From Cmdlet Help: Title for the Masterpage + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: Description for the Masterpage + var description = ""; + // From Cmdlet Help: Folder hierarchy where the MasterPage will be deployed + var destinationFolderHierarchy = ""; + // From Cmdlet Help: UIVersion of the Masterpage. Default = 15 + var uIVersion = ""; + // From Cmdlet Help: Default CSS file for the MasterPage, this Url is SiteRelative + var defaultCssFile = ""; + + var results = scope.ExecuteCommand("Add-PnPMasterPage", + new CommandParameter("SourceFilePath", sourceFilePath), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("DestinationFolderHierarchy", destinationFolderHierarchy), + new CommandParameter("UIVersion", uIVersion), + new CommandParameter("DefaultCssFile", defaultCssFile)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPPublishingImageRenditionTests.cs b/Tests/Publishing/AddPnPPublishingImageRenditionTests.cs new file mode 100644 index 000000000..dea31846a --- /dev/null +++ b/Tests/Publishing/AddPnPPublishingImageRenditionTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddPublishingImageRenditionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPPublishingImageRenditionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The display name of the Image Rendition. + var name = ""; + // This is a mandatory parameter + // From Cmdlet Help: The width of the Image Rendition. + var width = ""; + // This is a mandatory parameter + // From Cmdlet Help: The height of the Image Rendition. + var height = ""; + + var results = scope.ExecuteCommand("Add-PnPPublishingImageRendition", + new CommandParameter("Name", name), + new CommandParameter("Width", width), + new CommandParameter("Height", height)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPPublishingPageLayoutTests.cs b/Tests/Publishing/AddPnPPublishingPageLayoutTests.cs new file mode 100644 index 000000000..47d9066e4 --- /dev/null +++ b/Tests/Publishing/AddPnPPublishingPageLayoutTests.cs @@ -0,0 +1,93 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddPublishingPageLayoutTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPPublishingPageLayoutTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Path to the file which will be uploaded + var sourceFilePath = ""; + // This is a mandatory parameter + // From Cmdlet Help: Title for the page layout + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: Description for the page layout + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: Associated content type ID + var associatedContentTypeID = ""; + // From Cmdlet Help: Folder hierarchy where the html page layouts will be deployed + var destinationFolderHierarchy = ""; + + var results = scope.ExecuteCommand("Add-PnPPublishingPageLayout", + new CommandParameter("SourceFilePath", sourceFilePath), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("AssociatedContentTypeID", associatedContentTypeID), + new CommandParameter("DestinationFolderHierarchy", destinationFolderHierarchy)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPPublishingPageTests.cs b/Tests/Publishing/AddPnPPublishingPageTests.cs new file mode 100644 index 000000000..495c34565 --- /dev/null +++ b/Tests/Publishing/AddPnPPublishingPageTests.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddPublishingPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPPublishingPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The name of the page to be added as an aspx file + var pageName = ""; + // From Cmdlet Help: The site relative folder path of the page to be added + var folderPath = ""; + // This is a mandatory parameter + // From Cmdlet Help: The name of the page layout you want to use. Specify without the .aspx extension. So 'ArticleLeft' or 'BlankWebPartPage' + var pageTemplateName = ""; + // From Cmdlet Help: The title of the page + var title = ""; + // From Cmdlet Help: Publishes the page. Also Approves it if moderation is enabled on the Pages library. + var publish = ""; + + var results = scope.ExecuteCommand("Add-PnPPublishingPage", + new CommandParameter("PageName", pageName), + new CommandParameter("FolderPath", folderPath), + new CommandParameter("PageTemplateName", pageTemplateName), + new CommandParameter("Title", title), + new CommandParameter("Publish", publish)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/AddPnPWikiPageTests.cs b/Tests/Publishing/AddPnPWikiPageTests.cs new file mode 100644 index 000000000..1227d2ec8 --- /dev/null +++ b/Tests/Publishing/AddPnPWikiPageTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class AddWikiPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPWikiPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative page URL + var serverRelativePageUrl = ""; + // This is a mandatory parameter + var content = ""; + // This is a mandatory parameter + var layoutVar = ""; + + var results = scope.ExecuteCommand("Add-PnPWikiPage", + new CommandParameter("ServerRelativePageUrl", serverRelativePageUrl), + new CommandParameter("Content", content), + new CommandParameter("Layout", layoutVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/GetPnPPublishingImageRenditionTests.cs b/Tests/Publishing/GetPnPPublishingImageRenditionTests.cs new file mode 100644 index 000000000..4e90380aa --- /dev/null +++ b/Tests/Publishing/GetPnPPublishingImageRenditionTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class GetPublishingImageRenditionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPPublishingImageRenditionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Id or name of an existing image rendition + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPPublishingImageRendition", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/GetPnPWikiPageContentTests.cs b/Tests/Publishing/GetPnPWikiPageContentTests.cs new file mode 100644 index 000000000..534af35f3 --- /dev/null +++ b/Tests/Publishing/GetPnPWikiPageContentTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class GetWikiPageContentTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPWikiPageContentTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The server relative URL for the wiki page + var serverRelativePageUrl = ""; + + var results = scope.ExecuteCommand("Get-PnPWikiPageContent", + new CommandParameter("ServerRelativePageUrl", serverRelativePageUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/RemovePnPPublishingImageRenditionTests.cs b/Tests/Publishing/RemovePnPPublishingImageRenditionTests.cs new file mode 100644 index 000000000..6403434a1 --- /dev/null +++ b/Tests/Publishing/RemovePnPPublishingImageRenditionTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class RemovePublishingImageRenditionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPPublishingImageRenditionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The display name or id of the Image Rendition. + var identity = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to remove the Image Rendition. + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPPublishingImageRendition", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/RemovePnPWikiPageTests.cs b/Tests/Publishing/RemovePnPWikiPageTests.cs new file mode 100644 index 000000000..8f9649248 --- /dev/null +++ b/Tests/Publishing/RemovePnPWikiPageTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class RemoveWikiPageTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPWikiPageTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var serverRelativePageUrl = ""; + // This is a mandatory parameter + var siteRelativePageUrl = ""; + + var results = scope.ExecuteCommand("Remove-PnPWikiPage", + new CommandParameter("ServerRelativePageUrl", serverRelativePageUrl), + new CommandParameter("SiteRelativePageUrl", siteRelativePageUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/SetPnPAvailablePageLayoutsTests.cs b/Tests/Publishing/SetPnPAvailablePageLayoutsTests.cs new file mode 100644 index 000000000..25a0391b0 --- /dev/null +++ b/Tests/Publishing/SetPnPAvailablePageLayoutsTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class SetAvailablePageLayoutsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPAvailablePageLayoutsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: An array of page layout files to set as available page layouts for the site. + var pageLayoutVars = ""; + // This is a mandatory parameter + // From Cmdlet Help: An array of page layout files to set as available page layouts for the site. + var allowAllPageLayoutVars = ""; + // This is a mandatory parameter + // From Cmdlet Help: Set the available page layouts to inherit from the parent site. + var inheritPageLayoutVars = ""; + + var results = scope.ExecuteCommand("Set-PnPAvailablePageLayouts", + new CommandParameter("PageLayouts", pageLayoutVars), + new CommandParameter("AllowAllPageLayouts", allowAllPageLayoutVars), + new CommandParameter("InheritPageLayouts", inheritPageLayoutVars)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/SetPnPDefaultPageLayoutTests.cs b/Tests/Publishing/SetPnPDefaultPageLayoutTests.cs new file mode 100644 index 000000000..5c10de9d5 --- /dev/null +++ b/Tests/Publishing/SetPnPDefaultPageLayoutTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class SetDefaultPageLayoutTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPDefaultPageLayoutTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Title of the page layout + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: Set the default page layout to be inherited from the parent site. + var inheritFromParentSite = ""; + + var results = scope.ExecuteCommand("Set-PnPDefaultPageLayout", + new CommandParameter("Title", title), + new CommandParameter("InheritFromParentSite", inheritFromParentSite)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Publishing/SetPnPWikiPageContentTests.cs b/Tests/Publishing/SetPnPWikiPageContentTests.cs new file mode 100644 index 000000000..d54f8d10c --- /dev/null +++ b/Tests/Publishing/SetPnPWikiPageContentTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Publishing +{ + [TestClass] + public class SetWikiPageContentTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPWikiPageContentTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var content = ""; + // This is a mandatory parameter + var path = ""; + // This is a mandatory parameter + // From Cmdlet Help: Site Relative Page Url + var serverRelativePageUrl = ""; + + var results = scope.ExecuteCommand("Set-PnPWikiPageContent", + new CommandParameter("Content", content), + new CommandParameter("Path", path), + new CommandParameter("ServerRelativePageUrl", serverRelativePageUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/ClearPnPListItemAsRecordTests.cs b/Tests/RecordsManagement/ClearPnPListItemAsRecordTests.cs new file mode 100644 index 000000000..13b2cf5bf --- /dev/null +++ b/Tests/RecordsManagement/ClearPnPListItemAsRecordTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class ClearListItemAsRecordTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ClearPnPListItemAsRecordTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + + var results = scope.ExecuteCommand("Clear-PnPListItemAsRecord", + new CommandParameter("List", list), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/DisablePnPInPlaceRecordsManagementForSiteTests.cs b/Tests/RecordsManagement/DisablePnPInPlaceRecordsManagementForSiteTests.cs new file mode 100644 index 000000000..4843bd63d --- /dev/null +++ b/Tests/RecordsManagement/DisablePnPInPlaceRecordsManagementForSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class DisableInPlaceRecordsManagementForSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPInPlaceRecordsManagementForSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Disable-PnPInPlaceRecordsManagementForSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/EnablePnPInPlaceRecordsManagementForSiteTests.cs b/Tests/RecordsManagement/EnablePnPInPlaceRecordsManagementForSiteTests.cs new file mode 100644 index 000000000..0e124e8da --- /dev/null +++ b/Tests/RecordsManagement/EnablePnPInPlaceRecordsManagementForSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class EnableInPlaceRecordsManagementForSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPInPlaceRecordsManagementForSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Enable-PnPInPlaceRecordsManagementForSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/GetPnPInPlaceRecordsManagementTests.cs b/Tests/RecordsManagement/GetPnPInPlaceRecordsManagementTests.cs new file mode 100644 index 000000000..1b5aff160 --- /dev/null +++ b/Tests/RecordsManagement/GetPnPInPlaceRecordsManagementTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class GetInPlaceRecordsManagementTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPInPlaceRecordsManagementTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPInPlaceRecordsManagement"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/GetPnPListRecordDeclarationTests.cs b/Tests/RecordsManagement/GetPnPListRecordDeclarationTests.cs new file mode 100644 index 000000000..6442fc5df --- /dev/null +++ b/Tests/RecordsManagement/GetPnPListRecordDeclarationTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class GetListRecordDeclarationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPListRecordDeclarationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The list to retrieve the record declaration settings for + var list = ""; + + var results = scope.ExecuteCommand("Get-PnPListRecordDeclaration", + new CommandParameter("List", list)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/SetPnPInPlaceRecordsManagementTests.cs b/Tests/RecordsManagement/SetPnPInPlaceRecordsManagementTests.cs new file mode 100644 index 000000000..62aebfa17 --- /dev/null +++ b/Tests/RecordsManagement/SetPnPInPlaceRecordsManagementTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class SetInPlaceRecordsManagementTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPInPlaceRecordsManagementTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var enabled = ""; + // This is a mandatory parameter + // From Cmdlet Help: Turn records management on + var on = ""; + // This is a mandatory parameter + // From Cmdlet Help: Turn records management off + var off = ""; + + var results = scope.ExecuteCommand("Set-PnPInPlaceRecordsManagement", + new CommandParameter("Enabled", enabled), + new CommandParameter("On", on), + new CommandParameter("Off", off)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/SetPnPListItemAsRecordTests.cs b/Tests/RecordsManagement/SetPnPListItemAsRecordTests.cs new file mode 100644 index 000000000..2534e6ec6 --- /dev/null +++ b/Tests/RecordsManagement/SetPnPListItemAsRecordTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class SetListItemAsRecordTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListItemAsRecordTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + // From Cmdlet Help: The declaration date + var declarationDate = ""; + + var results = scope.ExecuteCommand("Set-PnPListItemAsRecord", + new CommandParameter("List", list), + new CommandParameter("Identity", identity), + new CommandParameter("DeclarationDate", declarationDate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/SetPnPListRecordDeclarationTests.cs b/Tests/RecordsManagement/SetPnPListRecordDeclarationTests.cs new file mode 100644 index 000000000..7b344ddcf --- /dev/null +++ b/Tests/RecordsManagement/SetPnPListRecordDeclarationTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class SetListRecordDeclarationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPListRecordDeclarationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The List to set the manual record declaration settings for + var list = ""; + // From Cmdlet Help: Defines the manual record declaration setting for the lists + var manualRecordDeclaration = ""; + // From Cmdlet Help: Defines if you want to set auto record declaration on the list + var autoRecordDeclaration = ""; + + var results = scope.ExecuteCommand("Set-PnPListRecordDeclaration", + new CommandParameter("List", list), + new CommandParameter("ManualRecordDeclaration", manualRecordDeclaration), + new CommandParameter("AutoRecordDeclaration", autoRecordDeclaration)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecordsManagement/TestPnPListItemIsRecordTests.cs b/Tests/RecordsManagement/TestPnPListItemIsRecordTests.cs new file mode 100644 index 000000000..fa466ae5d --- /dev/null +++ b/Tests/RecordsManagement/TestPnPListItemIsRecordTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecordsManagement +{ + [TestClass] + public class TestListItemIsRecordTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void TestPnPListItemIsRecordTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID, Title or Url of the list. + var list = ""; + // This is a mandatory parameter + // From Cmdlet Help: The ID of the listitem, or actual ListItem object + var identity = ""; + + var results = scope.ExecuteCommand("Test-PnPListItemIsRecord", + new CommandParameter("List", list), + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/ClearPnPRecycleBinItemTests.cs b/Tests/RecycleBin/ClearPnPRecycleBinItemTests.cs new file mode 100644 index 000000000..f795ebfcd --- /dev/null +++ b/Tests/RecycleBin/ClearPnPRecycleBinItemTests.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class ClearRecycleBinItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ClearPnPRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Id of the recycle bin item or the recycle bin item itself to permanently delete + var identity = ""; + // From Cmdlet Help: Clears all items + var all = ""; + // From Cmdlet Help: If provided, only all the items in the second stage recycle bin will be cleared + var secondStageOnly = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to permanently delete the recycle bin item + var force = ""; + + var results = scope.ExecuteCommand("Clear-PnPRecycleBinItem", + new CommandParameter("Identity", identity), + new CommandParameter("All", all), + new CommandParameter("SecondStageOnly", secondStageOnly), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/ClearPnPTenantRecycleBinItemTests.cs b/Tests/RecycleBin/ClearPnPTenantRecycleBinItemTests.cs new file mode 100644 index 000000000..76ba6c248 --- /dev/null +++ b/Tests/RecycleBin/ClearPnPTenantRecycleBinItemTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class ClearTenantRecycleBinItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ClearPnPTenantRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Url of the site collection to permanently delete from the tenant recycle bin + var url = ""; + // From Cmdlet Help: If provided, the PowerShell execution will halt until the operation has completed + var wait = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to permanently delete the site collection from the tenant recycle bin + var force = ""; + + var results = scope.ExecuteCommand("Clear-PnPTenantRecycleBinItem", + new CommandParameter("Url", url), + new CommandParameter("Wait", wait), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/GetPnPRecycleBinItemTests.cs b/Tests/RecycleBin/GetPnPRecycleBinItemTests.cs new file mode 100644 index 000000000..1753a64a1 --- /dev/null +++ b/Tests/RecycleBin/GetPnPRecycleBinItemTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class GetRecycleBinItemsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Returns a recycle bin item with a specific identity + var identity = ""; + // From Cmdlet Help: Return all items in the first stage recycle bin + var firstStage = ""; + // From Cmdlet Help: Return all items in the second stage recycle bin + var secondStage = ""; + // From Cmdlet Help: Limits return results to specified amount + var rowLimit = ""; + + var results = scope.ExecuteCommand("Get-PnPRecycleBinItem", + new CommandParameter("Identity", identity), + new CommandParameter("FirstStage", firstStage), + new CommandParameter("SecondStage", secondStage), + new CommandParameter("RowLimit", rowLimit)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/GetPnPTenantRecycleBinItemTests.cs b/Tests/RecycleBin/GetPnPTenantRecycleBinItemTests.cs new file mode 100644 index 000000000..20092ff61 --- /dev/null +++ b/Tests/RecycleBin/GetPnPTenantRecycleBinItemTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class GetTenantRecycleBinItemsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPTenantRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPTenantRecycleBinItem"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/MovePnPRecycleBinItemTests.cs b/Tests/RecycleBin/MovePnPRecycleBinItemTests.cs new file mode 100644 index 000000000..43adf281d --- /dev/null +++ b/Tests/RecycleBin/MovePnPRecycleBinItemTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class MoveRecycleBinItemsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void MovePnPRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: If provided, moves the item with the specific ID to the second stage recycle bin + var identity = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to move the first stage recycle bin items to the second stage + var force = ""; + + var results = scope.ExecuteCommand("Move-PnPRecycleBinItem", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/RestorePnPRecycleBinItemTests.cs b/Tests/RecycleBin/RestorePnPRecycleBinItemTests.cs new file mode 100644 index 000000000..7f21dc438 --- /dev/null +++ b/Tests/RecycleBin/RestorePnPRecycleBinItemTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class RestoreRecycleBinItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RestorePnPRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Id of the recycle bin item or the recycle bin item object itself to restore + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: If provided all items will be stored + var all = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to restore the recycle bin item + var force = ""; + + var results = scope.ExecuteCommand("Restore-PnPRecycleBinItem", + new CommandParameter("Identity", identity), + new CommandParameter("All", all), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/RecycleBin/RestorePnPTenantRecycleBinItemTests.cs b/Tests/RecycleBin/RestorePnPTenantRecycleBinItemTests.cs new file mode 100644 index 000000000..77067c681 --- /dev/null +++ b/Tests/RecycleBin/RestorePnPTenantRecycleBinItemTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.RecycleBin +{ + [TestClass] + public class RestoreTenantRecycleBinItemTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RestorePnPTenantRecycleBinItemTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Url of the site collection to restore from the tenant recycle bin + var url = ""; + // From Cmdlet Help: If provided, the PowerShell execution will halt until the site restore process has completed + var wait = ""; + // From Cmdlet Help: If provided, no confirmation will be asked to restore the site collection from the tenant recycle bin + var force = ""; + + var results = scope.ExecuteCommand("Restore-PnPTenantRecycleBinItem", + new CommandParameter("Url", url), + new CommandParameter("Wait", wait), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/GetPnPSearchConfigurationTests.cs b/Tests/Search/GetPnPSearchConfigurationTests.cs new file mode 100644 index 000000000..6bd7df2d2 --- /dev/null +++ b/Tests/Search/GetPnPSearchConfigurationTests.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class GetSearchConfigurationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSearchConfigurationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Scope to use. Either Web, Site, or Subscription. Defaults to Web + var scopeVar = ""; + // From Cmdlet Help: Local path where the search configuration will be saved + var path = ""; + // From Cmdlet Help: Output format for of the configuration. Defaults to complete XML + var outVarputFormat = ""; + + var results = scope.ExecuteCommand("Get-PnPSearchConfiguration", + new CommandParameter("Scope", scopeVar), + new CommandParameter("Path", path), + new CommandParameter("OutputFormat", outVarputFormat)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/GetPnPSearchCrawlLogTests.cs b/Tests/Search/GetPnPSearchCrawlLogTests.cs new file mode 100644 index 000000000..5e6ed921b --- /dev/null +++ b/Tests/Search/GetPnPSearchCrawlLogTests.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class GetSearchCrawlLogTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSearchCrawlLogTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Filter what log entries to return (All, Success, Warning, Error). Defaults to All + var logLevel = ""; + // From Cmdlet Help: Number of entries to return. Defaults to 100. + var rowLimit = ""; + // From Cmdlet Help: Filter to limit what is being returned. Has to be a URL prefix for SharePoint content, and part of a user principal name for user profiles. Wildcard characters are not supported. + var filter = ""; + // From Cmdlet Help: Content to retrieve (Sites, User Profiles). Defaults to Sites. + var contentSource = ""; + // From Cmdlet Help: Start date to start getting entries from. Defaults to start of time. + var startDate = ""; + // From Cmdlet Help: End date to stop getting entries from. Default to current time. + var endDate = ""; + // From Cmdlet Help: Show raw crawl log data + var rawFormat = ""; + + var results = scope.ExecuteCommand("Get-PnPSearchCrawlLog", + new CommandParameter("LogLevel", logLevel), + new CommandParameter("RowLimit", rowLimit), + new CommandParameter("Filter", filter), + new CommandParameter("ContentSource", contentSource), + new CommandParameter("StartDate", startDate), + new CommandParameter("EndDate", endDate), + new CommandParameter("RawFormat", rawFormat)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/GetPnPSearchSettingsTests.cs b/Tests/Search/GetPnPSearchSettingsTests.cs new file mode 100644 index 000000000..da8bc5185 --- /dev/null +++ b/Tests/Search/GetPnPSearchSettingsTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class GetSearchSettingsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSearchSettingsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPSearchSettings"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/GetPnPSiteSearchQueryResultsTests.cs b/Tests/Search/GetPnPSiteSearchQueryResultsTests.cs new file mode 100644 index 000000000..cc45c80e9 --- /dev/null +++ b/Tests/Search/GetPnPSiteSearchQueryResultsTests.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class GetSiteSearchQueryResultsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteSearchQueryResultsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Search query in Keyword Query Language (KQL) to execute to refine the returned sites. If omitted, all indexed sites will be returned. + var query = ""; + // From Cmdlet Help: Search result item to start returning the results from. Useful for paging. Leave at 0 to return all results. + var startRow = ""; + // From Cmdlet Help: Maximum amount of search results to return. Default and max is 500 search results. + var maxResults = ""; + // From Cmdlet Help: Automatically page results until the end to get more than 500 sites. Use with caution! + var all = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteSearchQueryResults", + new CommandParameter("Query", query), + new CommandParameter("StartRow", startRow), + new CommandParameter("MaxResults", maxResults), + new CommandParameter("All", all)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/RemovePnPSearchConfigurationTests.cs b/Tests/Search/RemovePnPSearchConfigurationTests.cs new file mode 100644 index 000000000..616403ad0 --- /dev/null +++ b/Tests/Search/RemovePnPSearchConfigurationTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class RemoveSearchConfigurationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSearchConfigurationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Search configuration string + var configuration = ""; + // This is a mandatory parameter + // From Cmdlet Help: Path to a search configuration + var path = ""; + var scopeVar = ""; + + var results = scope.ExecuteCommand("Remove-PnPSearchConfiguration", + new CommandParameter("Configuration", configuration), + new CommandParameter("Path", path), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/SetPnPSearchConfigurationTests.cs b/Tests/Search/SetPnPSearchConfigurationTests.cs new file mode 100644 index 000000000..825df151d --- /dev/null +++ b/Tests/Search/SetPnPSearchConfigurationTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class SetSearchConfigurationTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSearchConfigurationTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Search configuration string + var configuration = ""; + // This is a mandatory parameter + // From Cmdlet Help: Path to a search configuration + var path = ""; + var scopeVar = ""; + + var results = scope.ExecuteCommand("Set-PnPSearchConfiguration", + new CommandParameter("Configuration", configuration), + new CommandParameter("Path", path), + new CommandParameter("Scope", scopeVar)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/SetPnPSearchSettingsTests.cs b/Tests/Search/SetPnPSearchSettingsTests.cs new file mode 100644 index 000000000..76017e7c9 --- /dev/null +++ b/Tests/Search/SetPnPSearchSettingsTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class SetSearchSettingsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSearchSettingsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Set the scope of which the suite bar search box shows. Possible values: Inherit, AllPages, ModernOnly, Hidden + var searchBoxInNavBar = ""; + // From Cmdlet Help: Set the URL where the search box should redirect to. + var searchPageUrl = ""; + // From Cmdlet Help: Set the search scope of the suite bar search box. Possible values: DefaultScope, Tenant, Hub, Site + var searchScope = ""; + // From Cmdlet Help: Scope to apply the setting to. Possible values: Web (default), Site\r\n\r\nFor a root site, the scope does not matter. + var scopeVar = ""; + // From Cmdlet Help: Do not ask for confirmation. + var force = ""; + + var results = scope.ExecuteCommand("Set-PnPSearchSettings", + new CommandParameter("SearchBoxInNavBar", searchBoxInNavBar), + new CommandParameter("SearchPageUrl", searchPageUrl), + new CommandParameter("SearchScope", searchScope), + new CommandParameter("Scope", scopeVar), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Search/SubmitPnPSearchQueryTests.cs b/Tests/Search/SubmitPnPSearchQueryTests.cs new file mode 100644 index 000000000..ef168f906 --- /dev/null +++ b/Tests/Search/SubmitPnPSearchQueryTests.cs @@ -0,0 +1,147 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Search +{ + [TestClass] + public class SubmitSearchQueryTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SubmitPnPSearchQueryTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Search query in Keyword Query Language (KQL). + var query = ""; + // From Cmdlet Help: Search result item to start returning the results from. Useful for paging. Leave at 0 to return all results. + var startRow = ""; + // From Cmdlet Help: Maximum amount of search results to return. Default and max per page is 500 search results. + var maxResults = ""; + // From Cmdlet Help: Automatically page results until the end to get more than 500. Use with caution! + var all = ""; + // From Cmdlet Help: Specifies whether near duplicate items should be removed from the search results. + var trimDuplicates = ""; + // From Cmdlet Help: Extra query properties. Can for example be used for Office Graph queries. + var properties = ""; + // From Cmdlet Help: The list of refiners to be returned in a search result. + var refiners = ""; + // From Cmdlet Help: The locale for the query. + var culture = ""; + // From Cmdlet Help: Specifies the query template that is used at run time to transform the query based on user input. + var queryTemplate = ""; + // From Cmdlet Help: The list of properties to return in the search results. + var selectProperties = ""; + // From Cmdlet Help: The set of refinement filters used. + var refinementFilters = ""; + // From Cmdlet Help: The list of properties by which the search results are ordered. + var sortList = ""; + // From Cmdlet Help: The identifier (ID) of the ranking model to use for the query. + var rankingModelId = ""; + // From Cmdlet Help: Specifies the name of the client which issued the query. + var clientType = ""; + // From Cmdlet Help: Limit the number of items per the collapse specification. See https://docs.microsoft.com/en-us/sharepoint/dev/general-development/customizing-search-results-in-sharepoint#collapse-similar-search-results-using-the-collapsespecification-property for more information. + var collapseSpecification = ""; + // From Cmdlet Help: The keyword query’s hidden constraints. + var hiddenConstraints = ""; + // From Cmdlet Help: The identifier for the search query time zone. + var timeZoneId = ""; + // From Cmdlet Help: Specifies whether the phonetic forms of the query terms are used to find matches. + var enablePhonetic = ""; + // From Cmdlet Help: Specifies whether stemming is enabled. + var enableStemming = ""; + // From Cmdlet Help: Specifies whether Query Rules are enabled for this query. + var enableQueryRules = ""; + // From Cmdlet Help: Specifies the identifier (ID or name) of the result source to be used to run the query. + var sourceId = ""; + // From Cmdlet Help: Determines whether Best Bets are enabled. + var processBestBets = ""; + // From Cmdlet Help: Determines whether personal favorites data is processed or not. + var processPersonalFavorites = ""; + // From Cmdlet Help: Specifies whether only relevant results are returned + var relevantResults = ""; + + var results = scope.ExecuteCommand("Submit-PnPSearchQuery", + new CommandParameter("Query", query), + new CommandParameter("StartRow", startRow), + new CommandParameter("MaxResults", maxResults), + new CommandParameter("All", all), + new CommandParameter("TrimDuplicates", trimDuplicates), + new CommandParameter("Properties", properties), + new CommandParameter("Refiners", refiners), + new CommandParameter("Culture", culture), + new CommandParameter("QueryTemplate", queryTemplate), + new CommandParameter("SelectProperties", selectProperties), + new CommandParameter("RefinementFilters", refinementFilters), + new CommandParameter("SortList", sortList), + new CommandParameter("RankingModelId", rankingModelId), + new CommandParameter("ClientType", clientType), + new CommandParameter("CollapseSpecification", collapseSpecification), + new CommandParameter("HiddenConstraints", hiddenConstraints), + new CommandParameter("TimeZoneId", timeZoneId), + new CommandParameter("EnablePhonetic", enablePhonetic), + new CommandParameter("EnableStemming", enableStemming), + new CommandParameter("EnableQueryRules", enableQueryRules), + new CommandParameter("SourceId", sourceId), + new CommandParameter("ProcessBestBets", processBestBets), + new CommandParameter("ProcessPersonalFavorites", processPersonalFavorites), + new CommandParameter("RelevantResults", relevantResults)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SharePointPnP.PowerShell.Tests.csproj b/Tests/SharePointPnP.PowerShell.Tests.csproj index 591bd42db..f99046207 100644 --- a/Tests/SharePointPnP.PowerShell.Tests.csproj +++ b/Tests/SharePointPnP.PowerShell.Tests.csproj @@ -344,29 +344,455 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -380,6 +806,7 @@ Designer + @@ -387,6 +814,7 @@ SharePointPnP.PowerShell.Commands + diff --git a/Tests/Site/AddPnPRoleDefinitionTests.cs b/Tests/Site/AddPnPRoleDefinitionTests.cs new file mode 100644 index 000000000..63576f05b --- /dev/null +++ b/Tests/Site/AddPnPRoleDefinitionTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class AddRoleDefinitionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPRoleDefinitionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Name of new permission level. + var roleName = ""; + // From Cmdlet Help: An existing permission level or the name of an permission level to clone as base template. + var clone = ""; + // From Cmdlet Help: Specifies permission flags(s) to enable. Please visit https://docs.microsoft.com/previous-versions/office/sharepoint-csom/ee536458(v%3Doffice.15) for the PermissionKind enum + var include = ""; + // From Cmdlet Help: Specifies permission flags(s) to disable. Please visit https://docs.microsoft.com/previous-versions/office/sharepoint-csom/ee536458(v%3Doffice.15) for the PermissionKind enum + var exclude = ""; + // From Cmdlet Help: Optional description for the new permission level. + var description = ""; + + var results = scope.ExecuteCommand("Add-PnPRoleDefinition", + new CommandParameter("RoleName", roleName), + new CommandParameter("Clone", clone), + new CommandParameter("Include", include), + new CommandParameter("Exclude", exclude), + new CommandParameter("Description", description)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/AddPnPSiteCollectionAdminTests.cs b/Tests/Site/AddPnPSiteCollectionAdminTests.cs new file mode 100644 index 000000000..ea6a6717b --- /dev/null +++ b/Tests/Site/AddPnPSiteCollectionAdminTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class AddSiteCollectionAdminTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteCollectionAdminTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies owner(s) to add as site collection administrators. They will be added as additional site collection administrators to the site in the current context. Existing administrators will stay. Can be both users and groups. + var owners = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteCollectionAdmin", + new CommandParameter("Owners", owners)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/AddPnPTeamsTeamTests.cs b/Tests/Site/AddPnPTeamsTeamTests.cs new file mode 100644 index 000000000..4a709e78a --- /dev/null +++ b/Tests/Site/AddPnPTeamsTeamTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class AddTeamsTeamTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPTeamsTeamTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Add-PnPTeamsTeam"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/DisablePnPSharingForNonOwnersOfSiteTests.cs b/Tests/Site/DisablePnPSharingForNonOwnersOfSiteTests.cs new file mode 100644 index 000000000..5af28a9f5 --- /dev/null +++ b/Tests/Site/DisablePnPSharingForNonOwnersOfSiteTests.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class DisableSharingForNonOwnersOfSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void DisablePnPSharingForNonOwnersOfSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var identity = ""; + + var results = scope.ExecuteCommand("Disable-PnPSharingForNonOwnersOfSite", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/EnablePnPCommSiteTests.cs b/Tests/Site/EnablePnPCommSiteTests.cs new file mode 100644 index 000000000..152b44f64 --- /dev/null +++ b/Tests/Site/EnablePnPCommSiteTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class EnableCommSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void EnablePnPCommSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The id (guid) of the design package to apply: 96c933ac-3698-44c7-9f4a-5fd17d71af9e (Topic = default), 6142d2a0-63a5-4ba0-aede-d9fefca2c767 (Showcase) or f6cc5403-0d63-442e-96c0-285923709ffc (Blank) + var designPackageId = ""; + + var results = scope.ExecuteCommand("Enable-PnPCommSite", + new CommandParameter("DesignPackageId", designPackageId)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPAuditingTests.cs b/Tests/Site/GetPnPAuditingTests.cs new file mode 100644 index 000000000..20470d8a3 --- /dev/null +++ b/Tests/Site/GetPnPAuditingTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetAuditingTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPAuditingTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPAuditing"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPIsSiteAliasAvailableTests.cs b/Tests/Site/GetPnPIsSiteAliasAvailableTests.cs new file mode 100644 index 000000000..de7bd743b --- /dev/null +++ b/Tests/Site/GetPnPIsSiteAliasAvailableTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetIsSiteAliasAvailableTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPIsSiteAliasAvailableTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: Alias you want to check for if it is still available to create a new site collection for + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPIsSiteAliasAvailable", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPRoleDefinitionTests.cs b/Tests/Site/GetPnPRoleDefinitionTests.cs new file mode 100644 index 000000000..982282e40 --- /dev/null +++ b/Tests/Site/GetPnPRoleDefinitionTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetRoleDefinitionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPRoleDefinitionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The name of a role definition to retrieve. + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPRoleDefinition", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPSharingForNonOwnersOfSiteTests.cs b/Tests/Site/GetPnPSharingForNonOwnersOfSiteTests.cs new file mode 100644 index 000000000..cef0d0204 --- /dev/null +++ b/Tests/Site/GetPnPSharingForNonOwnersOfSiteTests.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetSharingForNonOwnersOfSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSharingForNonOwnersOfSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPSharingForNonOwnersOfSite", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPSiteCollectionAdminTests.cs b/Tests/Site/GetPnPSiteCollectionAdminTests.cs new file mode 100644 index 000000000..a2895baf2 --- /dev/null +++ b/Tests/Site/GetPnPSiteCollectionAdminTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetSiteCollectionAdminTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteCollectionAdminTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPSiteCollectionAdmin"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/GetPnPSiteTests.cs b/Tests/Site/GetPnPSiteTests.cs new file mode 100644 index 000000000..e74fb3ffa --- /dev/null +++ b/Tests/Site/GetPnPSiteTests.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class GetSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + + var results = scope.ExecuteCommand("Get-PnPSite"); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/InstallPnPSolutionTests.cs b/Tests/Site/InstallPnPSolutionTests.cs new file mode 100644 index 000000000..2b47f4d4e --- /dev/null +++ b/Tests/Site/InstallPnPSolutionTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class InstallSolutionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InstallPnPSolutionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: ID of the solution, from the solution manifest + var packageId = ""; + // This is a mandatory parameter + // From Cmdlet Help: Path to the sandbox solution package (.WSP) file + var sourceFilePath = ""; + // From Cmdlet Help: Optional major version of the solution, defaults to 1 + var majorVersion = ""; + // From Cmdlet Help: Optional minor version of the solution, defaults to 0 + var minorVersion = ""; + + var results = scope.ExecuteCommand("Install-PnPSolution", + new CommandParameter("PackageId", packageId), + new CommandParameter("SourceFilePath", sourceFilePath), + new CommandParameter("MajorVersion", majorVersion), + new CommandParameter("MinorVersion", minorVersion)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/NewPnPSiteTests.cs b/Tests/Site/NewPnPSiteTests.cs new file mode 100644 index 000000000..197e6b0a3 --- /dev/null +++ b/Tests/Site/NewPnPSiteTests.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class NewSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void NewPnPSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies with type of site to create. + var type = ""; + // From Cmdlet Help: If specified the site will be associated to the hubsite as identified by this id + var hubSiteId = ""; + // From Cmdlet Help: If specified the cmdlet will wait until the site has been fully created and all site artifacts have been provisioned by SharePoint. Notice that this can take a while. + var wait = ""; + + var results = scope.ExecuteCommand("New-PnPSite", + new CommandParameter("Type", type), + new CommandParameter("HubSiteId", hubSiteId), + new CommandParameter("Wait", wait)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/RemovePnPRoleDefinitionTests.cs b/Tests/Site/RemovePnPRoleDefinitionTests.cs new file mode 100644 index 000000000..0bc0680bd --- /dev/null +++ b/Tests/Site/RemovePnPRoleDefinitionTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class RemoveRoleDefinitionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPRoleDefinitionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The identity of the role definition, either a RoleDefinition object or a the name of roledefinition + var identity = ""; + // From Cmdlet Help: Do not ask for confirmation to delete the role definition + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPRoleDefinition", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/RemovePnPSiteCollectionAdminTests.cs b/Tests/Site/RemovePnPSiteCollectionAdminTests.cs new file mode 100644 index 000000000..ca220cd3a --- /dev/null +++ b/Tests/Site/RemovePnPSiteCollectionAdminTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class RemoveSiteCollectionAdminTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteCollectionAdminTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies owner(s) to remove as site collection administrators. Can be both users and groups. + var owners = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteCollectionAdmin", + new CommandParameter("Owners", owners)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/SetPnPAppSideLoadingTests.cs b/Tests/Site/SetPnPAppSideLoadingTests.cs new file mode 100644 index 000000000..92c81727d --- /dev/null +++ b/Tests/Site/SetPnPAppSideLoadingTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class SetAppSideLoadingTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPAppSideLoadingTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + var on = ""; + // This is a mandatory parameter + var off = ""; + + var results = scope.ExecuteCommand("Set-PnPAppSideLoading", + new CommandParameter("On", on), + new CommandParameter("Off", off)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/SetPnPAuditingTests.cs b/Tests/Site/SetPnPAuditingTests.cs new file mode 100644 index 000000000..2f59af239 --- /dev/null +++ b/Tests/Site/SetPnPAuditingTests.cs @@ -0,0 +1,109 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class SetAuditingTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPAuditingTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Enable all audit flags + var enableAll = ""; + // This is a mandatory parameter + // From Cmdlet Help: Disable all audit flags + var disableAll = ""; + // From Cmdlet Help: Set the retention time + var retentionTime = ""; + // From Cmdlet Help: Trim the audit log + var trimAuditLog = ""; + // From Cmdlet Help: Audit editing items + var editItems = ""; + // From Cmdlet Help: Audit checking out or checking in items + var checkOutCheckInItems = ""; + // From Cmdlet Help: Audit moving or copying items to another location in the site. + var moveCopyItems = ""; + // From Cmdlet Help: Audit deleting or restoring items + var deleteRestoreItems = ""; + // From Cmdlet Help: Audit editing content types and columns + var editContentTypesColumns = ""; + // From Cmdlet Help: Audit searching site content + var searchContent = ""; + // From Cmdlet Help: Audit editing users and permissions + var editUsersPermissions = ""; + + var results = scope.ExecuteCommand("Set-PnPAuditing", + new CommandParameter("EnableAll", enableAll), + new CommandParameter("DisableAll", disableAll), + new CommandParameter("RetentionTime", retentionTime), + new CommandParameter("TrimAuditLog", trimAuditLog), + new CommandParameter("EditItems", editItems), + new CommandParameter("CheckOutCheckInItems", checkOutCheckInItems), + new CommandParameter("MoveCopyItems", moveCopyItems), + new CommandParameter("DeleteRestoreItems", deleteRestoreItems), + new CommandParameter("EditContentTypesColumns", editContentTypesColumns), + new CommandParameter("SearchContent", searchContent), + new CommandParameter("EditUsersPermissions", editUsersPermissions)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/SetPnPSiteTests.cs b/Tests/Site/SetPnPSiteTests.cs new file mode 100644 index 000000000..5df308810 --- /dev/null +++ b/Tests/Site/SetPnPSiteTests.cs @@ -0,0 +1,143 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class SetSiteTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSiteTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + var identity = ""; + // From Cmdlet Help: The classification to set + var classification = ""; + // From Cmdlet Help: Disables Microsoft Flow for this site + var disableFlows = ""; + // From Cmdlet Help: Sets the logo of the site if it concerns a modern team site. Provide a full path to a local image file on your disk which you want to use as the site logo. The logo will be uploaded automatically to SharePoint. If you want to set the logo for a classic site, use Set-PnPWeb -SiteLogoUrl. + var logoFilePath = ""; + // From Cmdlet Help: Specifies what the sharing capabilities are for the site. Possible values: Disabled, ExternalUserSharingOnly, ExternalUserAndGuestSharing, ExistingExternalUserSharingOnly + var sharing = ""; + // From Cmdlet Help: Specifies the storage quota for this site collection in megabytes. This value must not exceed the company's available quota. + var storageMaximumLevel = ""; + // From Cmdlet Help: Specifies the warning level for the storage quota in megabytes. This value must not exceed the values set for the StorageMaximumLevel parameter + var storageWarningLevel = ""; + // From Cmdlet Help: Specifies the quota for this site collection in Sandboxed Solutions units. This value must not exceed the company's aggregate available Sandboxed Solutions quota. The default value is 0. For more information, see Resource Usage Limits on Sandboxed Solutions in SharePoint 2010 : http://msdn.microsoft.com/en-us/library/gg615462.aspx. + var userCodeMaximumLevel = ""; + // From Cmdlet Help: Specifies the warning level for the resource quota. This value must not exceed the value set for the UserCodeMaximumLevel parameter + var userCodeWarningLevel = ""; + // From Cmdlet Help: Sets the lockstate of a site + var lockState = ""; + // From Cmdlet Help: Specifies if the site administrator can upgrade the site collection + var allowSelfServiceUpgrade = ""; + // From Cmdlet Help: Specifies if a site allows custom script or not. See https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f for more information. + var noScriptSite = ""; + // From Cmdlet Help: Specifies owner(s) to add as site collection administrators. They will be added as additional site collection administrators. Existing administrators will stay. Can be both users and groups. + var owners = ""; + // From Cmdlet Help: Specifies if comments on site pages are enabled or disabled + var commentsOnSitePagesDisabled = ""; + // From Cmdlet Help: Specifies the default link permission for the site collection. None - Respect the organization default link permission. View - Sets the default link permission for the site to "view" permissions. Edit - Sets the default link permission for the site to "edit" permissions + var defaultLinkPermission = ""; + // From Cmdlet Help: Specifies the default link type for the site collection. None - Respect the organization default sharing link type. AnonymousAccess - Sets the default sharing link for this site to an Anonymous Access or Anyone link. Internal - Sets the default sharing link for this site to the "organization" link or company shareable link. Direct - Sets the default sharing link for this site to the "Specific people" link + var defaultSharingLinkType = ""; + var disableAppViews = ""; + var disableCompanyWideSharingLinks = ""; + // From Cmdlet Help: Specifies to prevent non-owners from inviting new users to the site + var disableSharingForNonOwners = ""; + // From Cmdlet Help: Specifies the language of this site collection. + var localeId = ""; + // From Cmdlet Help: Specifies the new URL for this site collection. + var newUrl = ""; + // From Cmdlet Help: Specifies the Geo/Region restrictions of this site. + var restrictedToGeo = ""; + // From Cmdlet Help: Disables or enables the Social Bar for Site Collection. + var socialBarOnSitePagesDisabled = ""; + // From Cmdlet Help: Wait for the operation to complete + var wait = ""; + + var results = scope.ExecuteCommand("Set-PnPSite", + new CommandParameter("Identity", identity), + new CommandParameter("Classification", classification), + new CommandParameter("DisableFlows", disableFlows), + new CommandParameter("LogoFilePath", logoFilePath), + new CommandParameter("Sharing", sharing), + new CommandParameter("StorageMaximumLevel", storageMaximumLevel), + new CommandParameter("StorageWarningLevel", storageWarningLevel), + new CommandParameter("UserCodeMaximumLevel", userCodeMaximumLevel), + new CommandParameter("UserCodeWarningLevel", userCodeWarningLevel), + new CommandParameter("LockState", lockState), + new CommandParameter("AllowSelfServiceUpgrade", allowSelfServiceUpgrade), + new CommandParameter("NoScriptSite", noScriptSite), + new CommandParameter("Owners", owners), + new CommandParameter("CommentsOnSitePagesDisabled", commentsOnSitePagesDisabled), + new CommandParameter("DefaultLinkPermission", defaultLinkPermission), + new CommandParameter("DefaultSharingLinkType", defaultSharingLinkType), + new CommandParameter("DisableAppViews", disableAppViews), + new CommandParameter("DisableCompanyWideSharingLinks", disableCompanyWideSharingLinks), + new CommandParameter("DisableSharingForNonOwners", disableSharingForNonOwners), + new CommandParameter("LocaleId", localeId), + new CommandParameter("NewUrl", newUrl), + new CommandParameter("RestrictedToGeo", restrictedToGeo), + new CommandParameter("SocialBarOnSitePagesDisabled", socialBarOnSitePagesDisabled), + new CommandParameter("Wait", wait)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/TestPnPOffice365GroupAliasIsUsedTests.cs b/Tests/Site/TestPnPOffice365GroupAliasIsUsedTests.cs new file mode 100644 index 000000000..84609536f --- /dev/null +++ b/Tests/Site/TestPnPOffice365GroupAliasIsUsedTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class AddOffice365GroupAliasIsUsedTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void TestPnPOffice365GroupAliasIsUsedTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the alias of the group. Cannot contain spaces. + var alias = ""; + + var results = scope.ExecuteCommand("Test-PnPOffice365GroupAliasIsUsed", + new CommandParameter("Alias", alias)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Site/UninstallPnPSolutionTests.cs b/Tests/Site/UninstallPnPSolutionTests.cs new file mode 100644 index 000000000..0249df147 --- /dev/null +++ b/Tests/Site/UninstallPnPSolutionTests.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Site +{ + [TestClass] + public class UninstallSolutionTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void UninstallPnPSolutionTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: ID of the solution, from the solution manifest + var packageId = ""; + // This is a mandatory parameter + // From Cmdlet Help: Filename of the WSP file to uninstall + var packageName = ""; + // From Cmdlet Help: Optional major version of the solution, defaults to 1 + var majorVersion = ""; + // From Cmdlet Help: Optional minor version of the solution, defaults to 0 + var minorVersion = ""; + + var results = scope.ExecuteCommand("Uninstall-PnPSolution", + new CommandParameter("PackageId", packageId), + new CommandParameter("PackageName", packageName), + new CommandParameter("MajorVersion", majorVersion), + new CommandParameter("MinorVersion", minorVersion)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/AddPnPSiteDesignTaskTests.cs b/Tests/SiteDesigns/AddPnPSiteDesignTaskTests.cs new file mode 100644 index 000000000..9f89db071 --- /dev/null +++ b/Tests/SiteDesigns/AddPnPSiteDesignTaskTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class AddSiteDesignTaskTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteDesignTaskTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID of the site design to apply. + var siteDesignId = ""; + // From Cmdlet Help: The URL of the site collection where the site design will be applied. If not specified the design will be applied to the site you connected to with Connect-PnPOnline. + var webUrl = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteDesignTask", + new CommandParameter("SiteDesignId", siteDesignId), + new CommandParameter("WebUrl", webUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/AddPnPSiteDesignTests.cs b/Tests/SiteDesigns/AddPnPSiteDesignTests.cs new file mode 100644 index 000000000..d4f04e420 --- /dev/null +++ b/Tests/SiteDesigns/AddPnPSiteDesignTests.cs @@ -0,0 +1,98 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class AddSiteDesignTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteDesignTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The title of the site design + var title = ""; + // This is a mandatory parameter + // From Cmdlet Help: An array of guids of site scripts + var siteScriptIds = ""; + // From Cmdlet Help: The description of the site design + var description = ""; + // From Cmdlet Help: Specifies if the site design is a default site design + var isDefault = ""; + // From Cmdlet Help: Sets the text for the preview image + var previewImageAltText = ""; + // From Cmdlet Help: Sets the url to the preview image + var previewImageUrl = ""; + // This is a mandatory parameter + // From Cmdlet Help: Specifies the type of site to which this design applies + var webTemplate = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteDesign", + new CommandParameter("Title", title), + new CommandParameter("SiteScriptIds", siteScriptIds), + new CommandParameter("Description", description), + new CommandParameter("IsDefault", isDefault), + new CommandParameter("PreviewImageAltText", previewImageAltText), + new CommandParameter("PreviewImageUrl", previewImageUrl), + new CommandParameter("WebTemplate", webTemplate)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/AddPnPSiteScriptTests.cs b/Tests/SiteDesigns/AddPnPSiteScriptTests.cs new file mode 100644 index 000000000..8c187684d --- /dev/null +++ b/Tests/SiteDesigns/AddPnPSiteScriptTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class AddSiteScriptTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void AddPnPSiteScriptTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The title of the site script + var title = ""; + // From Cmdlet Help: The description of the site script + var description = ""; + // This is a mandatory parameter + // From Cmdlet Help: A JSON string containing the site script + var content = ""; + + var results = scope.ExecuteCommand("Add-PnPSiteScript", + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Content", content)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteDesignRightsTests.cs b/Tests/SiteDesigns/GetPnPSiteDesignRightsTests.cs new file mode 100644 index 000000000..1edd5bd1e --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteDesignRightsTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteDesignRightsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteDesignRightsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID of the Site Design to receive the rights for + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteDesignRights", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteDesignRunStatusTests.cs b/Tests/SiteDesigns/GetPnPSiteDesignRunStatusTests.cs new file mode 100644 index 000000000..a0e802670 --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteDesignRunStatusTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteDesignRunStatusTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteDesignRunStatusTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site design run for the desired set of script action details. + var run = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteDesignRunStatus", + new CommandParameter("Run", run)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteDesignRunTests.cs b/Tests/SiteDesigns/GetPnPSiteDesignRunTests.cs new file mode 100644 index 000000000..f6dff257a --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteDesignRunTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteDesignRunTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteDesignRunTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The ID of the site design to apply. + var siteDesignId = ""; + // From Cmdlet Help: The URL of the site collection where the site design will be applied. If not specified the design will be applied to the site you connected to with Connect-PnPOnline. + var webUrl = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteDesignRun", + new CommandParameter("SiteDesignId", siteDesignId), + new CommandParameter("WebUrl", webUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteDesignTaskTests.cs b/Tests/SiteDesigns/GetPnPSiteDesignTaskTests.cs new file mode 100644 index 000000000..6b55e89d2 --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteDesignTaskTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteDesignTaskTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteDesignTaskTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: The ID of the site design task to retrieve. + var identity = ""; + // From Cmdlet Help: The URL of the site collection where the site design will be applied. If not specified the site design tasks will be returned for the site you connected to with Connect-PnPOnline. + var webUrl = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteDesignTask", + new CommandParameter("Identity", identity), + new CommandParameter("WebUrl", webUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteDesignTests.cs b/Tests/SiteDesigns/GetPnPSiteDesignTests.cs new file mode 100644 index 000000000..3fddf4b82 --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteDesignTests.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteDesignTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteDesignTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: If specified will retrieve the specified site design + var identity = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteDesign", + new CommandParameter("Identity", identity)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteScriptFromListTests.cs b/Tests/SiteDesigns/GetPnPSiteScriptFromListTests.cs new file mode 100644 index 000000000..c7b722b87 --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteScriptFromListTests.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteScriptFromListTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteScriptFromListTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the URL of the list to generate a Site Script from + var url = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteScriptFromList", + new CommandParameter("Url", url)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteScriptFromWebTests.cs b/Tests/SiteDesigns/GetPnPSiteScriptFromWebTests.cs new file mode 100644 index 000000000..403e4ef07 --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteScriptFromWebTests.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteScriptFromWebTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteScriptFromWebTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: Specifies the URL of the site to generate a Site Script from + var url = ""; + // From Cmdlet Help: Allows specifying one or more site relative URLs of lists that should be included into the Site Script, i.e. "Shared Documents","List\MyList" + var lists = ""; + // From Cmdlet Help: If specified will include all supported components into the Site Script + var includeAll = ""; + // From Cmdlet Help: If specified will include the branding of the site into the Site Script + var includeBranding = ""; + // From Cmdlet Help: If specified will include navigation links into the Site Script + var includeLinksToExportedItems = ""; + // From Cmdlet Help: If specified will include the regional settings into the Site Script + var includeRegionalSettings = ""; + // From Cmdlet Help: If specified will include the external sharing configuration into the Site Script + var includeSiteExternalSharingCapability = ""; + // From Cmdlet Help: If specified will include the branding of the site into the Site Script + var includeTheme = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteScriptFromWeb", + new CommandParameter("Url", url), + new CommandParameter("Lists", lists), + new CommandParameter("IncludeAll", includeAll), + new CommandParameter("IncludeBranding", includeBranding), + new CommandParameter("IncludeLinksToExportedItems", includeLinksToExportedItems), + new CommandParameter("IncludeRegionalSettings", includeRegionalSettings), + new CommandParameter("IncludeSiteExternalSharingCapability", includeSiteExternalSharingCapability), + new CommandParameter("IncludeTheme", includeTheme)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GetPnPSiteScriptTests.cs b/Tests/SiteDesigns/GetPnPSiteScriptTests.cs new file mode 100644 index 000000000..46d923bfd --- /dev/null +++ b/Tests/SiteDesigns/GetPnPSiteScriptTests.cs @@ -0,0 +1,80 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GetSiteScriptTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GetPnPSiteScriptTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: If specified will retrieve the specified site script + var identity = ""; + // From Cmdlet Help: If specified will retrieve the site scripts for this design + var siteDesign = ""; + + var results = scope.ExecuteCommand("Get-PnPSiteScript", + new CommandParameter("Identity", identity), + new CommandParameter("SiteDesign", siteDesign)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/GrantPnPSiteDesignRightsTests.cs b/Tests/SiteDesigns/GrantPnPSiteDesignRightsTests.cs new file mode 100644 index 000000000..ee164194b --- /dev/null +++ b/Tests/SiteDesigns/GrantPnPSiteDesignRightsTests.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class GrantSiteDesignRightsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void GrantPnPSiteDesignRightsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site design to use. + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: One or more principals to grant rights to. + var principals = ""; + // From Cmdlet Help: The rights to set. Defaults to 'View' + var rights = ""; + + var results = scope.ExecuteCommand("Grant-PnPSiteDesignRights", + new CommandParameter("Identity", identity), + new CommandParameter("Principals", principals), + new CommandParameter("Rights", rights)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/InvokePnPSiteDesignTests.cs b/Tests/SiteDesigns/InvokePnPSiteDesignTests.cs new file mode 100644 index 000000000..374cabdfe --- /dev/null +++ b/Tests/SiteDesigns/InvokePnPSiteDesignTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class InvokeSiteDesignTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void InvokePnPSiteDesignTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The Site Design Id or an actual Site Design object to apply + var identity = ""; + // From Cmdlet Help: The URL of the web to apply the site design to. If not specified it will default to the current web based upon the URL specified with Connect-PnPOnline. + var webUrl = ""; + + var results = scope.ExecuteCommand("Invoke-PnPSiteDesign", + new CommandParameter("Identity", identity), + new CommandParameter("WebUrl", webUrl)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/RemovePnPSiteDesignTaskTests.cs b/Tests/SiteDesigns/RemovePnPSiteDesignTaskTests.cs new file mode 100644 index 000000000..ccb55e313 --- /dev/null +++ b/Tests/SiteDesigns/RemovePnPSiteDesignTaskTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class RemoveSiteDesignTaskTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteDesignTaskTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID of the site design to remove + var identity = ""; + // From Cmdlet Help: If specified you will not be asked to confirm removing the specified Site Design + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteDesignTask", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/RemovePnPSiteDesignTests.cs b/Tests/SiteDesigns/RemovePnPSiteDesignTests.cs new file mode 100644 index 000000000..3d43f8f43 --- /dev/null +++ b/Tests/SiteDesigns/RemovePnPSiteDesignTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class RemoveSiteDesignTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteDesignTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID of the site design to remove + var identity = ""; + // From Cmdlet Help: If specified you will not be asked to confirm removing the specified Site Design + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteDesign", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/RemovePnPSiteScriptTests.cs b/Tests/SiteDesigns/RemovePnPSiteScriptTests.cs new file mode 100644 index 000000000..04fd63354 --- /dev/null +++ b/Tests/SiteDesigns/RemovePnPSiteScriptTests.cs @@ -0,0 +1,81 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class RemoveSiteScriptTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RemovePnPSiteScriptTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The ID of the Site Script to remove + var identity = ""; + // From Cmdlet Help: If specified you will not be asked to confirm removing the specified Site Script + var force = ""; + + var results = scope.ExecuteCommand("Remove-PnPSiteScript", + new CommandParameter("Identity", identity), + new CommandParameter("Force", force)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/RevokePnPSiteDesignRightsTests.cs b/Tests/SiteDesigns/RevokePnPSiteDesignRightsTests.cs new file mode 100644 index 000000000..91cad74ef --- /dev/null +++ b/Tests/SiteDesigns/RevokePnPSiteDesignRightsTests.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class RevokeSiteDesignRightsTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void RevokePnPSiteDesignRightsTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The site design to use. + var identity = ""; + // This is a mandatory parameter + // From Cmdlet Help: One or more principals to revoke. + var principals = ""; + + var results = scope.ExecuteCommand("Revoke-PnPSiteDesignRights", + new CommandParameter("Identity", identity), + new CommandParameter("Principals", principals)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/SetPnPSiteDesignTests.cs b/Tests/SiteDesigns/SetPnPSiteDesignTests.cs new file mode 100644 index 000000000..360743de2 --- /dev/null +++ b/Tests/SiteDesigns/SetPnPSiteDesignTests.cs @@ -0,0 +1,102 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class SetSiteDesignTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSiteDesignTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The guid or an object representing the site design + var identity = ""; + // From Cmdlet Help: The title of the site design + var title = ""; + // From Cmdlet Help: An array of guids of site scripts + var siteScriptIds = ""; + // From Cmdlet Help: The description of the site design + var description = ""; + // From Cmdlet Help: Specifies if the site design is a default site design + var isDefault = ""; + // From Cmdlet Help: Sets the text for the preview image + var previewImageAltText = ""; + // From Cmdlet Help: Sets the url to the preview image + var previewImageUrl = ""; + // From Cmdlet Help: Specifies the type of site to which this design applies + var webTemplate = ""; + // From Cmdlet Help: Specifies the version of the design + var version = ""; + + var results = scope.ExecuteCommand("Set-PnPSiteDesign", + new CommandParameter("Identity", identity), + new CommandParameter("Title", title), + new CommandParameter("SiteScriptIds", siteScriptIds), + new CommandParameter("Description", description), + new CommandParameter("IsDefault", isDefault), + new CommandParameter("PreviewImageAltText", previewImageAltText), + new CommandParameter("PreviewImageUrl", previewImageUrl), + new CommandParameter("WebTemplate", webTemplate), + new CommandParameter("Version", version)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/SiteDesigns/SetPnPSiteScriptTests.cs b/Tests/SiteDesigns/SetPnPSiteScriptTests.cs new file mode 100644 index 000000000..1f63df268 --- /dev/null +++ b/Tests/SiteDesigns/SetPnPSiteScriptTests.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.SiteDesigns +{ + [TestClass] + public class SetSiteScriptTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void SetPnPSiteScriptTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // This is a mandatory parameter + // From Cmdlet Help: The guid or an object representing the site script + var identity = ""; + // From Cmdlet Help: The title of the site script + var title = ""; + // From Cmdlet Help: The description of the site script + var description = ""; + // From Cmdlet Help: A JSON string containing the site script + var content = ""; + // From Cmdlet Help: Specifies the version of the site script + var version = ""; + + var results = scope.ExecuteCommand("Set-PnPSiteScript", + new CommandParameter("Identity", identity), + new CommandParameter("Title", title), + new CommandParameter("Description", description), + new CommandParameter("Content", content), + new CommandParameter("Version", version)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/Tests/Taxonomy/ExportPnPTaxonomyTests.cs b/Tests/Taxonomy/ExportPnPTaxonomyTests.cs new file mode 100644 index 000000000..3addbe7c4 --- /dev/null +++ b/Tests/Taxonomy/ExportPnPTaxonomyTests.cs @@ -0,0 +1,98 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace SharePointPnP.PowerShell.Tests.Taxonomy +{ + [TestClass] + public class ExportTaxonomyTests + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [ClassCleanup] + public static void Cleanup(TestContext testContext) + { + // This runs on class level once + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + + [TestInitialize] + public void Initialize() + { + using (var scope = new PSTestScope()) + { + // Example + // scope.ExecuteCommand("cmdlet", new CommandParameter("param1", prop)); + } + } + + [TestCleanup] + public void Cleanup() + { + using (var scope = new PSTestScope()) + { + try + { + // Do Test Setup - Note, this runs PER test + } + catch (Exception) + { + // Describe Exception + } + } + } + #endregion + + #region Scaffolded Cmdlet Tests + //TODO: This is a scaffold of the cmdlet - complete the unit test + //[TestMethod] + public void ExportPnPTaxonomyTest() + { + using (var scope = new PSTestScope(true)) + { + // Complete writing cmd parameters + + // From Cmdlet Help: If specified, will export the specified termset only + var termSetId = ""; + // From Cmdlet Help: If specified will include the ids of the taxonomy items in the output. Format: