Example #1
0
        protected EndToEndTestFixture(string rootPath, string testId, string extensionName = null, string extensionVersion = null)
        {
            FixtureId = testId;
            string connectionString            = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();
            TableClient = storageAccount.CreateCloudTableClient();

            CreateTestStorageEntities().Wait();

            _copiedRootPath = Path.Combine(Path.GetTempPath(), "FunctionsE2E", DateTime.UtcNow.ToString("yyMMdd-HHmmss"));
            FileUtility.CopyDirectory(rootPath, _copiedRootPath);

            // Allow derived classes to limit functions. We'll update host.json in the copied location
            // so it only affects this fixture's instance.
            IEnumerable <string> functions = GetActiveFunctions();
            string  hostJsonPath           = Path.Combine(_copiedRootPath, "host.json");
            JObject hostJson = JObject.Parse(File.ReadAllText(hostJsonPath));

            if (functions != null && functions.Any())
            {
                hostJson["functions"] = JArray.FromObject(functions);
            }
            File.WriteAllText(hostJsonPath, hostJson.ToString());

            Host = new TestFunctionHost(_copiedRootPath);

            // We can currently only support a single extension.
            if (extensionName != null && extensionVersion != null)
            {
                Host.SetNugetPackageSources("http://www.myget.org/F/azure-appservice/api/v2", "https://api.nuget.org/v3/index.json");
                Host.InstallBindingExtension(extensionName, extensionVersion).Wait(TimeSpan.FromSeconds(30));
            }

            Host.StartAsync().Wait(TimeSpan.FromSeconds(30));
        }