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 pathTelemetryModulesTests.cs
More file actions
112 lines (85 loc) · 4.83 KB
/
TelemetryModulesTests.cs
File metadata and controls
112 lines (85 loc) · 4.83 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
namespace WindowsServer.Nuget.Tests
{
using System;
using System.Linq;
using System.Xml.Linq;
using Microsoft.ApplicationInsights.WindowsServer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class TelemetryModulesTests
{
private const string DiagnosticsModuleName = "Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights";
[TestMethod]
public void InstallAddsDeveloperModeWithDebuggerAttachedTelemetryModule()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);
Type typeToFind = typeof(DeveloperModeWithDebuggerAttachedTelemetryModule);
var node = ConfigurationHelpers.GetTelemetryModules(configAfterTransform)
.Descendants()
.FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind));
Assert.IsNotNull(node);
}
[TestMethod]
public void InstallAddsUnhandledExceptionTelemetryModule()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);
Type typeToFind = typeof(UnhandledExceptionTelemetryModule);
var node = ConfigurationHelpers.GetTelemetryModules(configAfterTransform)
.Descendants()
.FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind));
Assert.IsNotNull(node);
}
[TestMethod]
[Ignore]
public void InstallAddsFirstChanceExceptionTelemetryModule()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);
Type typeToFind = typeof(FirstChanceExceptionStatisticsTelemetryModule);
var node = ConfigurationHelpers.GetTelemetryModules(configAfterTransform)
.Descendants()
.FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind));
Assert.IsNotNull(node);
}
[TestMethod]
public void InstallDoesNotInstallExtraModules()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);
Type typeToFind = typeof(FirstChanceExceptionStatisticsTelemetryModule);
Assert.AreEqual(5, ConfigurationHelpers.GetTelemetryModules(configAfterTransform).Descendants().Count());
}
[TestMethod]
public void InstallAddsUnobservedExceptionTelemetryModule()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);
Type typeToFind = typeof(UnobservedExceptionTelemetryModule);
var node = ConfigurationHelpers.GetTelemetryModules(configAfterTransform)
.Descendants()
.FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind));
Assert.IsNotNull(node);
}
[TestMethod]
public void UninstallRemovesAllTelemetryModules()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterInstall = ConfigurationHelpers.InstallTransform(emptyConfig);
XDocument configAfterUninstall = ConfigurationHelpers.UninstallTransform(configAfterInstall.ToString());
Assert.AreEqual(0, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).ToList().Count);
}
[TestMethod]
public void UninstallDoesNotRemoveTelemetryModulesTagIfCustomTelemetryModuleIsPresent()
{
string emptyConfig = ConfigurationHelpers.GetEmptyConfig();
XDocument configAfterInstall = ConfigurationHelpers.InstallTransform(emptyConfig);
// Replace valid type on custom so during uninstall it should stay in the config
string customConfig = configAfterInstall.ToString().Replace("DeveloperModeWithDebuggerAttachedTelemetryModule", "blah");
XDocument configAfterUninstall = ConfigurationHelpers.UninstallTransform(customConfig);
Assert.AreEqual(1, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).ToList().Count);
Assert.AreEqual(1, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).Descendants().ToList().Count);
}
}
}