internal static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName)
        {
            try
            {
                string devSiteUrl      = ConfigurationManager.AppSettings["SPODevSiteUrl"];
                string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);

                string siteOwnerLogin = ConfigurationManager.AppSettings["SPOUserName"];
                if (TestCommon.AppOnlyTesting())
                {
                    using (var clientContext = TestCommon.CreateClientContext())
                    {
                        List <UserEntity> admins = clientContext.Web.GetAdministrators();
                        siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                    }
                }

                SiteEntity siteToCreate = new SiteEntity()
                {
                    Url            = siteToCreateUrl,
                    Template       = "STS#0",
                    Title          = "Test",
                    Description    = "Test site collection",
                    SiteOwnerLogin = siteOwnerLogin,
                };

                tenant.CreateSiteCollection(siteToCreate, false, true);
                return(siteToCreateUrl);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Example #2
0
        public void SetDefaultColumnValuesTest()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Taxonomy tests are not supported when testing using app-only");
            }

            using (var clientContext = TestCommon.CreateClientContext())
            {
                TaxonomySession            taxSession    = TaxonomySession.GetTaxonomySession(clientContext);
                List <IDefaultColumnValue> defaultValues = new List <IDefaultColumnValue>();

                var defaultColumnValue = new DefaultColumnTermValue();

                defaultColumnValue.FieldInternalName  = "TaxKeyword"; // Enterprise metadata field, should be present on the list
                defaultColumnValue.FolderRelativePath = "/";          // Root Folder
                var term = taxSession.GetTerm(_termId);
                defaultColumnValue.Terms.Add(term);
                defaultValues.Add(defaultColumnValue);

                var testDefaultValue = new DefaultColumnTextValue();
                testDefaultValue.Text = "Bla";
                testDefaultValue.FieldInternalName  = _textFieldName;
                testDefaultValue.FolderRelativePath = "/"; // Root folder

                defaultValues.Add(testDefaultValue);

                var list = clientContext.Web.Lists.GetById(_listId);

                list.SetDefaultColumnValues(defaultValues);
            }
        }
Example #3
0
        public void CleanUp()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                using (var ctx = TestCommon.CreateClientContext())
                {
                    try
                    {
                        TaxonomySession session = TaxonomySession.GetTaxonomySession(ctx);

                        var store    = session.GetDefaultSiteCollectionTermStore();
                        var termSet1 = store.GetTermSet(_termSetGuid);
                        var termSet2 = store.GetTermSet(_additionalTermSetGuid);

                        termSet1.DeleteObject();
                        termSet2.DeleteObject();

                        store.CommitAll();
                        ctx.ExecuteQueryRetry();

                        if (_termGroupGuid != Guid.Empty)
                        {
                            var termGroup = store.GetGroup(_termGroupGuid);
                            termGroup.DeleteObject();
                        }
                        store.CommitAll();
                        ctx.ExecuteQueryRetry();
                    }
                    catch
                    {
                    }
                }
            }
        }
 public void Initialize()
 {
     if (TestCommon.AppOnlyTesting())
     {
         Assert.Inconclusive("Search tests are not supported when testing using app-only");
     }
 }
Example #5
0
        public void CleanUp()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                using (new PnPProvisioningContext((resource, scope) => Task.FromResult(TestCommon.AcquireTokenAsync(resource, scope))))
                {
                    foreach (var teamName in _teamNames)
                    {
                        var teams = GetTeamsByDisplayName(teamName);

                        foreach (var team in teams)
                        {
                            try
                            {
                                DeleteTeam(team["id"].ToString());
                            }
                            catch (Exception ex)
                            {
                                // NOOP
                            }
                        }
                    }
                }
            }
        }
        public void Initialize()
        {
#if !ONPREMISES
            _userLogin = ConfigurationManager.AppSettings["SPOUserName"];
            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    _userLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                }
            }
#else
            _userLogin = String.Format(@"{0}\{1}", ConfigurationManager.AppSettings["OnPremDomain"], ConfigurationManager.AppSettings["OnPremUserName"]);
            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    _userLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }
#endif

            using (ClientContext clientContext = TestCommon.CreateClientContext())
            {
                clientContext.Web.AddGroup(_testGroupName, "", true, true);
            }
        }
