public void TestErrorMessageWillBeTraced()
        {
            InMemoryTraceListener listener = new InMemoryTraceListener();

            using (TraceSourceForEventSource source = new TraceSourceForEventSource(SourceLevels.Error))
            {
                source.Listeners.Add(listener);

                using (TestEventSource eventSource = new TestEventSource())
                {
                    eventSource.TraceError("MyError");

                    Assert.IsTrue(listener.Trace.Contains("MyError"), "Actual: " + listener.Trace);
                }
            }
        }
        public void FilePathCanBeChangedForModule()
        {
            using (FileDiagnosticsTelemetryModule module = new FileDiagnosticsTelemetryModule())
            {
                module.LogFilePath = Directory.GetCurrentDirectory();

                using (TestEventSource eventSource = new TestEventSource())
                {
                    eventSource.TraceError("MyError");

                    string fileName = Path.Combine(module.LogFilePath, module.LogFileName);
                    Assert.IsTrue(File.Exists(fileName));
                    using (StreamReader sr = new StreamReader(fileName))
                    {
                        var content = sr.ReadToEnd();
                        Assert.IsTrue(content.Contains("MyError"), "Actual content: " + content);
                    }
                }
            }
        }
        public void ModuleTracesToTempFolder()
        {
            using (FileDiagnosticsTelemetryModule module = new FileDiagnosticsTelemetryModule())
            {
                module.Initialize(null);
                using (TestEventSource eventSource = new TestEventSource())
                {
                    eventSource.TraceError("MyError");
                    Assert.IsTrue(module.LogFileName.Contains("ApplicationInsightsLog"), "Actual file name: " + module.LogFileName.Contains("ApplicationInsightsLog"));

                    string fileName = Path.Combine(module.LogFilePath, module.LogFileName);
                    Assert.IsTrue(File.Exists(fileName));
                    using (StreamReader sr = new StreamReader(fileName))
                    {
                        var content = sr.ReadToEnd();
                        Assert.IsTrue(content.Contains("MyError"), "Actual content: " + content);
                    }
                }
            }
        }
        private void SetInvalidFolder(string directoryName)
        {
            using (FileDiagnosticsTelemetryModule module = new FileDiagnosticsTelemetryModule())
            {
                module.LogFilePath = directoryName;

                using (TestEventSource eventSource = new TestEventSource())
                {
                    eventSource.TraceError("MyError");
                    Assert.AreNotEqual(directoryName, module.LogFilePath);

                    string fileName = Path.Combine(module.LogFilePath, module.LogFileName);
                    Assert.IsTrue(File.Exists(fileName));
                    using (StreamReader sr = new StreamReader(fileName))
                    {
                        var content = sr.ReadToEnd();
                        Assert.IsTrue(content.Contains("MyError"), "Actual content: " + content);
                    }
                }
            }
        }