public async Task HandleExceptions() { //TestCommon.Instance.Mocking = false; TestCommon.Instance.UseApplicationPermissions = false; using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite)) { Assert.ThrowsException <ArgumentNullException>(() => { SiteCreationOptions siteCreationOptions = new SiteCreationOptions() { UsingApplicationPermissions = false }; using (var newSiteContext = context.GetSiteCollectionManager().CreateSiteCollection(null, siteCreationOptions)) { } }); Assert.ThrowsException <ArgumentNullException>(() => { CommunicationSiteOptions communicationSiteToCreate = new CommunicationSiteOptions(null, "PnP Core SDK Test") { Description = "This is a test site collection", Language = Language.English, }; }); Assert.ThrowsException <ArgumentNullException>(() => { CommunicationSiteOptions communicationSiteToCreate = new CommunicationSiteOptions(new Uri("https://contoso.sharepoint.com/sites/dummy"), null) { Description = "This is a test site collection", Language = Language.English, }; }); Assert.ThrowsException <ArgumentNullException>(() => { TeamSiteOptions communicationSiteToCreate = new TeamSiteOptions(null, "display name"); }); Assert.ThrowsException <ArgumentNullException>(() => { TeamSiteOptions communicationSiteToCreate = new TeamSiteOptions("alias", null); }); Assert.ThrowsException <ArgumentNullException>(() => { ClassicSiteOptions communicationSiteToCreate = new ClassicSiteOptions(null, "title", "webtemplate", "owner", Language.Default, Model.SharePoint.TimeZone.None); }); Assert.ThrowsException <ArgumentNullException>(() => { ClassicSiteOptions communicationSiteToCreate = new ClassicSiteOptions(new Uri("https://contoso.sharepoint.com/sites/dummy"), "", "webtemplate", "owner", Language.Default, Model.SharePoint.TimeZone.None); }); Assert.ThrowsException <ArgumentNullException>(() => { ClassicSiteOptions communicationSiteToCreate = new ClassicSiteOptions(new Uri("https://contoso.sharepoint.com/sites/dummy"), "title", "", "owner", Language.Default, Model.SharePoint.TimeZone.None); }); Assert.ThrowsException <ArgumentNullException>(() => { ClassicSiteOptions communicationSiteToCreate = new ClassicSiteOptions(new Uri("https://contoso.sharepoint.com/sites/dummy"), "title", "webtemplate", "", Language.Default, Model.SharePoint.TimeZone.None); }); Assert.ThrowsException <ArgumentException>(() => { ClassicSiteOptions communicationSiteToCreate = new ClassicSiteOptions(new Uri("https://contoso.sharepoint.com/sites/dummy"), "title", "webtemplate", "owner", Language.Default, Model.SharePoint.TimeZone.None); }); Assert.ThrowsException <ArgumentNullException>(() => { CreationOptions creationOptions = new CreationOptions() { UsingApplicationPermissions = false }; context.GetSiteCollectionManager().ConnectSiteCollectionToGroup(null, creationOptions); }); Assert.ThrowsException <ArgumentNullException>(() => { ConnectSiteToGroupOptions communicationSiteToCreate = new ConnectSiteToGroupOptions(null, "alias", "displayname"); }); Assert.ThrowsException <ArgumentNullException>(() => { context.GetSiteCollectionManager().RecycleSiteCollection(null); }); Assert.ThrowsException <ArgumentNullException>(() => { context.GetSiteCollectionManager().RestoreSiteCollection(null); }); Assert.ThrowsException <ArgumentNullException>(() => { context.GetSiteCollectionManager().DeleteSiteCollection(null); }); Assert.ThrowsException <ArgumentNullException>(() => { context.GetSiteCollectionManager().GetSiteCollectionProperties(null); }); } }
public async Task ConnectGroupToExistingSiteUsingDelegatedPermissions() { //TestCommon.Instance.Mocking = false; TestCommon.Instance.UseApplicationPermissions = false; TeamSiteWithoutGroupOptions teamSiteToCreate = null; 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; string alias = null; if (!TestCommon.Instance.Mocking) { Guid tempId = Guid.NewGuid(); siteUrl = new Uri($"https://{context.Uri.DnsSafeHost}/sites/pnpcoresdktestteamsite{tempId.ToString().Replace("-", "")}"); alias = $"pnpcoresdktestteamsite{tempId.ToString().Replace("-", "")}"; Dictionary <string, string> properties = new Dictionary <string, string> { { "SiteUrl", siteUrl.ToString() }, { "Alias", alias }, }; TestManager.SaveProperties(context, properties); } else { siteUrl = new Uri(TestManager.GetProperties(context)["SiteUrl"]); alias = TestManager.GetProperties(context)["Alias"]; } teamSiteToCreate = new TeamSiteWithoutGroupOptions(siteUrl, "PnP Core SDK Test") { Description = "This is a test site collection", Language = Language.English, }; SiteCreationOptions siteCreationOptions = new SiteCreationOptions() { UsingApplicationPermissions = false }; // first create the site collection using (var newSiteContext = context.GetSiteCollectionManager().CreateSiteCollection(teamSiteToCreate, siteCreationOptions)) { var web = await newSiteContext.Web.GetAsync(p => p.Url, p => p.Title); // Add a group to the created site collection ConnectSiteToGroupOptions groupConnectOptions = new ConnectSiteToGroupOptions(teamSiteToCreate.Url, alias, web.Title); CreationOptions creationOptions = new CreationOptions() { UsingApplicationPermissions = false }; newSiteContext.GetSiteCollectionManager().ConnectSiteCollectionToGroup(groupConnectOptions, creationOptions); // load site again to see if there's a group connected await context.Site.LoadAsync(p => p.GroupId); Assert.IsTrue(context.Site.GroupId != Guid.Empty); } } } finally { TestCommon.Instance.UseApplicationPermissions = false; // Cleanup the created site collection using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite, 1)) { context.GetSiteCollectionManager().DeleteSiteCollection(teamSiteToCreate.Url); } } }