Example #7
0
        public void CanProvisionHierarchy()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Template requires term store work, so this will not work in app-only");
            }

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                                  AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var hierarchy = provider.GetHierarchy("ProvisioningSchema-2019-03-FullSample-01.xml");

            CanProvisionResult result = null;

            using (var pnpContext = new PnPProvisioningContext())
            {
                using (var tenantContext = TestCommon.CreateTenantClientContext())
                {
                    var applyingInformation = new ProvisioningTemplateApplyingInformation();
                    var tenant = new Tenant(tenantContext);
                    result = CanProvisionRulesManager.CanProvision(tenant, hierarchy, String.Empty, applyingInformation);
                }
            }

            Assert.IsNotNull(result);
            Assert.IsTrue(result.CanProvision);
        }
Example #8
0
        public void CanProvisionObjects()
        {
#if !ONPREMISES
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("This test requires a user credentials, cannot be run using app-only for now");
            }

            using (new PnPProvisioningContext((resource, scope) => Task.FromResult(TestCommon.AcquireTokenAsync(resource, scope))))
            {
                var template = new ProvisioningTemplate {
                    ParentHierarchy = new ProvisioningHierarchy()
                };

                template.ParentHierarchy.Teams.TeamTemplates.Add(new TeamTemplate {
                    JsonTemplate = _jsonTemplate
                });
                template.ParentHierarchy.Teams.Teams.Add(_team);

                Provision(template);

                // Wait for groups to be provisioned
                Thread.Sleep(5000);

                // Verify if Teams have been provisioned
                foreach (var teamName in _teamNames)
                {
                    var teams = GetTeamsByDisplayName(teamName);
                    Assert.IsTrue(teams.HasValues);
                }
            }
#else
            Assert.Inconclusive();
#endif
        }
Example #9
0
        public void CanProvisionSite()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Template requires term store work, so this will not work in app-only");
            }

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                                  AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var hierarchy = provider.GetHierarchy("ProvisioningSchema-2019-03-FullSample-01.xml");

            CanProvisionResult result = null;

            using (var pnpContext = new PnPProvisioningContext())
            {
                using (var context = TestCommon.CreateClientContext())
                {
                    var applyingInformation = new ProvisioningTemplateApplyingInformation();
                    result = CanProvisionRulesManager.CanProvision(context.Web, hierarchy.Templates[0], applyingInformation);
                }
            }

            Assert.IsNotNull(result);
#if ONPREMISES
            // Because the "apps" rule is verified here
            Assert.IsFalse(result.CanProvision);
#else
            Assert.IsTrue(result.CanProvision);
