This repository was archived by the owner on Jul 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathAzureWebAppRoleEnvironmentTelemetryInitializerTest.cs
More file actions
123 lines (97 loc) · 5 KB
/
AzureWebAppRoleEnvironmentTelemetryInitializerTest.cs
File metadata and controls
123 lines (97 loc) · 5 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace Microsoft.ApplicationInsights.WindowsServer
{
using System;
using System.Globalization;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
#if !NETCORE
using Microsoft.ApplicationInsights.WindowsServer.Azure;
using Microsoft.ApplicationInsights.WindowsServer.Azure.Emulation;
#endif
using Microsoft.ApplicationInsights.WindowsServer.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Assert = Xunit.Assert;
[TestClass]
public class AzureWebAppRoleEnvironmentTelemetryInitializerTest
{
[TestMethod]
public void AzureWebAppRoleEnvironmentTelemetryInitializerSetsRoleName()
{
var telemetryItem = new EventTelemetry();
var testVarName = "WEBSITE_" + Guid.NewGuid().ToString() + "_HOSTNAME";
Environment.SetEnvironmentVariable(testVarName, "TestRoleName.azurewebsites.net");
var initializer = new AzureWebAppRoleEnvironmentTelemetryInitializer()
{
WebAppHostNameEnvironmentVariable = testVarName
};
initializer.Initialize(telemetryItem);
Assert.Equal("TestRoleName", telemetryItem.Context.Cloud.RoleName);
Assert.Equal("TestRoleName.azurewebsites.net", telemetryItem.Context.GetInternalContext().NodeName);
Environment.SetEnvironmentVariable(testVarName, null);
}
[TestMethod]
public void AzureWebAppRoleEnvironmentTelemetryInitializerDoesNotOverrideRoleName()
{
var testVarName = "WEBSITE_" + Guid.NewGuid().ToString() + "_HOSTNAME";
Environment.SetEnvironmentVariable(testVarName, "TestRoleName.azurewebsites.net");
var telemetryItem = new EventTelemetry();
telemetryItem.Context.Cloud.RoleName = "Test";
var initializer = new AzureWebAppRoleEnvironmentTelemetryInitializer()
{
WebAppHostNameEnvironmentVariable = testVarName
};
initializer.Initialize(telemetryItem);
Assert.Equal("Test", telemetryItem.Context.Cloud.RoleName);
Assert.Equal("TestRoleName.azurewebsites.net", telemetryItem.Context.GetInternalContext().NodeName);
Environment.SetEnvironmentVariable(testVarName, null);
}
[TestMethod]
public void AzureWebAppRoleEnvironmentTelemetryInitializerDoesNotOverrideRoleInstance()
{
var testVarName = "WEBSITE_" + Guid.NewGuid().ToString() + "_HOSTNAME";
Environment.SetEnvironmentVariable(testVarName, "TestRoleName.azurewebsites.net");
var telemetryItem = new EventTelemetry();
telemetryItem.Context.Cloud.RoleInstance = "Test";
var initializer = new AzureWebAppRoleEnvironmentTelemetryInitializer()
{
WebAppHostNameEnvironmentVariable = testVarName
};
initializer.Initialize(telemetryItem);
Assert.Equal("TestRoleName", telemetryItem.Context.Cloud.RoleName);
Assert.Equal("Test", telemetryItem.Context.Cloud.RoleInstance);
Assert.Equal("TestRoleName.azurewebsites.net", telemetryItem.Context.GetInternalContext().NodeName);
Environment.SetEnvironmentVariable(testVarName, null);
}
[TestMethod]
public void AzureWebAppRoleEnvironmentTelemetryInitializerDoesNotOverrideNodeName()
{
var testVarName = "WEBSITE_" + Guid.NewGuid().ToString() + "_HOSTNAME";
Environment.SetEnvironmentVariable(testVarName, "TestRoleName.azurewebsites.net");
var telemetryItem = new EventTelemetry();
telemetryItem.Context.GetInternalContext().NodeName = "Test";
var initializer = new AzureWebAppRoleEnvironmentTelemetryInitializer()
{
WebAppHostNameEnvironmentVariable = testVarName
};
initializer.Initialize(telemetryItem);
Assert.Equal("TestRoleName", telemetryItem.Context.Cloud.RoleName);
Assert.Equal("Test", telemetryItem.Context.GetInternalContext().NodeName);
Environment.SetEnvironmentVariable(testVarName, null);
}
[TestMethod]
public void AzureWebAppRoleEnvironmentTelemetryInitializerEmptyVariable()
{
var testVarName = "WEBSITE_" + Guid.NewGuid().ToString() + "_HOSTNAME";
Environment.SetEnvironmentVariable(testVarName, null);
var telemetryItem = new EventTelemetry();
var initializer = new AzureWebAppRoleEnvironmentTelemetryInitializer()
{
WebAppHostNameEnvironmentVariable = testVarName
};
initializer.Initialize(telemetryItem);
Assert.Null(telemetryItem.Context.Cloud.RoleName);
Assert.Null(telemetryItem.Context.Cloud.RoleInstance);
Assert.Null(telemetryItem.Context.GetInternalContext().NodeName);
}
}
}