public void ReturnsSingleItemWhenPipelineContainsSingleItem() { var pipelineItems = new[] { new object() }; var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems); Assert.Same(pipelineItems[0], returnValue); }
public void ReturnsNewArrayWhenPipelineContainsMultipleItems() { var pipelineItems = new[] { new object(), new object() }; var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems); Assert.IsType <object[]>(returnValue); Assert.NotSame(pipelineItems, returnValue); Assert.Same(pipelineItems[0], ((object[])returnValue)[0]); Assert.Same(pipelineItems[1], ((object[])returnValue)[1]); Assert.Equal(pipelineItems.Length, ((object[])returnValue).Length); }
public void AddPipelineOutputIfNecessary(Collection <object> pipelineItems, Hashtable result) { var shouldAddPipelineOutput = _durableEnabled && _durableFunctionInfo.Type == DurableFunctionType.ActivityFunction; if (shouldAddPipelineOutput) { var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems); result.Add(AzFunctionInfo.DollarReturn, returnValue); } }
public Hashtable Invoke(OrchestrationBindingInfo orchestrationBindingInfo, IPowerShellServices pwsh) { try { var outputBuffer = new PSDataCollection <object>(); var context = orchestrationBindingInfo.Context; // context.History should never be null when initializing CurrentUtcDateTime var orchestrationStart = context.History.First( e => e.EventType == HistoryEventType.OrchestratorStarted); context.CurrentUtcDateTime = orchestrationStart.Timestamp.ToUniversalTime(); // Marks the first OrchestratorStarted event as processed orchestrationStart.IsProcessed = true; var asyncResult = pwsh.BeginInvoke(outputBuffer); var(shouldStop, actions) = orchestrationBindingInfo.Context.OrchestrationActionCollector.WaitForActions(asyncResult.AsyncWaitHandle); if (shouldStop) { // The orchestration function should be stopped and restarted pwsh.StopInvoke(); return(CreateOrchestrationResult(isDone: false, actions, output: null, context.CustomStatus)); } else { try { // The orchestration function completed pwsh.EndInvoke(asyncResult); var result = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(outputBuffer); return(CreateOrchestrationResult(isDone: true, actions, output: result, context.CustomStatus)); } catch (Exception e) { // The orchestrator code has thrown an unhandled exception: // this should be treated as an entire orchestration failure throw new OrchestrationFailureException(actions, context.CustomStatus, e); } } } finally { pwsh.ClearStreamsAndCommands(); } }
public void AddPipelineOutputIfNecessary_AddsDollarReturn_ForActivityFunction() { var durableController = CreateDurableController(DurableFunctionType.ActivityFunction); var pipelineItems = new Collection <object> { "Item1", "Item2", "Item3" }; var result = new Hashtable { { "FieldA", "ValueA" }, { "FieldB", "ValueB" } }; var originalResultCount = result.Count; durableController.AddPipelineOutputIfNecessary(pipelineItems, result); Assert.Equal(originalResultCount + 1, result.Count); var dollarReturnValue = result[AzFunctionInfo.DollarReturn]; Assert.Equal( (IEnumerable <object>)dollarReturnValue, FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems)); }
public void ReturnsNullOnNull() { Assert.Null(FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(null)); }