public void GetDefaultHostId_AzureHost_ReturnsExpectedResult(string siteName, string expected)
        {
            var options = new ScriptApplicationHostOptions
            {
                ScriptPath = @"c:\testscripts"
            };

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId, "123123");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteName, siteName);

            string hostId = ScriptHostIdProvider.GetDefaultHostId(environment, options);

            Assert.Equal(expected, hostId);
        }
        public void GetDefaultHostId_AzureHost_ReturnsExpectedResult(string siteName, string azureWebsiteInstanceId, string expected, bool expectedTruncation)
        {
            var options = new ScriptApplicationHostOptions
            {
                ScriptPath = @"c:\testscripts"
            };

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId, azureWebsiteInstanceId);
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteName, siteName);
            environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, "testContainer");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, "testsite.azurewebsites.net");
            var result = ScriptHostIdProvider.GetDefaultHostId(environment, options);

            Assert.Equal(expected, result.HostId);
            Assert.Equal(expectedTruncation, result.IsTruncated);
            Assert.False(result.IsLocal);
        }
        public void GetDefaultHostId_SelfHost_ReturnsExpectedResult()
        {
            var options = new ScriptApplicationHostOptions
            {
                IsSelfHost = true,
                ScriptPath = @"c:\testing\FUNCTIONS-TEST\test$#"
            };

            var environmentMock = new Mock <IEnvironment>();

            string hostId = ScriptHostIdProvider.GetDefaultHostId(environmentMock.Object, options);

            // This suffix is a stable hash code derived from the "RootScriptPath" string passed in the configuration.
            // We're using the literal here as we want this test to fail if this compuation ever returns something different.
            string suffix = "473716271";

            string sanitizedMachineName = Environment.MachineName
                                          .Where(char.IsLetterOrDigit)
                                          .Aggregate(new StringBuilder(), (b, c) => b.Append(c)).ToString().ToLowerInvariant();

            Assert.Equal($"{sanitizedMachineName}-{suffix}", hostId);
        }