Skip to content

Commit

Permalink
Merge pull request #1 from kfchendllt/dev
Browse files Browse the repository at this point in the history
Include timezone option for the site creation #1265
  • Loading branch information
kfircs authored Dec 15, 2023
2 parents 5a3365f + 86d4e02 commit cdd8ce8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
64 changes: 64 additions & 0 deletions src/sdk/PnP.Core.Admin.Test/SharePoint/SiteManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,70 @@ await context.GetSiteCollectionManager().SetSiteCollectionAdminsAsync(
}
}

[TestMethod]
public async Task SetSiteCollectionWithTimeZome_Async()
{
//Time zone object to test with
var selectedTimeZone = TimeZone.UTCPLUS0200_JERUSALEM;

//TestCommon.Instance.Mocking = false;
TestCommon.Instance.UseApplicationPermissions = false;

CommunicationSiteOptions communicationSiteToCreate = null;

// Create the site collection
try
{
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
// Persist the used site url as we need to have the same url when we run an offline test
Uri siteUrl;
if (!TestCommon.Instance.Mocking)
{
siteUrl = new Uri($"https://{context.Uri.DnsSafeHost}/sites/pnpcoresdktestcommsite{Guid.NewGuid().ToString().Replace("-", "")}");
Dictionary<string, string> properties = new Dictionary<string, string>
{
{ "SiteUrl", siteUrl.ToString() }
};
TestManager.SaveProperties(context, properties);
}
else
{
siteUrl = new Uri(TestManager.GetProperties(context)["SiteUrl"]);
}

communicationSiteToCreate = new CommunicationSiteOptions(siteUrl, "PnP Core SDK Test")
{
Description = "This is a test site collection",
Language = Language.English,
TimeZone = selectedTimeZone
};

SiteCreationOptions siteCreationOptions = new()
{
UsingApplicationPermissions = false
};

var siteProperties = context.GetSiteCollectionManager().GetSiteCollectionProperties(context.Uri);

//Validating time zone set as expected
Assert.IsTrue(siteProperties.TimeZoneId == selectedTimeZone);

if (context.Mode == TestMode.Record)
{
// Add a little delay between creation and deletion
await Task.Delay(TimeSpan.FromSeconds(15));
}
}
}
finally
{
TestCommon.Instance.UseApplicationPermissions = false;
using var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite, 1);
await context.GetSiteCollectionManager().DeleteSiteCollectionAsync(communicationSiteToCreate.Url);
}
}

[TestMethod]
public async Task SetSiteCollectionAdminsGroupSite()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ private static async Task<PnPContext> CreateCommonNoGroupSiteAsync(PnPContext co
payload["Classification"] = siteToCreate.Classification ?? "";
}

if (siteToCreate.TimeZone.HasValue)
{
payload.Add("TimeZoneId", (int)siteToCreate.TimeZone.Value);
}


return await CreateSiteUsingSpoRestImplementationAsync(context, SiteCreationModel.SPSiteManagerCreate, payload, creationOptions).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public CommonNoGroupSiteOptions(Uri url, string title)
/// <summary>
/// The Sensitivity label to use. See https://www.youtube.com/watch?v=NxvUXBiPFcw for more information.
/// </summary>
public Guid SensitivityLabelId { get; set; }

public Guid SensitivityLabelId { get; set; }

/// <summary>
/// The time zone to use for the site.
/// </summary>
public TimeZone? TimeZone { get; set; }
}
}

0 comments on commit cdd8ce8

Please sign in to comment.