Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/Admin/AddTenantRestrictedSearchAllowedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void ExecuteCmdlet()
}
else
{
throw new ArgumentException("Parameter set cannot be resolved using the specified named parameters.");
throw new InvalidOperationException("Parameter set cannot be resolved using the specified named parameters.");
}

if (_sitelist == null)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/GetContainerTypeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void ExecuteCmdlet()
{
if (Identity == Guid.Empty)
{
throw new ArgumentException($"Identity {Identity} value is invalid");
throw new PSArgumentException($"Identity cannot be an empty GUID. Please provide a valid non-empty GUID.");
}
ClientResult<SPContainerTypeConfigurationProperties> sPOContainerTypeConfigurationByContainerTypeId = Tenant.GetSPOContainerTypeConfigurationByContainerTypeId(Identity);
AdminContext.ExecuteQueryRetry();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/GetStorageEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected override void ExecuteCmdlet()
{
var storageEntitiesDict = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(storageEntitiesIndex);

var storageEntities = new List<StorageEntity>();
var storageEntities = new List<StorageEntity>(storageEntitiesDict.Count);
foreach (var key in storageEntitiesDict.Keys)
{
var storageEntity = new StorageEntity
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Admin/GetTenantDeletedSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void ExecuteCmdlet()
bool flag = Identity != null && !string.IsNullOrEmpty(Identity.Url) && UrlUtilities.IsPersonalSiteUrl(Identity.Url);
if (Identity == null || string.IsNullOrEmpty(Identity.Url) || flag)
{
List<DeletedSiteProperties> list = new List<DeletedSiteProperties>();
List<DeletedSiteProperties> list = [];
uint siteRowLimit = Limit;
bool flag2 = siteRowLimit == 0;
bool flag3 = false;
Expand Down Expand Up @@ -95,7 +95,7 @@ private bool RequestDeletedSitePropertiesFromSharePoint(Func<string, SPODeletedS
SPODeletedSitePropertiesEnumerable spoDeletedSitePropertiesEnumerable = getDeletedSitePropertiesFunc(text);
if (spoDeletedSitePropertiesEnumerable == null)
{
throw new ArgumentNullException("Something went wrong fetching deleted sites");
throw new InvalidOperationException("Failed to retrieve deleted sites from SharePoint Online");
}
AdminContext.Load(spoDeletedSitePropertiesEnumerable);
AdminContext.Load(spoDeletedSitePropertiesEnumerable, (SPODeletedSitePropertiesEnumerable sp) => sp.NextStartIndexFromSharePoint);
Expand Down Expand Up @@ -146,7 +146,7 @@ private bool RequestDeletedSiteProperties(Func<int, SPODeletedSitePropertiesEnum
AdminContext.ExecuteQueryRetry();
if (spoDeletedSitePropertiesEnumerable == null)
{
throw new ArgumentNullException("Something went wrong fetching deleted sites");
throw new InvalidOperationException("Failed to retrieve deleted sites from SharePoint Online");
}
checked
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/RemoveTenantSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void ExecuteCmdlet()
dodelete = ShouldContinue("You are trying to delete the root site collection. Be aware that you need to contact Office 365 Support in order to create a new root site collection. Also notice that some CSOM and REST operations require the root site collection to be present. Removing this site can affect all your remote processing code, even when accessing non-root site collections.", Resources.Confirm);
}

if (dodelete && (Force || ShouldContinue(string.Format(Resources.RemoveSiteCollection0, Url), Resources.Confirm)))
if (dodelete && (Force || ShouldContinue($"Remove site collection '{Url}'?", Resources.Confirm)))
{

Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/RemoveTenantSyncClientRestriction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void ExecuteCmdlet()
{
Tenant.IsUnmanagedSyncClientForTenantRestricted = false;
Tenant.BlockMacSync = false;
Tenant.ExcludedFileExtensionsForSyncClient = new List<string>();
Tenant.ExcludedFileExtensionsForSyncClient = [];
Tenant.OptOutOfGrooveBlock = false;
Tenant.OptOutOfGrooveSoftBlock = false;
Tenant.DisableReportProblemDialog = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/SetTenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ protected override void ExecuteCmdlet()
else
{
// Build a GUID array by resolving each provided site URL to its SiteProperties and extracting the Id
var siteIdList = new List<Guid>();
var siteIdList = new List<Guid>(KnowledgeAgentSelectedSitesList.Length);
var tenantForLookup = new Tenant(AdminContext);

foreach (var siteUrl in KnowledgeAgentSelectedSitesList)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/SetTenantSyncClientRestriction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override void ExecuteCmdlet()
break;

default:
throw new PSArgumentException(string.Format(Resources.GrooveBlockOptionNotSupported, nameof(GrooveBlockOption), GrooveBlockOption), nameof(GrooveBlockOption));
throw new PSArgumentException($"Parameter '{nameof(GrooveBlockOption)}' does not support value '{GrooveBlockOption}'. Supported values are: OptOut, HardOptin, SoftOptin", nameof(GrooveBlockOption));
}
}
AdminContext.ExecuteQueryRetry();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Apps/GetApplicationCustomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GetApplicationCustomizer : PnPWebRetrievalsCmdlet<UserCustomAction>

protected override void ExecuteCmdlet()
{
List<UserCustomAction> actions = new List<UserCustomAction>();
List<UserCustomAction> actions = [];

if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Apps/GetAzureADAppSitePermission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void ExecuteCmdlet()
var permissions = this.GraphRequestHelper.GetResultCollection<AzureADAppPermissionInternal>($"v1.0/sites/{siteId}/permissions?$select=Id");
if (permissions.Any())
{
var results = new List<AzureADAppPermission>();
var results = new List<AzureADAppPermission>(permissions.Count());
foreach (var permission in permissions)
{
// Request the permission individually so it will include the roles
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/AzureAD/NewAzureADGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void ExecuteCmdlet()
{
var existingGroup = AzureADGroupsUtility.GetGroup(GraphRequestHelper, MailNickname);

forceCreation = existingGroup == null || ShouldContinue(string.Format(Resources.ForceCreationOfExistingGroup0, MailNickname), Resources.Confirm);
forceCreation = existingGroup == null || ShouldContinue($"The Unified Group with MailNickname of {MailNickname} already exists. Do you want to create another one?", Resources.Confirm);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/AzureAD/RegisterAzureADApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private X509Certificate2 GetCertificate(PSObject record)
// Ensure a file exists at the provided CertificatePath
if (!File.Exists(CertificatePath))
{
throw new PSArgumentException(string.Format(Resources.CertificateNotFoundAtPath, CertificatePath), nameof(CertificatePath));
throw new PSArgumentException($"Certificate not found at path: {CertificatePath}", nameof(CertificatePath));
}

try
Expand All @@ -469,7 +469,7 @@ private X509Certificate2 GetCertificate(PSObject record)
}
catch (CryptographicException e) when (e.Message.Contains("The specified password is not correct"))
{
throw new PSArgumentNullException(nameof(CertificatePassword), string.Format(Resources.PrivateKeyCertificateImportFailedPasswordIncorrect, nameof(CertificatePassword)));
throw new PSArgumentNullException(nameof(CertificatePassword), $"Failed to import private key certificate. Ensure the correct password is provided for parameter: {nameof(CertificatePassword)}");
}

// Ensure the certificate at the provided CertificatePath holds a private key
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/SiteDesigns/GetBuiltInSiteTemplateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Enums;
using PnP.PowerShell.Commands.Model.SharePoint;
using System;
using System.Linq;
using System.Management.Automation;

Expand All @@ -28,7 +29,8 @@ protected override void ExecuteCmdlet()
ClientResult<TenantOutOfBoxSiteTemplateSettings> templateSetting = null;
if (ParameterSpecified(nameof(Identity)))
{
if (Identity == null || !Identity.Id.HasValue) throw new PSArgumentException($"Identity contains an invalid {nameof(BuiltInSiteTemplateSettingsPipeBind)} value", nameof(Identity));
ArgumentNullException.ThrowIfNull(Identity, nameof(Identity));
if (!Identity.Id.HasValue) throw new PSArgumentException($"Identity contains an invalid {nameof(BuiltInSiteTemplateSettingsPipeBind)} value", nameof(Identity));

templateSetting = Tenant.GetOutOfBoxSiteTemplateSettings(AdminContext, Identity.Id.Value);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/SiteDesigns/SetBuiltInSiteTemplateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Enums;
using PnP.PowerShell.Commands.Model.SharePoint;
using System;
using System.Linq;
using System.Management.Automation;

Expand Down Expand Up @@ -36,7 +37,8 @@ protected override void ExecuteCmdlet()
ClientResult<TenantOutOfBoxSiteTemplateSettings> templateSetting = null;
if (ParameterSpecified(nameof(Identity)))
{
if (Identity == null || !Identity.Id.HasValue) throw new PSArgumentException($"Identity contains an invalid {nameof(BuiltInSiteTemplateSettingsPipeBind)} value", nameof(Identity));
ArgumentNullException.ThrowIfNull(Identity, nameof(Identity));
if (!Identity.Id.HasValue) throw new PSArgumentException($"Identity contains an invalid {nameof(BuiltInSiteTemplateSettingsPipeBind)} value", nameof(Identity));

if (!ParameterSpecified(nameof(WhatIf)))
{
Expand Down
32 changes: 16 additions & 16 deletions src/Commands/Utilities/DynamicLinq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static IQueryable<T> Where<T>(this IQueryable<T> source, string predicate

public static IQueryable Where(this IQueryable source, string predicate, params object[] values)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(predicate);
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, values);
return source.Provider.CreateQuery(
Expression.Call(
Expand All @@ -32,8 +32,8 @@ public static IQueryable Where(this IQueryable source, string predicate, params

public static IQueryable Select(this IQueryable source, string selector, params object[] values)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (selector == null) throw new ArgumentNullException(nameof(selector));
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(selector);
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, null, selector, values);
return source.Provider.CreateQuery(
Expression.Call(
Expand All @@ -49,8 +49,8 @@ public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string orderin

public static IQueryable OrderBy(this IQueryable source, string ordering, params object[] values)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (ordering == null) throw new ArgumentNullException(nameof(ordering));
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(ordering);
ParameterExpression[] parameters = new ParameterExpression[] {
Expression.Parameter(source.ElementType, "") };
ExpressionParser parser = new ExpressionParser(parameters, ordering, values);
Expand All @@ -72,7 +72,7 @@ public static IQueryable OrderBy(this IQueryable source, string ordering, params

public static IQueryable Take(this IQueryable source, int count)
{
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(source);
return source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Take",
Expand All @@ -82,7 +82,7 @@ public static IQueryable Take(this IQueryable source, int count)

public static IQueryable Skip(this IQueryable source, int count)
{
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(source);
return source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Skip",
Expand All @@ -92,9 +92,9 @@ public static IQueryable Skip(this IQueryable source, int count)

public static IQueryable GroupBy(this IQueryable source, string keySelector, string elementSelector, params object[] values)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
if (elementSelector == null) throw new ArgumentNullException(nameof(elementSelector));
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
ArgumentNullException.ThrowIfNull(elementSelector);
LambdaExpression keyLambda = DynamicExpression.ParseLambda(source.ElementType, null, keySelector, values);
LambdaExpression elementLambda = DynamicExpression.ParseLambda(source.ElementType, null, elementSelector, values);
return source.Provider.CreateQuery(
Expand All @@ -106,7 +106,7 @@ public static IQueryable GroupBy(this IQueryable source, string keySelector, str

public static bool Any(this IQueryable source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(source);
return (bool)source.Provider.Execute(
Expression.Call(
typeof(Queryable), "Any",
Expand All @@ -115,7 +115,7 @@ public static bool Any(this IQueryable source)

public static int Count(this IQueryable source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(source);
return (int)source.Provider.Execute(
Expression.Call(
typeof(Queryable), "Count",
Expand Down Expand Up @@ -149,8 +149,8 @@ public class DynamicProperty

public DynamicProperty(string name, Type type)
{
if (name == null) throw new ArgumentNullException(nameof(name));
if (type == null) throw new ArgumentNullException(nameof(type));
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(type);
this.name = name;
this.type = type;
}
Expand Down Expand Up @@ -636,7 +636,7 @@ interface IEnumerableSignatures

public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values)
{
if (expression == null) throw new ArgumentNullException(nameof(expression));
ArgumentNullException.ThrowIfNull(expression);
if (keywords == null) keywords = CreateKeywords();
symbols = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
literals = new Dictionary<Expression, string>();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Utilities/REST/RestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static string ExecuteGetRequest(ClientContext context, string endPointUrl
StringBuilder sb = new StringBuilder();
foreach (var cookie in authManager.CookieContainer.GetCookies(new Uri(url)))
{
sb.AppendFormat("{0}; ", cookie.ToString());
sb.Append($"{cookie}; ");
}
client.DefaultRequestHeaders.Add("Cookie", sb.ToString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/PnP.PowerShell.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>PnP.PowerShell.Tests</AssemblyName>
<RootNamespace>PnP.PowerShell.Tests</RootNamespace>
Expand All @@ -10,7 +10,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Authors>PnP.PowerShell</Authors>
<Configurations>Debug;Release;DebugLocal</Configurations>
<LocalPnPFramework Condition="'$(LocalPnPFramework)' == ''">false</LocalPnPFramework>
<LocalPnPFramework Condition="'$(LocalPnPFramework)' == ''">false</LocalPnPFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading