-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathBaseExecutionContextTests.cs
More file actions
59 lines (50 loc) · 2.46 KB
/
BaseExecutionContextTests.cs
File metadata and controls
59 lines (50 loc) · 2.46 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Net;
using Microsoft.Extensions.Hosting;
using Microsoft.Omex.Extensions.Abstractions.ExecutionContext;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Microsoft.Omex.Extensions.Hosting.Services.UnitTests
{
[TestClass]
public class BaseExecutionContextTests
{
[DataTestMethod]
[DataRow("Development", true)]
[DataRow("Prod", false)]
public void Constructor_InitializesPropertiesProperly(string enviroment, bool isPrivate)
{
string clusterName = "SomeClusterName";
string regionName = "SomeRegionName";
string sliceName = "SomeSliceName";
string applicationName = "SomeApplicationName";
string serviceName = "SomeServiceName";
string nodeName = "SomeNodeName";
string packageName = "SomePackageName";
IPAddress nodeIPOrFQDN = IPAddress.Parse("192.0.0.1");
Environment.SetEnvironmentVariable(BaseExecutionContext.ClusterNameVariableName, clusterName);
Environment.SetEnvironmentVariable(BaseExecutionContext.ServicePackageVariableName, packageName);
Environment.SetEnvironmentVariable(BaseExecutionContext.RegionNameVariableName, regionName);
Environment.SetEnvironmentVariable(BaseExecutionContext.SliceNameVariableName, sliceName);
Environment.SetEnvironmentVariable(BaseExecutionContext.ApplicationNameVariableName, applicationName);
Environment.SetEnvironmentVariable(BaseExecutionContext.ServiceNameVariableName, serviceName);
Environment.SetEnvironmentVariable(BaseExecutionContext.NodeNameVariableName, nodeName);
Environment.SetEnvironmentVariable(BaseExecutionContext.NodeIPOrFQDNVariableName, nodeIPOrFQDN.ToString());
Mock<IHostEnvironment> enviromentMock = new Mock<IHostEnvironment>();
enviromentMock.SetupGet(e => e.EnvironmentName).Returns(enviroment);
IExecutionContext info = new BaseExecutionContext(enviromentMock.Object);
Assert.AreEqual(clusterName, info.Cluster);
Assert.AreEqual(regionName, info.RegionName);
Assert.AreEqual(sliceName, info.DeploymentSlice);
Assert.AreEqual(packageName, info.ServicePackageName);
Assert.AreEqual(enviroment, info.EnvironmentName);
Assert.AreEqual(isPrivate, info.IsPrivateDeployment);
Assert.AreEqual(applicationName, info.ApplicationName);
Assert.AreEqual(serviceName, info.ServiceName);
StringAssert.Contains(info.MachineId, nodeName);
Assert.AreEqual(nodeIPOrFQDN, info.ClusterIpAddress);
}
}
}