public void ReadFunctionsMetadataSucceeds() { string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample"); // Setup var fileSystem = CreateFileSystem(_hostOptions.ScriptPath); var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var factory = new TestOptionsFactory <ScriptApplicationHostOptions>(_hostOptions); var tokenSource = new TestChangeTokenSource(); var changeTokens = new[] { tokenSource }; var optionsMonitor = new OptionsMonitor <ScriptApplicationHostOptions>(factory, changeTokens, factory); var secretManagerProviderMock = new Mock <ISecretManagerProvider>(MockBehavior.Strict); var secretManagerMock = new Mock <ISecretManager>(MockBehavior.Strict); secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object); var hostSecretsInfo = new HostSecretsInfo(); secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo); Dictionary <string, string> functionSecrets = new Dictionary <string, string>(); secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("httptrigger", false)).ReturnsAsync(functionSecrets); var configurationMock = new Mock <IConfiguration>(MockBehavior.Strict); var hostIdProviderMock = new Mock <IHostIdProvider>(MockBehavior.Strict); var mockWebHostEnvironment = new Mock <IScriptWebHostEnvironment>(MockBehavior.Strict); mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false); var mockEnvironment = new Mock <IEnvironment>(MockBehavior.Strict); mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady)).Returns("1"); mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.CoreToolsEnvironment)).Returns((string)null); var functionsSyncManager = new FunctionsSyncManager(configurationMock.Object, hostIdProviderMock.Object, optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, mockWebHostEnvironment.Object, mockEnvironment.Object); var webManager = new WebFunctionsManager(optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, functionsSyncManager); FileUtility.Instance = fileSystem; IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata(); var jsFunctions = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList(); var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList(); Assert.Equal(2, jsFunctions.Count()); Assert.Equal(1, unknownFunctions.Count()); }
public static void ReadFunctionsMetadataSucceeds() { string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample"); // Setup var settings = CreateWebSettings(); var fileSystem = CreateFileSystem(settings.ScriptPath); var loggerFactory = MockNullLogerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var webManager = new WebFunctionsManager(new OptionsWrapper <ScriptApplicationHostOptions>(settings), new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient); FileUtility.Instance = fileSystem; IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata(); var jsFunctions = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList(); var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList(); Assert.Equal(2, jsFunctions.Count()); Assert.Equal(1, unknownFunctions.Count()); }