#endif
        }
        public void CleanUp()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateTenantClientContext())
                {
                    var tenant = new Tenant(clientContext);

                    var communicationSiteUrl = $"{baseUrl}/sites/site{communicationSiteGuid}";
                    if (tenant.SiteExistsAnywhere(communicationSiteUrl) != SiteExistence.No)
                    {
#if !ONPREMISES
                        tenant.DeleteSiteCollection(communicationSiteUrl, false);
#else
                        tenant.DeleteSiteCollection(communicationSiteUrl);
#endif
                    }

                    var teamSiteUrl = $"{baseUrl}/sites/site{teamSiteGuid}";
                    if (tenant.SiteExistsAnywhere(teamSiteUrl) != SiteExistence.No)
                    {
#if !ONPREMISES
                        tenant.DeleteSiteCollection(teamSiteUrl, false);
#else
                        tenant.DeleteSiteCollection(teamSiteUrl);
#endif
                    }

                    // Commented this, first group cleanup needs to be implemented in this test case
                    //tenant.DeleteSiteCollection($"{baseUrl}/sites/site{teamSiteGuid}", false);
                    //TODO: Cleanup group
                }
            }
        }
        public async Task CanMapAssociatedGroupsToExistingOnesInNewScriptSite()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Site creation requires owner, so this will not yet work in app-only");
            }

            var newCommSiteUrl = string.Empty;

            ProvisioningTemplate template = new ProvisioningTemplate();

            template.Security.AssociatedOwnerGroup   = "These names shouldn't matter";
            template.Security.AssociatedMemberGroup  = "Site Members";
            template.Security.AssociatedVisitorGroup = "Dummy Visitors";
            // note: there are explicitly no SiteGroups defined

            using (var clientContext = TestCommon.CreateClientContext())
            {
                newCommSiteUrl = await CreateCommunicationSite(clientContext, "Dummy", true);
            }

            try
            {
                using (var ctx = TestCommon.CreateClientContext(newCommSiteUrl))
                {
                    ctx.Load(ctx.Web,
                             w => w.AssociatedOwnerGroup.Id,
                             w => w.AssociatedMemberGroup.Id,
                             w => w.AssociatedVisitorGroup.Id);
                    ctx.ExecuteQuery();
                    var oldOwnerGroupId   = ctx.Web.AssociatedOwnerGroup.Id;
                    var oldMemberGroupId  = ctx.Web.AssociatedMemberGroup.Id;
                    var oldVisitorGroupId = ctx.Web.AssociatedVisitorGroup.Id;

                    var parser = new TokenParser(ctx.Web, template);
                    new ObjectSiteSecurity().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                    ctx.Load(ctx.Web,
                             w => w.AssociatedOwnerGroup.Id,
                             w => w.AssociatedMemberGroup.Id,
                             w => w.AssociatedVisitorGroup.Id);
                    ctx.ExecuteQuery();
                    var newOwnerGroupId   = ctx.Web.AssociatedOwnerGroup.Id;
                    var newMemberGroupId  = ctx.Web.AssociatedMemberGroup.Id;
                    var newVisitorGroupId = ctx.Web.AssociatedVisitorGroup.Id;

                    Assert.AreEqual(oldOwnerGroupId, newOwnerGroupId, "Unexpected new associated owner group");
                    Assert.AreEqual(oldMemberGroupId, newMemberGroupId, "Unexpected new associated member group");
                    Assert.AreEqual(oldVisitorGroupId, newVisitorGroupId, "Unexpected new associated visitor group");
                }
            }
            finally
            {
                using (var clientContext = TestCommon.CreateTenantClientContext())
                {
                    var tenant = new Tenant(clientContext);
                    tenant.DeleteSiteCollection(newCommSiteUrl, false);
                }
            }
        }
        private string CreateTestSiteCollection(Tenant tenant, string sitecollectionName)
        {
            string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];

            string siteOwnerLogin = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["OnPremDomain"], ConfigurationManager.AppSettings["OnPremUserName"]);

            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }

            string     siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
            SiteEntity siteToCreate    = new SiteEntity()
            {
                Url            = siteToCreateUrl,
                Template       = "STS#0",
                Title          = "Test",
                Description    = "Test site collection",
                SiteOwnerLogin = siteOwnerLogin,
            };

            tenant.CreateSiteCollection(siteToCreate);
            return(siteToCreateUrl);
        }
Example #13
0
        public void CanProvisionHierarchy()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Template requires term store work, so this will not work in app-only");
            }

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\..\Resources",
                                  AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var hierarchy = provider.GetHierarchy("ProvisioningSchema-2019-03-FullSample-01.xml");

            var applyingInformation = new ProvisioningTemplateApplyingInformation();

            if (TestCommon.AppOnlyTesting())
            {
                bool templateSupportsAppOnly = true;

                if (applyingInformation.HandlersToProcess.Has(PnP.Framework.Provisioning.Model.Handlers.TermGroups) ||
                    applyingInformation.HandlersToProcess.Has(PnP.Framework.Provisioning.Model.Handlers.SearchSettings))
                {
                    if (hierarchy.Templates.Count > 0)
                    {
                        foreach (var template in hierarchy.Templates)
                        {
                            templateSupportsAppOnly = this.IsTemplateSupportedForAppOnly(template);
                            if (!templateSupportsAppOnly)
                            {
                                break;
                            }
                        }
                    }
                }

                if (!templateSupportsAppOnly)
                {
                    Assert.Inconclusive("Taxonomy and SearchSettings tests are not supported when testing using app-only context.");
                }
            }

            CanProvisionResult result = null;

            using (var pnpContext = new PnPProvisioningContext())
            {
                using (var tenantContext = TestCommon.CreateTenantClientContext())
                {
                    var tenant = new Tenant(tenantContext);
                    result = CanProvisionRulesManager.CanProvision(tenant, hierarchy, String.Empty, applyingInformation);
                }
            }

            Assert.IsNotNull(result);
            Assert.IsTrue(result.CanProvision);
            Assert.IsTrue(result.CanProvision);
        }
        public override void Initialize()
        {
            base.Initialize();

            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Test that require taxonomy creation are not supported in app-only.");
            }
        }
