Exemplo n.º 1
0
        public void ValidExtenstionConfig_ForAppServiceEnvironment_ConfiguresDownloadPath()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, CreateTestAppServiceEnvironment());
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Record.Exception(() => setup.Configure(options));

            string expectedDownloadPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                                    ? @"D:\home\data\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle"
                                    : "/home/data/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle";

            Assert.Equal(expectedDownloadPath, options.DownloadPath);
            Assert.Null(ex);
        }
Exemplo n.º 2
0
        public void ValidExtenstionConfig_ForAppServiceEnvironment_ConfiguresProbingPaths()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, CreateTestAppServiceEnvironment());
            ExtensionBundleOptions             options = new ExtensionBundleOptions();

            setup.Configure(options);

            List <string> expectedProbingPaths = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                                    ? new List <string>
            {
                @"C:\Program Files (x86)\FuncExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle"
            }
                                    : new List <string>
            {
                "/FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle",
                "/home/site/wwwroot/.azureFunctions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle"
            };

            Assert.Equal(expectedProbingPaths, options.ProbingPaths);
        }
Exemplo n.º 3
0
        internal static ExtensionBundleOptions GetExtensionBundleOptions(IConfiguration configuration)
        {
            var options      = new ExtensionBundleOptions();
            var optionsSetup = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);

            configuration.Bind(options);
            optionsSetup.Configure(options);
            return(options);
        }
Exemplo n.º 4
0
        public static ExtensionBundleOptions GetExtensionBundleOptions(ScriptApplicationHostOptions hostOptions = null)
        {
            hostOptions = hostOptions ?? SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory);
            IConfigurationRoot configuration = Utilities.BuildHostJsonConfigutation(hostOptions);
            var configurationHelper          = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);
            var options = new ExtensionBundleOptions();

            configurationHelper.Configure(options);
            return(options);
        }
Exemplo n.º 5
0
        public void MissingOrValidExtenstionConfig_DoesNotThrowException(string hostJsonContent)
        {
            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var configuration = BuildHostJsonConfiguration();

            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Record.Exception(() => setup.Configure(options));

            Assert.Null(ex);
        }
Exemplo n.º 6
0
        public void ExtensionBundleConfigure_InvalidVersion_ThrowsException(string hostJsonContent)
        {
            File.WriteAllText(_hostJsonFile, hostJsonContent);
            var configuration = BuildHostJsonConfiguration();

            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();
            var ex = Assert.Throws <ArgumentException>(() => setup.Configure(options));

            Assert.StartsWith($"The value of version property in extensionBundle section of {ScriptConstants.HostMetadataFileName} file is invalid or missing.", ex.Message);
        }
        public static ExtensionBundleOptions GetExtensionBundleOptions(ScriptApplicationHostOptions hostOptions = null)
        {
            hostOptions = hostOptions ?? SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory);
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.Add(new HostJsonFileConfigurationSource(hostOptions, SystemEnvironment.Instance, loggerFactory: NullLoggerFactory.Instance));
            var configuration = builder.Build();

            var configurationHelper = new ExtensionBundleConfigurationHelper(configuration, SystemEnvironment.Instance);
            var options             = new ExtensionBundleOptions();

            configurationHelper.Configure(options);
            return(options);
        }
Exemplo n.º 8
0
        public void ValidExtenstionConfig_NonAppServiceEnvironment_DoesNotConfigureDownloadPathAndProbingPath()
        {
            string hostJsonContent = @"{
                    'version': '2.0',
                    'extensionBundle': {
                        'id': 'Microsoft.Azure.Functions.ExtensionBundle',
                        'version': '[2.*, 3.0.0)'
                        }
                    }";

            File.WriteAllText(_hostJsonFile, hostJsonContent);

            var configuration = BuildHostJsonConfiguration();
            ExtensionBundleConfigurationHelper setup   = new ExtensionBundleConfigurationHelper(configuration, _environment);
            ExtensionBundleOptions             options = new ExtensionBundleOptions();

            setup.Configure(options);

            Assert.Equal(options.Id, "Microsoft.Azure.Functions.ExtensionBundle");
            Assert.Equal(options.Version.OriginalString, "[2.*, 3.0.0)");
            Assert.True(string.IsNullOrEmpty(options.DownloadPath));
            Assert.Equal(options.ProbingPaths.Count, 0);
        }