Esempio n. 1
0
        public void TestConfigStoreTraceConfig()
        {
            lock (ContextLock)
            {
                var onFilterUpdateCalledCount = 0;
                TraceConfig.OnFilterUpdate += sinkType =>
                {
                    switch (sinkType)
                    {
                    case TraceSinkType.ETW:
                        Assert.IsTrue(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Informational, EventTask.None, string.Empty),
                            "ETW should allow info traces.");
                        Assert.IsFalse(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Verbose, EventTask.None, string.Empty),
                            "ETW shouldn't allow verbose traces.");
                        Assert.IsTrue(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Verbose, FabricEvents.Tasks.FabricDCA, "ServiceResolver"),
                            "ETW should allow DCA.ServiceResolver verbose traces.");
                        Assert.IsTrue(TraceConfig.GetEventProvisionalFeatureStatus(sinkType), "ETW should have Provisional Featue Enabled");
                        break;

                    case TraceSinkType.Console:
                        Assert.IsTrue(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Error, EventTask.None, string.Empty),
                            "Console should allow error traces.");
                        Assert.IsFalse(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Warning, EventTask.None, string.Empty),
                            "Console shouldn't allow warning traces.");
                        break;

                    case TraceSinkType.TextFile:
                        Console.WriteLine("Entering - TextFile");
                        Assert.IsTrue(
                            TraceConfig.GetEventEnabledStatus(sinkType, EventLevel.Verbose, EventTask.None, string.Empty),
                            "Text file should allow all traces.");
                        break;

                    default:
                        Assert.Fail("Unknown sink type filter updated" + sinkType);
                        break;
                    }

                    onFilterUpdateCalledCount++;
                };

                var mockConfigReader = new Mock <TraceConfig.IConfigReader>(MockBehavior.Strict);
                mockConfigReader.Setup(cr => cr.GetSections()).Returns(new[] { "Trace/File", "Trace/Etw", "Trace/Console" });

                SetMockConfig(mockConfigReader, "Trace/File", EventLevel.Verbose, null, "DoesntMatter.trace");

                SetMockConfig(mockConfigReader, "Trace/Etw", EventLevel.Informational, "FabricDCA.ServiceResolver:5");

                SetMockConfig(mockConfigReader, "Trace/Console", EventLevel.Error);

                TraceConfig.InitializeFromConfigStore(mockConfigReader.Object);
                Assert.AreEqual(3, onFilterUpdateCalledCount);
            }
        }