Exemple #1
0
        public async Task GetSensitivityLabelsUsingApplicationPermissions()
        {
            //TestCommon.Instance.Mocking = false;
            TestCommon.Instance.UseApplicationPermissions = true;
            try
            {
                using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
                {
                    var labels = await SensitivityLabelManager.GetLabelsUsingApplicationPermissionsAsync(context);

                    Assert.IsTrue(labels.Any());
                }
            }
            finally
            {
                TestCommon.Instance.UseApplicationPermissions = false;
            }
        }
Exemple #2
0
        public async Task CreateCommunicationSiteAdvancedUsingDelegatedPermissions()
        {
            //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))
                {
                    // Get a list of available sensitivity labels
                    var labels = await SensitivityLabelManager.GetLabelsUsingDelegatedPermissionsAsync(context);

                    var  siteLabel          = labels.FirstOrDefault();
                    Guid sensitivityLabelId = Guid.Empty;

                    // 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("-", "")}");

                        if (siteLabel != null)
                        {
                            sensitivityLabelId = siteLabel.Id;
                        }

                        Dictionary <string, string> properties = new Dictionary <string, string>
                        {
                            { "SiteUrl", siteUrl.ToString() },
                            { "SensitivityLabelId", sensitivityLabelId.ToString() }
                        };

                        TestManager.SaveProperties(context, properties);
                    }
                    else
                    {
                        siteUrl            = new Uri(TestManager.GetProperties(context)["SiteUrl"]);
                        sensitivityLabelId = Guid.Parse(TestManager.GetProperties(context)["SensitivityLabelId"]);
                    }

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


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

                    using (var newSiteContext = context.GetSiteCollectionManager().CreateSiteCollection(communicationSiteToCreate, siteCreationOptions))
                    {
                        var site = await newSiteContext.Site.GetAsync(p => p.SensitivityLabelId, p => p.SensitivityLabel);

                        var web = await newSiteContext.Web.GetAsync(p => p.Url, p => p.Title, p => p.Description, p => p.Language);

                        Assert.IsTrue(web.Url == communicationSiteToCreate.Url);
                        Assert.IsTrue(web.Title == communicationSiteToCreate.Title);
                        Assert.IsTrue(web.Description == communicationSiteToCreate.Description);
                        Assert.IsTrue(web.Language == (int)communicationSiteToCreate.Language);
                        Assert.IsTrue(site.SensitivityLabelId == communicationSiteToCreate.SensitivityLabelId);
                    }

                    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))
                {
                    context.GetSiteCollectionManager().DeleteSiteCollection(communicationSiteToCreate.Url);
                }
            }
        }