8
8
using System . Linq ;
9
9
using System . Threading . Tasks ;
10
10
using Microsoft . Azure . WebJobs . Script . Description ;
11
- using Microsoft . Azure . WebJobs . Script . Grpc . Messages ;
12
- using Microsoft . Azure . WebJobs . Script . Workers ;
13
11
using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
14
12
using Microsoft . Extensions . Logging ;
13
+ using Microsoft . Extensions . Options ;
15
14
using Moq ;
16
- using NuGet . ContentModel ;
17
15
using Xunit ;
18
16
19
17
namespace Microsoft . Azure . WebJobs . Script . Tests
20
18
{
21
19
public class WorkerFunctionMetadataProviderTests
22
20
{
21
+ private readonly WorkerFunctionMetadataProvider _workerFunctionMetadataProvider ;
22
+
23
+ public WorkerFunctionMetadataProviderTests ( )
24
+ {
25
+ var mockScriptOptions = new Mock < IOptionsMonitor < ScriptApplicationHostOptions > > ( ) ;
26
+ var mockLogger = new Mock < ILogger < WorkerFunctionMetadataProvider > > ( ) ;
27
+ var mockEnvironment = new Mock < IEnvironment > ( ) ;
28
+ var mockChannelManager = new Mock < IWebHostRpcWorkerChannelManager > ( ) ;
29
+ var mockScriptHostManager = new Mock < IScriptHostManager > ( ) ;
30
+
31
+ _workerFunctionMetadataProvider = new WorkerFunctionMetadataProvider (
32
+ mockScriptOptions . Object ,
33
+ mockLogger . Object ,
34
+ mockEnvironment . Object ,
35
+ mockChannelManager . Object ,
36
+ mockScriptHostManager . Object ) ;
37
+ }
38
+
23
39
[ Fact ]
24
40
public void ValidateBindings_NoBindings_Throws ( )
25
41
{
@@ -28,7 +44,7 @@ public void ValidateBindings_NoBindings_Throws()
28
44
29
45
var ex = Assert . Throws < FormatException > ( ( ) =>
30
46
{
31
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
47
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
32
48
} ) ;
33
49
34
50
Assert . Equal ( "At least one binding must be declared." , ex . Message ) ;
@@ -45,7 +61,7 @@ public void ValidateBindings_DuplicateBindingNames_Throws()
45
61
46
62
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
47
63
{
48
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
64
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
49
65
} ) ;
50
66
51
67
Assert . Equal ( "Multiple bindings with name 'dupe' discovered. Binding names must be unique." , ex . Message ) ;
@@ -60,7 +76,7 @@ public void ValidateBindings_NoTriggerBinding_Throws()
60
76
61
77
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
62
78
{
63
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
79
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
64
80
} ) ;
65
81
66
82
Assert . Equal ( "No trigger binding specified. A function must have a trigger input binding." , ex . Message ) ;
@@ -81,7 +97,7 @@ public void ValidateBindings_InvalidName_Throws(string bindingName)
81
97
82
98
var ex = Assert . Throws < ArgumentException > ( ( ) =>
83
99
{
84
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
100
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
85
101
} ) ;
86
102
87
103
Assert . Equal ( $ "The binding name { bindingName } is invalid. Please assign a valid name to the binding.", ex . Message ) ;
@@ -108,7 +124,7 @@ public void ValidateBindings_ValidName_DoesNotThrow(string bindingName)
108
124
109
125
try
110
126
{
111
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
127
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
112
128
}
113
129
catch ( ArgumentException )
114
130
{
@@ -123,7 +139,7 @@ public void ValidateFunctionAppFormat_InputMixedApp()
123
139
logger . ClearLogMessages ( ) ;
124
140
string scriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , "sample" , "node" ) ;
125
141
var environment = SystemEnvironment . Instance ;
126
- WorkerFunctionMetadataProvider . ValidateFunctionAppFormat ( scriptPath , logger , environment ) ;
142
+ _workerFunctionMetadataProvider . ValidateFunctionAppFormat ( scriptPath , logger , environment ) ;
127
143
var traces = logger . GetLogMessages ( ) ;
128
144
var functionLoadLogs = traces . Where ( m => m . FormattedMessage . Contains ( "Detected mixed function app. Some functions may not be indexed" ) ) ;
129
145
Assert . True ( functionLoadLogs . Any ( ) ) ;
@@ -139,7 +155,7 @@ public void ValidateBindings_OutputNameWithoutDirection_Throws()
139
155
140
156
var ex = Assert . Throws < ArgumentException > ( ( ) =>
141
157
{
142
- WorkerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
158
+ _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
143
159
} ) ;
144
160
145
161
Assert . Equal ( $ "{ ScriptConstants . SystemReturnParameterBindingName } bindings must specify a direction of 'out'.", ex . Message ) ;
@@ -180,5 +196,19 @@ public async void ValidateFunctionMetadata_Logging()
180
196
Assert . Equal ( "Reading functions metadata (Worker)" , traces [ 1 ] . FormattedMessage ) ;
181
197
// The third log is Host is running without any initialized channels, restarting the JobHost. This is not relevant to this test.
182
198
}
199
+
200
+ [ Fact ]
201
+ public void ValidateFunctionMetadata_IsoStringNotAltered ( )
202
+ {
203
+ FunctionMetadata functionMetadata = new FunctionMetadata ( ) ;
204
+ List < string > rawBindings = new List < string > ( ) ;
205
+ var isoString = "2025-02-10T22:45:33Z" ;
206
+ rawBindings . Add ( "{\" type\" : \" cosmosDBTrigger\" ,\" name\" : \" cosmosTrigger\" ,\" direction\" : \" in\" ,\" databaseName\" :\" databaseName\" ," +
207
+ "\" containerName\" :\" containerNameFoo\" ,\" leaseContainerName\" :\" leaseContanerFoo\" ,\" createLeaseContainerIfNotExists\" :true," +
208
+ "\" connection\" :\" CosmosConnection\" ,\" startFromTime\" :\" " + isoString + "\" ,\" dataType\" :\" String\" }" ) ;
209
+
210
+ var function = _workerFunctionMetadataProvider . ValidateBindings ( rawBindings , functionMetadata ) ;
211
+ Assert . Equal ( isoString , function . Bindings . FirstOrDefault ( ) . Raw [ "startFromTime" ] . ToString ( ) ) ;
212
+ }
183
213
}
184
214
}
0 commit comments