The documentation for Durable Function Testing only talks about the in-proc model - https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-unit-testing
I have a timer-triggered orchestrator as below -
public class Orchestrator
{
private IMapper mapper;
private IRepository repository;
public Orchestrator(IMapper mapper, IRepository repository)
{
this.mapper = mapper;
this.repository = repository;
}
[Function(nameof(Orchestrator))]
public async Task RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(nameof(ConnectorOrchestrator));
IEnumerable<Result> results;
try
{
results = await repository.GetAllResultsAsync();
}
catch (Exception ex)
{
logger.LogError(ex, $"Error getting results.");
throw;
}
foreach (var result in results)
{
try
{
_ = context.CallActivityAsync<string>(nameof(Activity), result);
}
catch (Exception ex)
{
logger.LogError(ex, $"Error calling activity.");
throw;
}
}
}
[Function(nameof(Activity))]
public void ProcessAlerts([ActivityTrigger] Result result, FunctionContext executionContext)
{
logger.LogInformation($"Activity started.");
logger.LogInformation($"Activity completed");
}
[Function("Orchestrator_ScheduledStart")]
public async Task ScheduledStart(
[TimerTrigger("* */15 * * * *")] TimerInfo timerInfo,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("Orchestrator_ScheduledStart");
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(ConnectorOrchestrator));
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
}
}
In the below test, I get an error that DurableTaskClient cannot be mocked -
public OrchestratorTests()
{
mapper = new Mock<IMapper>();
repository = new Mock<IRepository>();
durableClient = new Mock<DurableTaskClient>();
connectorOrchestrator = new ConnectorOrchestrator(mapper.Object, repository.Object);
}
[Fact]
public async Task ScheduledStart_ShouldTriggerOrchestrator()
{
TimerInfo timerInfo = new TimerInfo();
Mock<FunctionContext> functionContext = new Mock<FunctionContext>();
await connectorOrchestrator.ScheduledStart(timerInfo, durableClient.Object, functionContext.Object);
durableClient.Verify(client => client.ScheduleNewOrchestrationInstanceAsync(nameof(Orchestrator), null, null, default), Times.Once);
}
Is there any way to test isolated durable orchestrators today?