Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix failing unit tests (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
pharring authored and TimothyMothra committed Apr 14, 2018
1 parent 13b231e commit b081414
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void ValidateLoggingIsWorking()
[TestCategory("Log4NetAppender")]
public void TracesAreEnqueuedInChannel()
{
TelemetryConfiguration.Active.InstrumentationKey = this.adapterHelper.InstrumentationKey;
TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;

ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);
Expand Down
11 changes: 3 additions & 8 deletions test/Shared/AdapterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.ApplicationInsights.Tracing.Tests
using System.Reflection;
using System.Threading;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class AdapterHelper : IDisposable
Expand All @@ -21,13 +20,15 @@ public class AdapterHelper : IDisposable
#if NET45 || NET46
private static readonly string ApplicationInsightsConfigFilePath =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApplicationInsights.config");
#else
private static readonly string ApplicationInsightsConfigFilePath =
Path.Combine(Path.GetDirectoryName(typeof(AdapterHelper).GetTypeInfo().Assembly.Location), "ApplicationInsights.config");
#endif

public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C309AE69")
{
this.InstrumentationKey = instrumentationKey;

#if NET45 || NET46
string configuration = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ApplicationInsights xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
Expand All @@ -36,10 +37,6 @@ public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C3
instrumentationKey);

File.WriteAllText(ApplicationInsightsConfigFilePath, configuration);
#else
TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
#endif

this.Channel = new CustomTelemetryChannel();
}

Expand Down Expand Up @@ -85,12 +82,10 @@ private void Dispose(bool dispossing)
{
this.Channel.Dispose();

#if NET45 || NET46
if (File.Exists(ApplicationInsightsConfigFilePath))
{
File.Delete(ApplicationInsightsConfigFilePath);
}
#endif
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/Shared/ApplicationInsightsTraceListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void TraceListenerInitializeTDoesNoThrowWhenInstrumentationKeyIsEmpty()
[TestCategory("TraceListener")]
public void TraceListenerWriteUsedApplicationInsightsConfigInstrumentationKeyWhenUnspecifiedInstrumentationKey()
{
TelemetryConfiguration.Active.InstrumentationKey = this.adapterHelper.InstrumentationKey;

// Changing the channel to Mock channel to verify
// the Telemetry event is assigned with the InstrumentationKey from configuration
TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;
Expand Down

0 comments on commit b081414

Please sign in to comment.