Exemplo n.º 1
0
        public ActionResult <GetSubscriptionsResponse> Get()
        {
            GetSubscriptionsRequest  request  = new GetSubscriptionsRequest();
            GetSubscriptionsResponse response = this._getSubscriptions.Process(request);

            return(response);
        }
        public async Task MapsPagingProperties()
        {
            // given
            var subject = new SubscriptionsClient(_clientConfiguration);

            var firstPageRequest = new GetSubscriptionsRequest
            {
                Limit = 1
            };

            // when
            var firstPageResult = await subject.GetPageAsync(firstPageRequest);

            var secondPageRequest = new GetSubscriptionsRequest
            {
                After = firstPageResult.Meta.Cursors.After,
                Limit = 2
            };

            var secondPageResult = await subject.GetPageAsync(secondPageRequest);

            // then
            Assert.That(firstPageResult.Items.Count(), Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Limit, Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Cursors.Before, Is.Null);
            Assert.That(firstPageResult.Meta.Cursors.After, Is.Not.Null);

            Assert.That(secondPageResult.Items.Count(), Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Limit, Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Cursors.Before, Is.Not.Null);
            Assert.That(secondPageResult.Meta.Cursors.After, Is.Not.Null);
        }
        public GetSubscriptionsResult GetSubscriptions(GetSubscriptionsRequest request)
        {
            // TODO: Handle user subscription version
            var subscriptions = GetUserSubscriptions(request.Users.Select(u => u.User));

            return(new GetSubscriptionsResult
            {
                Result = new ServiceResult <List <UserSubscriptions> >
                {
                    Data = subscriptions.ToList()
                }
            });
        }
Exemplo n.º 4
0
        public void GetSubscriptionsRequestIsNullThrows()
        {
            // given
            var subject = new SubscriptionsClient(_clientConfiguration);

            GetSubscriptionsRequest request = null;

            // when
            AsyncTestDelegate test = () => subject.GetPageAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ArgumentNullException>(test);

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
Exemplo n.º 5
0
        public async Task CallsGetSubscriptionsEndpointUsingRequest()
        {
            // given
            var subject = new SubscriptionsClient(_clientConfiguration);

            var request = new GetSubscriptionsRequest
            {
                Before = "before test",
                After  = "after test",
                Limit  = 5
            };

            // when
            await subject.GetPageAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/subscriptions?before=before%20test&after=after%20test&limit=5")
            .WithVerb(HttpMethod.Get);
        }
        public async Task PagesThroughSubscriptions()
        {
            // given
            var subject = new SubscriptionsClient(_clientConfiguration);
            var firstId = (await subject.GetPageAsync()).Items.First().Id;

            var initialRequest = new GetSubscriptionsRequest
            {
                After = firstId,
                CreatedGreaterThan = new DateTimeOffset(DateTime.Now.AddDays(-1)),
                Limit = 1,
            };

            // when
            var result = await subject
                         .BuildPager()
                         .StartFrom(initialRequest)
                         .AndGetAllAfterAsync();

            // then
            Assert.That(result.Count, Is.GreaterThan(1));
            Assert.That(result[0].Id, Is.Not.Null.And.Not.EqualTo(result[1].Id));
            Assert.That(result[1].Id, Is.Not.Null.And.Not.EqualTo(result[0].Id));
        }