private string ConfigurePnPContextFactory(string configurationName, int id, string testName, string sourceFilePath, IPnPTestContextFactory factory) { sourceFilePath = Path.GetFullPath(sourceFilePath); var testPnPContextFactory = factory as TestPnPContextFactory; testPnPContextFactory.Mocking = Mocking; testPnPContextFactory.Id = id; testPnPContextFactory.TestName = testName; testPnPContextFactory.SourceFilePath = UseApplicationPermissions ? $"{sourceFilePath}{Constants.ApplicationPermissionsSuffix}" : sourceFilePath; testPnPContextFactory.GenerateTestMockingDebugFiles = GenerateMockingDebugFiles; testPnPContextFactory.TestUris = TestUris; testPnPContextFactory.UseApplicationPermissions = UseApplicationPermissions; // rewrite configuration for special cases configurationName = RewriteConfigurationNameForOptionalOfflineTestConfigurations(configurationName); return(configurationName); }
public IPnPTestContextFactory BuildContextFactory() { try { // If a test case is already initializing the factory then let's wait semaphoreSlimFactory.Wait(); if (pnpContextFactoryCache != null) { return(pnpContextFactoryCache); } var configuration = GetConfigurationSettings(); string targetSiteUrl = configuration.GetValue <string>("PnPCore:Sites:TestSite:SiteUrl"); string targetSubSiteUrl = configuration.GetValue <string>("PnPCore:Sites:TestSubSite:SiteUrl"); string noGroupSiteUrl = configuration.GetValue <string>("PnPCore:Sites:NoGroupTestSite:SiteUrl"); string classicSTS0SiteUrl = configuration.GetValue <string>("PnPCore:Sites:ClassicSTS0TestSite:SiteUrl"); string tenantAdminCenterSiteUrl = configuration.GetValue <string>("PnPCore:Sites:TenantAdminCenterSite:SiteUrl"); string syntexContentCenterSiteUrl = configuration.GetValue <string>("PnPCore:Sites:SyntexContentCenterTestSite:SiteUrl"); string vivaTopicCenterSiteUrl = configuration.GetValue <string>("PnPCore:Sites:VivaTopicCenterTestSite:SiteUrl"); if (RunningInGitHubWorkflow()) { targetSiteUrl = "https://bertonline.sharepoint.com/sites/prov-1"; targetSubSiteUrl = "https://bertonline.sharepoint.com/sites/prov-1/testsub1"; noGroupSiteUrl = "https://bertonline.sharepoint.com/sites/modern"; classicSTS0SiteUrl = "https://bertonline.sharepoint.com/sites/sts0"; tenantAdminCenterSiteUrl = "https://bertonline-admin.sharepoint.com"; syntexContentCenterSiteUrl = "https://bertonline.sharepoint.com/sites/syntextcc"; } var serviceProvider = new ServiceCollection() // Configuration .AddScoped <IConfiguration>(_ => configuration) // Logging service, get config from appsettings + add debug output handler .AddLogging(configure => { configure.AddConfiguration(configuration.GetSection("Logging")); configure.AddDebug(); }) // Add the PnP Core SDK library services for test .AddTestPnPContextFactory() // Add the PnP Core SDK library services configuration from the appsettings.json file .Configure <PnPCoreOptions>(configuration.GetSection("PnPCore")) // Add the PnP Core SDK Authentication Providers .AddPnPCoreAuthentication() .Configure <PnPCoreAuthenticationOptions>(configuration.GetSection("PnPCore")) .BuildServiceProvider(); TestUris = new Dictionary <string, Uri> { { TestSite, new Uri(targetSiteUrl) }, { TestSubSite, new Uri(targetSubSiteUrl) }, { NoGroupTestSite, new Uri(noGroupSiteUrl) } }; if (!string.IsNullOrEmpty(classicSTS0SiteUrl)) { TestUris.Add("ClassicSTS0TestSite", new Uri(classicSTS0SiteUrl)); } if (!string.IsNullOrEmpty(tenantAdminCenterSiteUrl)) { TestUris.Add("TenantAdminCenterSite", new Uri(tenantAdminCenterSiteUrl)); } if (!string.IsNullOrEmpty(syntexContentCenterSiteUrl)) { TestUris.Add("SyntexContentCenterTestSite", new Uri(syntexContentCenterSiteUrl)); } if (!string.IsNullOrEmpty(vivaTopicCenterSiteUrl)) { TestUris.Add("VivaTopicCenterTestSite", new Uri(vivaTopicCenterSiteUrl)); } var pnpContextFactory = serviceProvider.GetRequiredService <IPnPTestContextFactory>(); if (pnpContextFactoryCache == null) { pnpContextFactoryCache = pnpContextFactory; } return(pnpContextFactory); } finally { semaphoreSlimFactory.Release(); } }