public static UnitTestClientContext CreateTestClientContext( bool runInIntegrationMode = false, [System.Runtime.CompilerServices.CallerFilePath] string mockFolderPath = null, [System.Runtime.CompilerServices.CallerMemberName] string mockFileName = null) { RegisterPnPHttpClientMock(runInIntegrationMode, mockFolderPath, mockFileName); string mockFilePath = mockFolderPath.Replace(".cs", $"\\{mockFileName}.json"); string sdkFilePath = mockFolderPath.Replace(".cs", $"\\{mockFileName}-sdk.json"); CurrentTestInIntegration = runInIntegrationMode || RunInIntegrationAll; PnPCoreSdk.OnDIContainerBuilding += delegate(object sender, IServiceCollection serviceCollection) { PnPCoreSdk_OnDIContainerBuilding(sender, serviceCollection, sdkFilePath, CurrentTestInIntegration); }; if (System.IO.File.Exists(mockFilePath) || CurrentTestInIntegration) { UnitTestClientContext context; if (CurrentTestInIntegration) { context = UnitTestClientContext.GetUnitTestContext(CreateClientContext(DevSiteUrl), CurrentTestInIntegration, mockFilePath); } else { PnPCoreSdk.AuthenticationProviderFactory = new MockLegacyAuthenticationProviderFactory(); context = new UnitTestClientContext(DevSiteUrl, CurrentTestInIntegration, mockFilePath); } return(context); } throw new Exception("Mock file doesn't exist in: " + mockFilePath); }
public static UnitTestClientContext CreateTestClientContext( bool runInIntegrationMode = false, [System.Runtime.CompilerServices.CallerFilePath] string mockFolderPath = null, [System.Runtime.CompilerServices.CallerMemberName] string mockFileName = null) { string mockFilePath = mockFolderPath.Replace(".cs", $"\\{mockFileName}.json"); if (System.IO.File.Exists(mockFilePath)) { UnitTestClientContext context; if (runInIntegrationMode) { context = UnitTestClientContext.GetUnitTestContext(CreateClientContext(DevSiteUrl), runInIntegrationMode, mockFilePath); } else { context = new UnitTestClientContext(DevSiteUrl, runInIntegrationMode, mockFilePath); } return(context); } throw new Exception("Mock file doesn't exist in: " + mockFilePath); }