コード例 #1
0
        public static void PerformanceCounterExceptionHandler_Counter_Not_Available()
        {
            // Arrange
            var handler = new PerformanceCounterExceptionHandler()
            {
                Counters = new[]
                {
                    @"\XXXXX\XXXXXX"
                },
                WatchWindow = 1
            };
            var ex = new InvalidOperationException();

            // Act
            var result = handler.HandleException(ex);

            // Assert
            Assert.False(result);
            var counters = (NameValueCollection)ex.Data["Performance Counters"];

            Assert.Equal(1, counters.Count);
            Assert.Equal("N/A", counters[0]);
        }
コード例 #2
0
        public static void PerformanceCounterExceptionHandler()
        {
            // Arrange
            var handler = new PerformanceCounterExceptionHandler()
            {
                Counters = new[]
                {
                    @"\Memory\Pages/sec",
                    @"\PhysicalDisk(_Total)\Avg. Disk Queue Length",
                    @"\Processor(_Total)\% Processor Time"
                }
            };
            var ex = new InvalidOperationException();

            // Act
            var result = handler.HandleException(ex);

            // Assert
            Assert.False(result);
            var counters = (NameValueCollection)ex.Data["Performance Counters"];

            Assert.Equal(3, counters.Count);
            Assert.True(handler.Counters.All(name => NameValueCollectionHelper.HasKey(counters, name)));
        }