public async Task ShouldListMandatesForACustomer()
        {
            var responseFixture = "fixtures/client/list_mandates_for_a_customer.json";

            mockHttp.EnqueueResponse(200, responseFixture);
            var mandateListRequest = new MandateListRequest()
            {
                Customer  = "CU00003068FG73",
                CreatedAt = new MandateListRequest.CreatedAtParam
                {
                    GreaterThan = new DateTimeOffset(2017, 5, 2, 11, 12, 13, TimeSpan.FromHours(-5))
                }
            };
            var listResponse = await client.Mandates.ListAsync(mandateListRequest);

            TestHelpers.AssertResponseCanSerializeBackToFixture(listResponse, responseFixture);
            var mandates = listResponse.Mandates;

            Assert.AreEqual(2, mandates.Count);
            Assert.AreEqual("MD00001PEYCSQF", mandates[0].Id);
            Assert.AreEqual("CR000035EME9H5", mandates[0].Links.Creditor);
            Assert.AreEqual("MD00001P57AN84", mandates[1].Id);
            Assert.AreEqual("CR000035EME9H5", mandates[1].Links.Creditor);
            mockHttp.AssertRequestMade("GET",
                                       "/mandates?created_at[gt]=2017-05-02T11:12:13.0000000-05:00&customer=CU00003068FG73");
        }
Esempio n. 2
0
        public async Task InsufficentPermissions()
        {
            var responseFixture = "fixtures/insufficient_permissions.json";

            mockHttp.EnqueueResponse(403, responseFixture, resp => resp.Headers.Location = new Uri("/mandates/MD000126", UriKind.Relative));
            try
            {
                await MakeSomeRequest();
            }
            catch (InvalidApiUsageException ex)
            {
                TestHelpers.AssertResponseCanSerializeBackToFixture(ex.ApiErrorResponse, responseFixture);
                Assert.AreEqual(ApiErrorType.INVALID_API_USAGE, ex.Type);
                Assert.AreEqual("Insufficient permissions", ex.Message);
                Assert.AreEqual("Insufficient permissions", ex.Errors.Single().Message);
                Assert.AreEqual("insufficient_permissions", ex.Errors.Single().Reason);
                Assert.AreEqual("insufficient_permissions", ex.Errors.Single().Reason);
                Assert.AreEqual("https://developer.gocardless.com/api-reference#insufficient_permissions",
                                ex.DocumentationUrl);
                Assert.AreEqual("b0e48853-abcd-41fa-9554-5f71820e915d", ex.RequestId);
                Assert.AreEqual(403, ex.Code);
                return;
            }
            Assert.Fail("Exception was not thrown");
        }
Esempio n. 3
0
        public async Task ShouldBuildValidRequest()
        {
            var responseFixture = "fixtures/client/create_a_redirect_flow_response.json";

            mockHttp.EnqueueResponse(201, responseFixture);
            var prefilledCustomer = new RedirectFlowCreateRequest.RedirectFlowPrefilledCustomer()
            {
                Email      = "*****@*****.**",
                GivenName  = "Frank",
                FamilyName = "Osborne"
            };

            var redirectFlowRequest = new RedirectFlowCreateRequest()
            {
                Description        = "Wine boxes",
                SessionToken       = "SESS_wSs0uGYMISxzqOBq",
                SuccessRedirectUrl = "https://example.com/pay/confirm",
                PrefilledCustomer  = prefilledCustomer
            };

            var redirectFlowResponse = await client.RedirectFlows.CreateAsync(redirectFlowRequest);

            TestHelpers.AssertResponseCanSerializeBackToFixture(redirectFlowResponse, responseFixture);

            var redirectFlow = redirectFlowResponse.RedirectFlow;

            Assert.AreEqual("http://pay.gocardless.dev/flow/RE123", redirectFlow.RedirectUrl);
            mockHttp.AssertRequestMade("POST", "/redirect_flows");
        }
        public async Task CanAccessResponseMessageContentAsync()
        {
            //Given a successful request has been made
            http.EnqueueResponse(200, "fixtures/client/list_mandates_for_a_customer.json");
            var mandateListRequest = new MandateListRequest()
            {
                Customer = "CU00003068FG73"
            };
            var listResponse = client.Mandates.ListAsync(mandateListRequest).Result;

            //When the responseMessage attached to the response is inspected
            //Then the responseMessage content can be read
            listResponse.ResponseMessage.Should().NotBeNull();
            var content = await listResponse.ResponseMessage.Content.ReadAsStringAsync();

            Assert.AreEqual(File.ReadAllText("fixtures/client/list_mandates_for_a_customer.json"), content);
        }