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

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("nextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("subscriptionFilters", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <SubscriptionFilter, SubscriptionFilterUnmarshaller>(SubscriptionFilterUnmarshaller.Instance);
                    response.SubscriptionFilters = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public async Task DescribeSubscriptionFiltersTest_TwoResponses()
        {
            var request       = new DescribeSubscriptionFiltersRequest();
            var firstResponse = new DescribeSubscriptionFiltersResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new DescribeSubscriptionFiltersResponse()
            {
                NextToken = null
            };
            var token = new CancellationToken();

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

            var numResponses = 0;

            await foreach (var desination in _mockClient.Object.Paginators.DescribeSubscriptionFilters(request).Responses.WithCancellation(token))
            {
                numResponses += 1;
            }
            Assert.Equal(2, numResponses);
        }
        public async Task DescribeSubscriptionFiltersTest__OnlyUsedOnce()
        {
            var request   = new DescribeSubscriptionFiltersRequest();
            var response  = new DescribeSubscriptionFiltersResponse();
            var token     = new CancellationToken();
            var paginator = _mockClient.Object.Paginators.DescribeSubscriptionFilters(request);

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

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

            // Second time should throw an exception
            await Assert.ThrowsAsync <System.InvalidOperationException>(async() => await LoopOverSubscriptionFilters(paginator, token));
        }
        public async Task DescribeSubscriptionFiltersTest__CancellationToken()
        {
            var request       = new DescribeSubscriptionFiltersRequest();
            var firstResponse = new DescribeSubscriptionFiltersResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new DescribeSubscriptionFiltersResponse()
            {
                NextToken = null
            };
            var paginator = _mockClient.Object.Paginators.DescribeSubscriptionFilters(request);

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

            tokenSource.Cancel();

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

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