-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathHostPropertyConditionTests.cs
More file actions
76 lines (63 loc) · 3.58 KB
/
HostPropertyConditionTests.cs
File metadata and controls
76 lines (63 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using System.Text.Json;
using Microsoft.Azure.WebJobs.Script.Workers;
using Microsoft.Azure.WebJobs.Script.Workers.Profiles;
using Xunit;
namespace Microsoft.Azure.WebJobs.Script.Tests.Workers.Profiles
{
public class HostPropertyConditionTests
{
private TestSystemRuntimeInformation _testSystemRuntimeInfo = new TestSystemRuntimeInformation();
[Theory]
[InlineData(null, null)]
[InlineData("", "")]
[InlineData("", null)]
[InlineData(null, "")]
[InlineData("sku", null)]
[InlineData("Platform", "")]
[InlineData("HostVersion", null)]
[InlineData("APPLICATIONINSIGHTS_ENABLE_AGENT", "")]
[InlineData(null, "true")]
[InlineData("", "true")]
public void HostPropertyConditionTest_ThrowsValidationException(string name, string expression)
{
var testLogger = new TestLogger("test");
var descriptor = new WorkerProfileConditionDescriptor();
descriptor.Type = WorkerConstants.WorkerDescriptionProfileHostPropertyCondition;
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionName] = JsonSerializer.SerializeToElement(name);
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionExpression] = JsonSerializer.SerializeToElement(expression);
Assert.Throws<ValidationException>(() => new HostPropertyCondition(testLogger, _testSystemRuntimeInfo, descriptor));
}
[Theory]
//[InlineData("sku", "Dynamic")] TODO: Add test case
[InlineData("platForm", "LINUX")]
[InlineData("HostVersion", "4.*")]
public void HostPropertyConditionTest_EvaluateTrue(string name, string testExpression)
{
var testLogger = new TestLogger("test");
var descriptor = new WorkerProfileConditionDescriptor();
descriptor.Type = WorkerConstants.WorkerDescriptionProfileHostPropertyCondition;
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionName] = JsonSerializer.SerializeToElement(name);
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionExpression] = JsonSerializer.SerializeToElement(testExpression);
var hostPropertyCondition = new HostPropertyCondition(testLogger, _testSystemRuntimeInfo, descriptor);
Assert.True(hostPropertyCondition.Evaluate());
}
[Theory]
//[InlineData("sku", "Dynamic")] TODO: Add test case
[InlineData("platForm", "Windows")]
[InlineData("HostVersion", "-1")]
public void HostPropertyConditionTest_EvaluateFalse(string name, string testExpression)
{
var testLogger = new TestLogger("test");
var descriptor = new WorkerProfileConditionDescriptor();
descriptor.Type = WorkerConstants.WorkerDescriptionProfileHostPropertyCondition;
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionName] = JsonSerializer.SerializeToElement(name);
descriptor.Properties[WorkerConstants.WorkerDescriptionProfileConditionExpression] = JsonSerializer.SerializeToElement(testExpression);
var hostPropertyCondition = new HostPropertyCondition(testLogger, _testSystemRuntimeInfo, descriptor);
Assert.False(hostPropertyCondition.Evaluate(), "Expression evaluates to false");
}
}
}