diff --git a/src/IntegrationTests.HostV4/IntegrationTests.HostV4.csproj b/src/IntegrationTests.HostV4/IntegrationTests.HostV4.csproj index bbd91f9c..144ef1ad 100644 --- a/src/IntegrationTests.HostV4/IntegrationTests.HostV4.csproj +++ b/src/IntegrationTests.HostV4/IntegrationTests.HostV4.csproj @@ -14,7 +14,7 @@ - + @@ -25,6 +25,13 @@ + + + + + + + diff --git a/src/IntegrationTests.HostV4/When_starting_the_function_host.cs b/src/IntegrationTests.HostV4/When_starting_the_function_host.cs index 5a7d4a66..6af4e977 100644 --- a/src/IntegrationTests.HostV4/When_starting_the_function_host.cs +++ b/src/IntegrationTests.HostV4/When_starting_the_function_host.cs @@ -3,10 +3,12 @@ using System; using System.Diagnostics; using System.IO; + using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Azure.Messaging.ServiceBus.Administration; + using Microsoft.Extensions.Configuration; using NUnit.Framework; [TestFixture] @@ -15,10 +17,50 @@ public class When_starting_the_function_host [Test] public async Task Should_not_blow_up() { - var pathToFuncExe = Environment.GetEnvironmentVariable("PathToFuncExe"); - Assert.IsNotNull(pathToFuncExe, "Environment variable 'PathToFuncExe' should be defined to run tests. When running locally this is usually 'C:\\Users\\MyUser\\AppData\\Local\\AzureFunctionsTools\\Releases\\4.30.0\\cli_x64\\func.exe'"); + var configBuilder = new ConfigurationBuilder(); + configBuilder.SetBasePath(Directory.GetCurrentDirectory()); + configBuilder.AddEnvironmentVariables(); + configBuilder.AddJsonFile("local.settings.json", true); - var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsServiceBus"); + var config = configBuilder.Build(); + + var pathToFuncExe = config.GetValue("PathToFuncExe"); + + if (pathToFuncExe == null) + { + Console.WriteLine("Environment variable 'PathToFuncExe' not defined. Going to try to find the latest version."); + + var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var sdkPath = Path.Combine(userProfile, "AppData", "Local", "AzureFunctionsTools", "Releases"); + if (Directory.Exists(sdkPath)) + { + var mostRecent = Directory.GetDirectories(sdkPath) + .Select(path => + { + var name = Path.GetFileName(path); + Version.TryParse(name, out var version); + return new { Name = name, Version = version }; + }) + .Where(x => x.Version is not null) + .OrderByDescending(x => x.Version) + .FirstOrDefault() + ?.Name; + + if (mostRecent is not null) + { + var exePath = Path.Combine(sdkPath, mostRecent, "cli_x64", "func.exe"); + if (File.Exists(exePath)) + { + Console.WriteLine("Found " + exePath); + pathToFuncExe = exePath; + } + } + } + } + + Assert.IsNotNull(pathToFuncExe, "Environment variable 'PathToFuncExe' should be defined to run tests. When running locally this is usually 'C:\\Users\\\\AppData\\Local\\AzureFunctionsTools\\Releases\\\\cli_x64\\func.exe'"); + + var connectionString = config.GetValue("AzureWebJobsServiceBus") ?? config.GetValue("Values:AzureWebJobsServiceBus"); Assert.IsNotNull(connectionString, "Environment variable 'AzureWebJobsServiceBus' should be defined to run tests."); var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(60)); diff --git a/src/ServiceBus.Tests/ServiceBus.Tests.csproj b/src/ServiceBus.Tests/ServiceBus.Tests.csproj index ad234cdd..dd063a29 100644 --- a/src/ServiceBus.Tests/ServiceBus.Tests.csproj +++ b/src/ServiceBus.Tests/ServiceBus.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Testing.Handlers/Testing.Handlers.csproj b/src/Testing.Handlers/Testing.Handlers.csproj index 5527b962..e392ed6b 100644 --- a/src/Testing.Handlers/Testing.Handlers.csproj +++ b/src/Testing.Handlers/Testing.Handlers.csproj @@ -1,11 +1,11 @@ - + net6.0;net7.0 - +