Skip to content

Commit f7f328c

Browse files
CopilotYunchuWang
andcommitted
Add test for auto-detection via trigger attributes
- Added AutoDetect_WithTriggerAttributes_GeneratesFunctionsCode test - Validates that presence of [ActivityTrigger] causes auto-detection as Functions project - Tests the allFunctions.IsDefaultOrEmpty check in DetermineIsDurableFunctions - All 53 tests passing (52 original + 1 new) Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
1 parent c22adcc commit f7f328c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/Generators.Tests/ProjectTypeConfigurationTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,42 @@ public GeneratedActivityContext(TaskName name, string instanceId)
473473
isDurableFunctions: true,
474474
projectType: null);
475475
}
476+
477+
[Fact]
478+
public Task AutoDetect_WithTriggerAttributes_GeneratesFunctionsCode()
479+
{
480+
// Test that presence of Azure Functions trigger attributes auto-detects as Functions project
481+
// This validates the allFunctions.IsDefaultOrEmpty check in DetermineIsDurableFunctions
482+
string code = @"
483+
using System.Threading.Tasks;
484+
using Microsoft.Azure.Functions.Worker;
485+
using Microsoft.DurableTask;
486+
487+
public class MyFunctions
488+
{
489+
[Function(nameof(MyActivity))]
490+
public int MyActivity([ActivityTrigger] int input) => input;
491+
}";
492+
493+
string expectedOutput = TestHelpers.WrapAndFormat(
494+
GeneratedClassName,
495+
methodList: @"
496+
/// <summary>
497+
/// Calls the <see cref=""MyFunctions.MyActivity""/> activity.
498+
/// </summary>
499+
/// <inheritdoc cref=""TaskOrchestrationContext.CallActivityAsync(TaskName, object?, TaskOptions?)""/>
500+
public static Task<int> CallMyActivityAsync(this TaskOrchestrationContext ctx, int input, TaskOptions? options = null)
501+
{
502+
return ctx.CallActivityAsync<int>(""MyActivity"", input, options);
503+
}",
504+
isDurableFunctions: true);
505+
506+
// No explicit projectType - should auto-detect based on [ActivityTrigger] attribute
507+
return TestHelpers.RunTestAsync<DurableTaskSourceGenerator>(
508+
GeneratedFileName,
509+
code,
510+
expectedOutput,
511+
isDurableFunctions: true,
512+
projectType: null);
513+
}
476514
}

0 commit comments

Comments
 (0)