Ejemplo n.º 1
0
        public void Setup()
        {
            _firstPage = new ListMetricsResponse
            {
                NextToken = "token-1",
                Metrics   = new List <Metric>
                {
                    new Metric
                    {
                        MetricName = "ApproximateAgeOfOldestMessage",
                        Dimensions = new List <Dimension>
                        {
                            new Dimension
                            {
                                Name  = "QueueName",
                                Value = "Queue-1"
                            }
                        }
                    }
                }
            };
            _secondPage = new ListMetricsResponse
            {
                NextToken = "token-2",
                Metrics   = new List <Metric>
                {
                    new Metric
                    {
                        MetricName = "ApproximateAgeOfOldestMessage",
                        Dimensions = new List <Dimension>
                        {
                            new Dimension
                            {
                                Name  = "QueueName",
                                Value = "Queue-2_error"
                            }
                        }
                    }
                }
            };
            _thirdPage = new ListMetricsResponse
            {
                NextToken = "token-3",
                Metrics   = new List <Metric>
                {
                    new Metric
                    {
                        MetricName = "ApproximateAgeOfOldestMessage",
                        Dimensions = new List <Dimension>
                        {
                            new Dimension
                            {
                                Name  = "QueueName",
                                Value = "Queue-3"
                            }
                        }
                    },
                    new Metric
                    {
                        MetricName = "ApproximateAgeOfOldestMessage",
                        Dimensions = new List <Dimension>
                        {
                            new Dimension
                            {
                                Name  = "QueueName",
                                Value = "Queue-3_error"
                            }
                        }
                    }
                }
            };

            var cloudWatchMock = new Mock <IAmazonCloudWatch>();

            cloudWatchMock.Setup(s => s.ListMetricsAsync(
                                     It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == null),
                                     It.IsAny <CancellationToken>()))
            .ReturnsAsync(_firstPage);

            cloudWatchMock.Setup(s => s.ListMetricsAsync(
                                     It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == "token-1"),
                                     It.IsAny <CancellationToken>()))
            .ReturnsAsync(_secondPage);

            cloudWatchMock.Setup(s => s.ListMetricsAsync(
                                     It.Is <ListMetricsRequest>(r => r.MetricName == "ApproximateAgeOfOldestMessage" && r.NextToken == "token-2"),
                                     It.IsAny <CancellationToken>()))
            .ReturnsAsync(_thirdPage);


            SUT = new QueueDataV2Source(new QueueSource(cloudWatchMock.Object));
        }