|
1 |
| -// Copyright (c) .NET Foundation. All rights reserved. |
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.ObjectModel;
|
6 |
| -using System.Diagnostics.Metrics; |
7 | 6 | using System.Threading.Tasks;
|
8 | 7 | using Microsoft.Azure.WebJobs.Script.Binding;
|
9 | 8 | using Microsoft.Azure.WebJobs.Script.Description;
|
10 | 9 | using Microsoft.Azure.WebJobs.Script.Metrics;
|
11 | 10 | using Microsoft.Azure.WebJobs.Script.Workers;
|
12 |
| -using Microsoft.Extensions.Configuration; |
13 | 11 | using Microsoft.Extensions.DependencyInjection;
|
14 | 12 | using Microsoft.Extensions.Hosting;
|
15 | 13 | using Microsoft.Extensions.Logging.Abstractions;
|
@@ -50,7 +48,9 @@ public WorkerFunctionInvokerTests()
|
50 | 48 | var sc = host.GetScriptHost();
|
51 | 49 |
|
52 | 50 | FunctionMetadata metaData = new FunctionMetadata();
|
53 |
| - _testFunctionInvoker = new TestWorkerFunctionInvoker(sc, null, metaData, NullLoggerFactory.Instance, null, new Collection<FunctionBinding>(), |
| 51 | + BindingMetadata bindingMetadata = new BindingMetadata(); |
| 52 | + bindingMetadata.Name = "TestName"; |
| 53 | + _testFunctionInvoker = new TestWorkerFunctionInvoker(sc, bindingMetadata, metaData, NullLoggerFactory.Instance, new Collection<FunctionBinding>(), new Collection<FunctionBinding>(), |
54 | 54 | _mockFunctionInvocationDispatcher.Object, _applicationLifetime.Object, TimeSpan.FromSeconds(5));
|
55 | 55 | }
|
56 | 56 |
|
@@ -104,5 +104,44 @@ public async Task InvokeInitialized_DoesNotCallShutdown()
|
104 | 104 | }
|
105 | 105 | _applicationLifetime.Verify(a => a.StopApplication(), Times.Never);
|
106 | 106 | }
|
| 107 | + |
| 108 | + [Fact] |
| 109 | + public async Task InvokeCore_DoesNotAddReturn_WhenOutputsIsImmutableDictionary() |
| 110 | + { |
| 111 | + // Arrange |
| 112 | + var mockBinder = new Mock<Binder>(); |
| 113 | + var immutableOutputs = System.Collections.Immutable.ImmutableDictionary<string, object>.Empty; |
| 114 | + var invocationResult = new ScriptInvocationResult |
| 115 | + { |
| 116 | + Outputs = immutableOutputs, |
| 117 | + }; |
| 118 | + |
| 119 | + // Setup the dispatcher to complete the invocation with our result |
| 120 | + _mockFunctionInvocationDispatcher |
| 121 | + .Setup(d => d.InvokeAsync(It.IsAny<ScriptInvocationContext>())) |
| 122 | + .Callback<ScriptInvocationContext>(ctx => |
| 123 | + { |
| 124 | + ctx.ResultSource.SetResult(invocationResult); |
| 125 | + }) |
| 126 | + .Returns(Task.CompletedTask); |
| 127 | + |
| 128 | + _mockFunctionInvocationDispatcher.Setup(a => a.State).Returns(FunctionInvocationDispatcherState.Initialized); |
| 129 | + |
| 130 | + // Act |
| 131 | + var result = await _testFunctionInvoker.InvokeCore( |
| 132 | + new object[] { null, null, null, null, default(System.Threading.CancellationToken) }, |
| 133 | + new FunctionInvocationContext |
| 134 | + { |
| 135 | + Binder = mockBinder.Object, |
| 136 | + ExecutionContext = new ExecutionContext |
| 137 | + { |
| 138 | + InvocationId = Guid.NewGuid() |
| 139 | + } |
| 140 | + }); |
| 141 | + |
| 142 | + // Assert |
| 143 | + Assert.IsType<System.Collections.Immutable.ImmutableDictionary<string, object>>(invocationResult.Outputs); |
| 144 | + Assert.False(invocationResult.Outputs.ContainsKey("$return")); |
| 145 | + } |
107 | 146 | }
|
108 | 147 | }
|
0 commit comments