Example #15
0
        public void Initialize()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Taxonomy tests are not supported when testing using app-only");
                return;
            }

            _termSetGuid           = Guid.NewGuid();
            _termGroupGuid         = Guid.NewGuid();
            _additionalTermSetGuid = Guid.NewGuid();
        }
        internal static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName, bool useSts)
        {
            try
            {
                string devSiteUrl      = TestCommon.AppSetting("SPODevSiteUrl");
                string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);

                string siteOwnerLogin = TestCommon.AppSetting("SPOUserName");
                if (TestCommon.AppOnlyTesting())
                {
                    using (var clientContext = TestCommon.CreateClientContext())
                    {
                        List <UserEntity> admins = clientContext.Web.GetAdministrators();
                        siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                    }
                }

                if (useSts)
                {
                    SiteEntity siteToCreate = new SiteEntity()
                    {
                        Url                  = siteToCreateUrl,
                        Template             = "STS#0",
                        Title                = "Test",
                        Description          = "Test site collection",
                        SiteOwnerLogin       = siteOwnerLogin,
                        Lcid                 = 1033,
                        StorageMaximumLevel  = 100,
                        UserCodeMaximumLevel = 0
                    };

                    tenant.CreateSiteCollection(siteToCreate, false, true);
                }
                else
                {
                    var commResults = (tenant.Context.Clone(devSiteUrl) as ClientContext).CreateSiteAsync(new PnP.Framework.Sites.CommunicationSiteCollectionCreationInformation()
                    {
                        Url        = siteToCreateUrl,
                        SiteDesign = PnP.Framework.Sites.CommunicationSiteDesign.Blank,
                        Title      = "Test",
                        Owner      = siteOwnerLogin,
                        Lcid       = 1033
                    }).GetAwaiter().GetResult();
                }

                return(siteToCreateUrl);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToDetailedString(tenant.Context));
                throw;
            }
        }
Example #17
0
        public void UploadFileWebDavTest()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Tests involving webdav are not supported when testing using app-only");
            }

            var fileNameExpected = "TestFile1.png";
            var file             = folder.UploadFileWebDav(fileNameExpected, TestFilePath1, true);

            Assert.AreEqual(fileNameExpected, file.Name);
        }
 public void Initialize()
 {
     if (!TestCommon.AppOnlyTesting())
     {
         _termSetGuid   = Guid.NewGuid();
         _termGroupGuid = Guid.NewGuid();
     }
     else
     {
         Assert.Inconclusive("Taxonomy tests are not supported when testing using app-only");
     }
 }
Example #19
0
        private void CleanupTaxonomy()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                // Ensure that the group is empty before deleting it.
                // exceptions like the following happen:
                // Microsoft.SharePoint.Client.ServerException: Microsoft.SharePoint.Client.ServerException: A Group cannot be deleted unless it is empty..

                OfficeDevPnP.Core.Tests.Utilities.RetryHelper.Do(
                    () => this.InnerCleanupTaxonomy(),
                    TimeSpan.FromSeconds(30),
                    3);
            }
        }
 public void CleanUp()
 {
     if (!TestCommon.AppOnlyTesting())
     {
         using (var clientContext = TestCommon.CreateTenantClientContext())
         {
             var tenant = new Tenant(clientContext);
             tenant.DeleteSiteCollection($"{baseUrl}/sites/site{communicationSiteGuid}", false);
             // Commented this, first group cleanup needs to be implemented in this test case
             //tenant.DeleteSiteCollection($"{baseUrl}/sites/site{teamSiteGuid}", false);
             //TODO: Cleanup group
         }
     }
 }
        public void CanProvisionSite()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Template requires term store work, so this will not work in app-only");
            }

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                                  AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var hierarchy = provider.GetHierarchy("ProvisioningSchema-2019-03-FullSample-01.xml");

            var applyingInformation = new ProvisioningTemplateApplyingInformation();
            var template            = hierarchy.Templates[0];

            if (TestCommon.AppOnlyTesting())
            {
                if (applyingInformation.HandlersToProcess.Has(Core.Framework.Provisioning.Model.Handlers.TermGroups) ||
                    applyingInformation.HandlersToProcess.Has(Core.Framework.Provisioning.Model.Handlers.SearchSettings))
                {
                    bool templateSupportsAppOnly = this.IsTemplateSupportedForAppOnly(template);
                    if (!templateSupportsAppOnly)
                    {
                        Assert.Inconclusive("Taxonomy and SearchSettings tests are not supported when testing using app-only context.");
                    }
                }
            }

            CanProvisionResult result = null;

            using (var pnpContext = new PnPProvisioningContext())
            {
                using (var context = TestCommon.CreateClientContext())
                {
                    result = CanProvisionRulesManager.CanProvision(context.Web, hierarchy.Templates[0], applyingInformation);
                }
            }

            Assert.IsNotNull(result);
#if SP2013 || SP2016
            // Because the "apps" rule is verified here
            Assert.IsFalse(result.CanProvision);
