/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeDestinationsResponse response = new DescribeDestinationsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("destinations", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Destination, DestinationUnmarshaller>(DestinationUnmarshaller.Instance);
                    response.Destinations = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("nextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public async Task DescribeDestinationsTest_TwoResponses()
        {
            var request       = new DescribeDestinationsRequest();
            var firstResponse = new DescribeDestinationsResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new DescribeDestinationsResponse()
            {
                NextToken = null
            };
            var token = new CancellationToken();

            _mockClient.SetupSequence(x => x.DescribeDestinationsAsync(It.IsAny <DescribeDestinationsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(firstResponse)
            .ReturnsAsync(secondResponse);

            var numResponses = 0;

            await foreach (var desination in _mockClient.Object.Paginators.DescribeDestinations(request).Responses.WithCancellation(token))
            {
                numResponses += 1;
            }
            Assert.Equal(2, numResponses);
        }
Beispiel #3
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudWatchLogsConfig config = new AmazonCloudWatchLogsConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(creds, config);

            DescribeDestinationsResponse resp = new DescribeDestinationsResponse();

            do
            {
                DescribeDestinationsRequest req = new DescribeDestinationsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    Limit = maxItems
                };

                resp = client.DescribeDestinations(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Destinations)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        public async Task DescribeDestinationsTest__OnlyUsedOnce()
        {
            var request   = new DescribeDestinationsRequest();
            var response  = new DescribeDestinationsResponse();
            var token     = new CancellationToken();
            var paginator = _mockClient.Object.Paginators.DescribeDestinations(request);

            _mockClient.Setup(x => x.DescribeDestinationsAsync(It.IsAny <DescribeDestinationsRequest>(), It.IsAny <CancellationToken>())).ReturnsAsync(response);

            // Should work the first time
            await LoopOverDestinations(paginator, token);

            // Second time should throw an exception
            await Assert.ThrowsAsync <System.InvalidOperationException>(async() => await LoopOverDestinations(paginator, token));
        }
        public async Task DescribeDestinationsTest__CancellationToken()
        {
            var request       = new DescribeDestinationsRequest();
            var firstResponse = new DescribeDestinationsResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new DescribeDestinationsResponse()
            {
                NextToken = null
            };
            var paginator = _mockClient.Object.Paginators.DescribeDestinations(request);

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            tokenSource.Cancel();

            _mockClient.SetupSequence(x => x.DescribeDestinationsAsync(It.IsAny <DescribeDestinationsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(firstResponse)
            .ReturnsAsync(secondResponse);

            await Assert.ThrowsAsync <OperationCanceledException>(async() => await LoopOverDestinations(paginator, token));
        }