AzureFunctions.TestHelpers icon indicating copy to clipboard operation
AzureFunctions.TestHelpers copied to clipboard

Helper functions not registered

Open nakah opened this issue 2 years ago • 2 comments

Hi @riezebosch ,

I'm trying to write some integration tests using your helpers however I'm facing issues with durable functions. This is how I creating my host:

_host = new HostBuilder()
             .ConfigureWebJobs(builder => builder
               .AddDurableTask()
               .AddAzureStorageCoreServices()
               .AddAzureStorageQueues()
               .AddAzureStorageBlobs()
               .UseWebJobsStartup(
                   typeof(FunctionsTestStartup),
                   new WebJobsBuilderContext()
                   {
                       ApplicationRootPath = Environment.CurrentDirectory,
                       EnvironmentName = "Test",
                       Configuration = inMemoryConfig
                   },
                   NullLoggerFactory.Instance))
             .Build();

It's a reusable host in a XUnit fixture.

In my test class (using this fixture), I have the following code:

public Task InitializeAsync() =>
             _host.Jobs
                .Terminate()
                .Purge();

It always fails on Terminate() extension method with the following error: System.InvalidOperationException : 'TerminateFunction' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?

When stepping into it, I found out that AzureFunctions.TestHelpers functions are not listed in the context : image

Only my project's functions are listed. I think that's why it's failing. Is there a way to load/include these functions ?

nakah avatar Nov 23 '23 17:11 nakah

Normally it is enough to use something from the library for it to be loaded/discovered, and by invoking the Terminate() function should qualify. Otherwise you could explicitly load it by adding something like _ = typeof(TerminateFunction).FullName prior to setting op the job host.

riezebosch avatar Nov 27 '23 19:11 riezebosch

Didn't work for me. I've managed to get them in the collection by loading the assembly before configuring the WebJobsHost but faced a lot of issues as described here : #10 So for the moment, I copied all your classes (except DummyHttpContext) in my test project and it works like a charm 😍

Thank you!

nakah avatar Nov 28 '23 08:11 nakah

Please, checkout the update. I think it is resolved now by explicitly targetting net6.0 besides netstandard2.1.

riezebosch avatar Mar 01 '24 15:03 riezebosch

I've just tested now and it's still doesn't work out of the box. However, I've been able to make it work by using your workaround : _ = typeof(TerminateFunction).FullName I managed to remove all classes that I copied previously 👍

nakah avatar Apr 03 '24 13:04 nakah