public static void Initialize()
        {
            AzureSession.Instance.DataStore         = new MemoryDataStore();
            AzureRmProfileProvider.Instance.Profile = new AzureRmProfile();

            PowerShellTokenCacheProvider tokenCacheProvider = new InMemoryTokenCacheProvider();

            AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenCacheProvider);
            AzureSession.Instance.RegisterComponent(nameof(PowerShellTokenCache), () => tokenCacheProvider.GetTokenCache());
            IAuthenticatorBuilder builder = new DefaultAuthenticatorBuilder();

            AzureSession.Instance.RegisterComponent(AuthenticatorBuilder.AuthenticatorBuilderKey, () => builder);
            AzureSession.Instance.RegisterComponent(nameof(AzureCredentialFactory), () => new AzureCredentialFactory());
            AzureSession.Instance.RegisterComponent(nameof(MsalAccessTokenAcquirerFactory), () => new MsalAccessTokenAcquirerFactory());
        }
Example #2
0
        void ResetState()
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            ResourceManagerProfileProvider.InitializeResourceManagerProfile(true);
            // prevent token acquisition
            AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>().ShouldRefreshContextsFromCache = false;
            AzureSession.Instance.DataStore             = dataStore;
            AzureSession.Instance.ARMContextSaveMode    = ContextSaveMode.Process;
            AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
            Environment.SetEnvironmentVariable("Azure_PS_Data_Collection", "false");
            PowerShellTokenCacheProvider tokenProvider = new InMemoryTokenCacheProvider();

            AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenProvider);
            AzureSession.Instance.RegisterComponent(nameof(PowerShellTokenCache), () => tokenProvider.GetTokenCache());
        }