#else
            Assert.IsTrue(result.CanProvision);
#endif
        }
Example #22
0
        public void Initialize()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Test that require modern site collection creation are not supported in app-only.");
            }

            using (var clientContext = TestCommon.CreateClientContext())
            {
                communicationSiteGuid = Guid.NewGuid().ToString("N");
                teamSiteGuid          = Guid.NewGuid().ToString("N");
                var baseUri = new Uri(clientContext.Url);
                baseUrl = $"{baseUri.Scheme}://{baseUri.Host}:{baseUri.Port}";
            }
        }
Example #23
0
        public void GetOneDriveSiteCollectionsTest()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Web service tests are not supported when testing using app-only");
            }

            using (var tenantContext = TestCommon.CreateTenantClientContext())
            {
                var tenant   = new Tenant(tenantContext);
                var siteCols = tenant.GetOneDriveSiteCollections();

                Assert.IsTrue(siteCols.Any());
            }
        }
Example #24
0
        public void Initialize()
        {
            _userLogin = TestCommon.AppSetting("SPOUserName");
            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    _userLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                }
            }

            using (ClientContext clientContext = TestCommon.CreateClientContext())
            {
                clientContext.Web.AddGroup(_testGroupName, "", true, true);
            }
        }
Example #25
0
        public void Cleanup()
        {
            // Let's do webhook testing for both app-only as credential flows
            using (var clientContext = TestCommon.CreateClientContext())
            {
                var list = clientContext.Web.Lists.GetById(webHookListId);
                list.DeleteObject();
                clientContext.ExecuteQueryRetry();
            }

            using (var clientContext = TestCommon.CreateClientContext())
            {
                if (!TestCommon.AppOnlyTesting())
                {
                    // Clean up Taxonomy
                    var taxSession = TaxonomySession.GetTaxonomySession(clientContext);
                    var termStore  = taxSession.GetDefaultSiteCollectionTermStore();
                    var termGroup  = termStore.GetGroup(_termGroupId);
                    var termSets   = termGroup.TermSets;
                    clientContext.Load(termSets);
                    clientContext.ExecuteQueryRetry();
                    foreach (var termSet in termSets)
                    {
                        termSet.DeleteObject();
                    }
                    termGroup.DeleteObject(); // Will delete underlying termset
                    clientContext.ExecuteQueryRetry();
                }

                // Clean up list
                var list = clientContext.Web.Lists.GetById(_listId);
                list.DeleteObject();
                clientContext.ExecuteQueryRetry();

                // Clean up fields
                var fields = clientContext.LoadQuery(clientContext.Web.Fields);
                clientContext.ExecuteQueryRetry();
                var testFields = fields.Where(f => f.InternalName.StartsWith("Test_", StringComparison.OrdinalIgnoreCase));
                foreach (var field in testFields)
                {
                    field.DeleteObject();
                }
                clientContext.ExecuteQueryRetry();
            }
        }
Example #26
0
        internal static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName, bool isNoScriptSite = false)
        {
            try
            {
                string devSiteUrl      = ConfigurationManager.AppSettings["SPODevSiteUrl"];
                string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);

                string siteOwnerLogin = ConfigurationManager.AppSettings["SPOUserName"];
                if (TestCommon.AppOnlyTesting())
                {
                    using (var clientContext = TestCommon.CreateClientContext())
                    {
                        List <UserEntity> admins = clientContext.Web.GetAdministrators();
                        siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                    }
                }

                SiteEntity siteToCreate = new SiteEntity()
                {
                    Url                  = siteToCreateUrl,
                    Template             = "STS#0",
                    Title                = "Test",
                    Description          = "Test site collection",
                    SiteOwnerLogin       = siteOwnerLogin,
                    Lcid                 = 1033,
                    StorageMaximumLevel  = 100,
                    UserCodeMaximumLevel = 0
                };

                tenant.CreateSiteCollection(siteToCreate, false, true);

                //if (isNoScriptSite)
                //{
                //    tenant.SetSiteProperties(siteToCreateUrl, noScriptSite: true);
                //}

                return(siteToCreateUrl);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToDetailedString(tenant.Context));
                throw;
            }
        }
