azure service bus client in timer triggered azure function unit test

259 Views Asked by At

I am trying to create Xunit test for azure timer triggered functions and I have to pass the service bus client queue in Run method and I cannot mock a service bus queue and not sure how to pass as a parameter

Below is my azure function

 [FunctionName("TimerJob")]
    public static async Task Run([TimerTrigger("%TimerJobExpression%")] TimerInfo myTimer,
        [ServiceBus("%Queue1%", Connection = "ServiceBusConnection")] IAsyncCollector<string> Queue1,
        [ServiceBus("%Queue2%", Connection = "ServiceBusConnection")] IAsyncCollector<string> Queue2,
        ILogger log)
    {
          //logic
    }

Below is the test method I am trying to create

 [Fact]
public async Task Run_Queue()
    {
      
        var param1 = default(TimerInfo);
        var result = await ProducerClientTimerJob.Run(param1, null, null, logger);

       
    }
1

There are 1 best solutions below

0
On

As sellotape mentioned in the comment, you just need to give a IAsyncCollector object.

That is an output binding and the information have been stored in the attribute so you don't need to give anything input information of the service bus. just give a IAsyncCollector object is ok.