Exemplo n.º 1
0
        public void Should_return_a_result()
        {
            //Arrange
            var counterBusiness = new CounterBusiness();
            var config = Mock.Of<IConfig>(x => x.Groups == Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "_Total").Take(2).ToList()).Take(2).ToList());
            Exception exception = null;

            //Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(exception, Is.Null);
            Assert.That(result.Count(), Is.EqualTo(2));
        }
Exemplo n.º 2
0
        public void Should_Apply_Filter_Which_Returns_None()
        {
            // The test filter remove all counters

            // Arrange
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute("MyInstance")).Returns((string)null);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(c => c.CategoryName == "Processor" && c.CounterName == "% Processor Time" && c.InstanceName == "*").Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(cg => cg.Name == "A" && cg.Counters == counters && cg.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(cfg => cfg.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(0), "Filter should have removed all performances counters");
        }
Exemplo n.º 3
0
        public void Should_Apply_Filter_Which_Returns_All()
        {
            // The test filter match all counters
            // For the processor time, it will result in having Environment.ProcessorCount + 1 counters (_Total)

            // Arrange
            var filterExpression = new Func<string, string>(z => z);
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute(It.IsAny<string>())).Returns(filterExpression);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "*" && z.MachineName == null && z.Max == null && z.Tags == new List<ITag> {}).Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == counters && y.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(x => x.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(Environment.ProcessorCount + 1));
        }
Exemplo n.º 4
0
        public void Should_Apply_Filter_Which_Returns_One()
        {
            // The test filter match one counter : _Total 

            // Arrange
            var filterExpression = new Func<string, string>(z => z == "_Total" ? z : null);
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute(It.IsAny<string>())).Returns(filterExpression);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "*").Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == counters && y.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(x => x.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(1));
            Assert.AreEqual(resultCounters.First().InstanceName, "_Total");
        }
Exemplo n.º 5
0
        public void Should_throw_if_no_groups()
        {
            //Arrange
            var counterBusiness = new CounterBusiness();
            var config = Mock.Of<IConfig>();
            Exception exception = null;
            List<IPerformanceCounterGroup> result = null;

            //Act
            try
            {
                result = counterBusiness.GetPerformanceCounterGroups(config).ToList();
            }
            catch (Exception exp)
            {
                exception = exp;
            }

            //Assert
            Assert.That(result, Is.Null);
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("No groups in config."));
        }