private void RemoveTestEnvVarsAssociatedToModule(AppServicesHeartbeatTelemetryModule appServicesHbeatModule)
 {
     foreach (var kvp in appServicesHbeatModule.WebHeartbeatPropertyNameEnvVarMap)
     {
         Environment.SetEnvironmentVariable(kvp.Value, string.Empty);
     }
 }
        private AppServicesHeartbeatTelemetryModule GetAppServiceHeartbeatModuleWithUniqueTestEnvVars(HeartbeatProviderMock heartbeatProvider)
        {
            var    appServicesHbeatModule = new AppServicesHeartbeatTelemetryModule(heartbeatProvider);
            string testSuffix             = Guid.NewGuid().ToString();

            for (int i = 0; i < appServicesHbeatModule.WebHeartbeatPropertyNameEnvVarMap.Length; ++i)
            {
                var kvp = appServicesHbeatModule.WebHeartbeatPropertyNameEnvVarMap[i];
                appServicesHbeatModule.WebHeartbeatPropertyNameEnvVarMap[i] = new KeyValuePair <string, string>(kvp.Key, string.Concat(kvp.Value, "_", testSuffix));
            }

            return(appServicesHbeatModule);
        }
        public void NoHeartbeatManagerAvailableDoesntThrow()
        {
            var appSrvHbeatModule = new AppServicesHeartbeatTelemetryModule();
            var envVars           = this.GetEnvVarsAssociatedToModule(appSrvHbeatModule);

            try
            {
                appSrvHbeatModule.Initialize(null);
            }
            catch (Exception any)
            {
                Assert.False(any == null);
            }
        }
        /// <summary>
        /// Return a dictionary containing the expected environment variables for the AppServicesHeartbeat module. If
        /// the environment does not contain a value for them, set the environment to have them.
        /// </summary>
        /// <returns>Dictionary with expected environment variable names as the key, current environment variable content as the value.</returns>
        private Dictionary <string, string> GetEnvVarsAssociatedToModule(AppServicesHeartbeatTelemetryModule testAppServicesHeartbeatModule)
        {
            Dictionary <string, string> uniqueTestEnvironmentVariables = new Dictionary <string, string>();

            foreach (var kvp in testAppServicesHeartbeatModule.WebHeartbeatPropertyNameEnvVarMap)
            {
                uniqueTestEnvironmentVariables.Add(kvp.Value, Environment.GetEnvironmentVariable(kvp.Value));
                if (string.IsNullOrEmpty(uniqueTestEnvironmentVariables[kvp.Value]))
                {
                    Environment.SetEnvironmentVariable(kvp.Value, kvp.Key);
                    uniqueTestEnvironmentVariables[kvp.Value] = kvp.Key;
                }
            }

            return(uniqueTestEnvironmentVariables);
        }
 public void BeforeEachTestMethod()
 {
     this.testHeartbeatPropertyManager = new HeartbeatProviderMock();
     this.testAppServiceHbeatModule    = this.GetAppServiceHeartbeatModuleWithUniqueTestEnvVars(this.testHeartbeatPropertyManager);
     this.testEnvironmentVariables     = this.GetEnvVarsAssociatedToModule(this.testAppServiceHbeatModule);
 }