public void TryParseOrchestration() { // Arrange var model = Calculator.Semantic; var method = Calculator.MultiplyMethod; // Act var result = DurableFunction.TryParse(model, method, out DurableFunction function); // Assert Assert.True(result); Assert.Equal("WebJobs.Extensions.DurableTask.CodeGen.Example.Calculator.Multiply", function.FullTypeName); Assert.Equal(2, function.RequiredNamespaces.Count); var requiredNamespaceList = function.RequiredNamespaces.ToList(); Assert.Equal("System.Threading.Tasks", requiredNamespaceList[0]); Assert.Equal("Microsoft.Azure.WebJobs.Extensions.DurableTask", requiredNamespaceList[1]); Assert.Equal("Multiply", function.Name); Assert.Equal(DurableFunctionKind.Orchestration, function.Kind); Assert.Equal(2, function.Parameters.Count); Assert.Equal("int", function.Parameters[0].Type.ToString()); Assert.Equal("int", function.Parameters[1].Type.ToString()); Assert.Equal("num1", function.Parameters[0].Name); Assert.Equal("num2", function.Parameters[1].Name); Assert.Equal("Task<int>", function.ReturnType); Assert.Equal("<int>", function.CallGenerics); }
public void OnVisitSyntaxNode(GeneratorSyntaxContext context) { try { // Only search on one visit, because we just need need to find the DurableTask types // once and then hold a reference of them to use later. if (!Searched) { Searched = true; Initialized = true; Initialized &= DurableFunctionUtility.TryFindDurableOrchestrationContextType(context.SemanticModel, out var durableOrchestrationContextTypeSymbol); Initialized &= DurableFunctionUtility.TryFindDurableClientType(context.SemanticModel, out var durableClientTypeSymbol); DurableOrchestrationContextTypeSymbol = durableOrchestrationContextTypeSymbol; DurableClientTypeSymbol = durableClientTypeSymbol; } // Must have found DurableTask types in order to find DurableFunctions if (!Initialized) { return; } // Looking for things that are methods if (!(context.Node is MethodDeclarationSyntax method)) { return; } if (!DurableFunction.TryParse(context.SemanticModel, method, out DurableFunction function)) { return; } Debug.WriteLine($"Adding function '{function.Name}'"); DurableFunctions.Add(function); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }