コード例 #1
0
        public async Task AggregateMultipleMetrics()
        {
            string expectedMetric1      = "one";
            string expectedMetric2      = "two";
            int    expectedMetric1Value = 1;
            int    expectedMetric2Value = 2;

            Uri name = new Uri("test://dictionary");
            MockReliableStateManager          stateManager = new MockReliableStateManager();
            MockReliableDictionary <int, int> dictionary   = new MockReliableDictionary <int, int>(name);

            dictionary.OnGetLoadMetrics = () =>
                                          new DecimalLoadMetric[]
            {
                new DecimalLoadMetric(expectedMetric1, (double)expectedMetric1Value),
                new DecimalLoadMetric(expectedMetric2, (double)expectedMetric2Value)
            };

            stateManager.SetMock(name, dictionary);

            MetricAggregator         target = new MetricAggregator();
            IEnumerable <LoadMetric> actual = await target.Aggregate(stateManager, CancellationToken.None);

            Assert.AreEqual <int>(1, actual.Count(x => x.Name == expectedMetric1 && x.Value == expectedMetric1Value));
            Assert.AreEqual <int>(1, actual.Count(x => x.Name == expectedMetric2 && x.Value == expectedMetric2Value));
        }
コード例 #2
0
        public async Task AggregateEmptyStateManager()
        {
            MockReliableStateManager stateManager = new MockReliableStateManager();
            MetricAggregator         target       = new MetricAggregator();

            IEnumerable <LoadMetric> actual = await target.Aggregate(stateManager, CancellationToken.None);

            Assert.IsFalse(actual.Any());
        }
コード例 #3
0
        public async Task AggregateEmptyMetrics()
        {
            Uri name = new Uri("test://dictionary");
            MockReliableStateManager          stateManager = new MockReliableStateManager();
            MockReliableDictionary <int, int> dictionary   = new MockReliableDictionary <int, int>(name);

            dictionary.OnGetLoadMetrics = () =>
                                          new DecimalLoadMetric[0];

            stateManager.SetMock(name, dictionary);

            MetricAggregator         target = new MetricAggregator();
            IEnumerable <LoadMetric> actual = await target.Aggregate(stateManager, CancellationToken.None);

            Assert.IsFalse(actual.Any());
        }
コード例 #4
0
        public async Task AggregateMultipleCollectionsSameMetrics()
        {
            string expectedMetric1 = "one";
            string expectedMetric2 = "two";

            double inputMetric1Value = 1.9;
            double inputMetric2Value = 4.1;

            int expectedMetric1Value = 2;
            int expectedMetric2Value = 4;

            Uri collection1Name = new Uri("test://dictionary1");
            Uri collection2Name = new Uri("test://dictionary2");

            MockReliableStateManager          stateManager = new MockReliableStateManager();
            MockReliableDictionary <int, int> dictionary1  = new MockReliableDictionary <int, int>(collection1Name);
            MockReliableDictionary <int, int> dictionary2  = new MockReliableDictionary <int, int>(collection2Name);

            dictionary1.OnGetLoadMetrics = () =>
                                           new DecimalLoadMetric[]
            {
                new DecimalLoadMetric(expectedMetric1, inputMetric1Value / 2.0),
                new DecimalLoadMetric(expectedMetric2, inputMetric2Value / 2.0)
            };

            dictionary2.OnGetLoadMetrics = () =>
                                           new DecimalLoadMetric[]
            {
                new DecimalLoadMetric(expectedMetric1, inputMetric1Value / 2.0),
                new DecimalLoadMetric(expectedMetric2, inputMetric2Value / 2.0)
            };

            stateManager.SetMock(collection1Name, dictionary1);
            stateManager.SetMock(collection2Name, dictionary2);


            MetricAggregator         target = new MetricAggregator();
            IEnumerable <LoadMetric> actual = await target.Aggregate(stateManager, CancellationToken.None);

            Assert.AreEqual <int>(1, actual.Count(x => x.Name == expectedMetric1 && x.Value == expectedMetric1Value));
            Assert.AreEqual <int>(1, actual.Count(x => x.Name == expectedMetric2 && x.Value == expectedMetric2Value));
        }