Example #27
0
        public void GetUserProfileServiceClientTest()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("Web service tests are not supported when testing using app-only");
            }

            using (var tenantContext = TestCommon.CreateTenantClientContext())
            {
                var tenant        = new Tenant(tenantContext);
                var serviceClient = tenant.GetUserProfileServiceClient();
                tenantContext.Load(tenantContext.Web, w => w.CurrentUser);
                tenantContext.ExecuteQueryRetry();

                var profile = serviceClient.GetUserProfileByName(tenantContext.Web.CurrentUser.LoginName);

                Assert.IsNotNull(profile);
            }
        }
        public void Initialize()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                Console.WriteLine("TaxonomyExtensionsTests.Initialise");
                // Create some taxonomy groups and terms
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    _termGroupName = "Test_Group_" + DateTime.Now.ToFileTime();
                    _termSetName   = "Test_Termset_" + DateTime.Now.ToFileTime();
                    _termName      = "Test_Term_" + DateTime.Now.ToFileTime();
                    // Termgroup
                    var taxSession = TaxonomySession.GetTaxonomySession(clientContext);
                    var termStore  = taxSession.GetDefaultSiteCollectionTermStore();
                    var termGroup  = termStore.CreateGroup(_termGroupName, _termGroupId);
                    clientContext.Load(termGroup);
                    clientContext.ExecuteQueryRetry();

                    // Termset
                    var termSet = termGroup.CreateTermSet(_termSetName, _termSetId, 1033);
                    clientContext.Load(termSet);
                    clientContext.ExecuteQueryRetry();

                    // Term
                    termSet.CreateTerm(_termName, 1033, _termId);
                    clientContext.ExecuteQueryRetry();

                    // List
                    ListCreationInformation listCI = new ListCreationInformation();
                    listCI.TemplateType = (int)ListTemplateType.GenericList;
                    listCI.Title        = "Test_List_" + DateTime.Now.ToFileTime();
                    var list = clientContext.Web.Lists.Add(listCI);
                    clientContext.Load(list);
                    clientContext.ExecuteQueryRetry();
                    _listId = list.Id;
                }
            }
            else
            {
                Assert.Inconclusive("Taxonomy tests are not supported when testing using app-only");
            }
        }
Example #29
0
        public void Cleanup()
        {
            if (!TestCommon.AppOnlyTesting())
            {
                Console.WriteLine("TaxonomyExtensionsTests.Cleanup");


                // Clean up Taxonomy
                try
                {
                    this.CleanupTaxonomy();
                }
                catch (ServerException serverEx)
                {
                    if (!string.IsNullOrEmpty(serverEx.ServerErrorTypeName) &&
                        serverEx.ServerErrorTypeName.Contains("TermStoreErrorCodeEx"))
                    {
                        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
                        this.CleanupTaxonomy();
                    }
                }

                using (var clientContext = TestCommon.CreateClientContext())
                {
                    // Clean up fields
                    var fields = clientContext.LoadQuery(clientContext.Web.Fields);
                    clientContext.ExecuteQueryRetry();
                    var testFields = fields.Where(f => f.InternalName.StartsWith("Test_", StringComparison.OrdinalIgnoreCase));
                    foreach (var field in testFields)
                    {
                        field.DeleteObject();
                    }
                    clientContext.ExecuteQueryRetry();

                    // Clean up list
                    var list = clientContext.Web.Lists.GetById(_listId);
                    list.DeleteObject();
                    clientContext.ExecuteQueryRetry();
                }
            }
        }
Example #30
0
        private static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName, bool isNoScriptSite = false)
        {
            string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];

            string siteOwnerLogin = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["OnPremDomain"], ConfigurationManager.AppSettings["OnPremUserName"]);

            if (TestCommon.AppOnlyTesting())
            {
                using (var clientContext = TestCommon.CreateClientContext())
                {
                    List <UserEntity> admins = clientContext.Web.GetAdministrators();
                    siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1];
                }
            }

            string     siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
            SiteEntity siteToCreate    = new SiteEntity()
            {
                Url            = siteToCreateUrl,
                Template       = "STS#0",
                Title          = "Test",
                Description    = "Test site collection",
                SiteOwnerLogin = siteOwnerLogin,
                Lcid           = 1033,
            };

            tenant.CreateSiteCollection(siteToCreate);

            // Create the default groups
            using (ClientContext cc = new ClientContext(siteToCreateUrl))
            {
                var owners   = cc.Web.AddGroup("Test Owners", "", true, false);
                var members  = cc.Web.AddGroup("Test Members", "", true, false);
                var visitors = cc.Web.AddGroup("Test Visitors", "", true, true);

                cc.Web.AssociateDefaultGroups(owners, members, visitors);
            }

            return(siteToCreateUrl);
        }