public async Task CallsCreateRedirectFlowEndpoint()
        {
            // given
            var subject = new RedirectFlowsClient(_clientConfiguration);

            var request = new CreateRedirectFlowRequest();

            // when
            await subject.CreateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/redirect_flows")
            .WithVerb(HttpMethod.Post);
        }
        public void CreateRedirectFlowRequestIsNullThrows()
        {
            // given
            var subject = new RedirectFlowsClient(_clientConfiguration);

            CreateRedirectFlowRequest request = null;

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

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

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
        internal async Task <RedirectFlow> CreateRedirectFlowFor(Creditor creditor)
        {
            var request = new CreateRedirectFlowRequest
            {
                Description = "First redirect flow",
                Links       = new CreateRedirectFlowLinks
                {
                    Creditor = creditor.Id
                },
                PrefilledCustomer = new PrefilledCustomer
                {
                    AddressLine1          = "Address Line 1",
                    AddressLine2          = "Address Line 2",
                    AddressLine3          = "Address Line 3",
                    City                  = "London",
                    CompanyName           = "Company Name",
                    CountryCode           = "GB",
                    DanishIdentityNumber  = "2205506218",
                    Email                 = "*****@*****.**",
                    FamilyName            = "Family Name",
                    GivenName             = "Given Name",
                    Language              = "en",
                    PostalCode            = "SW1A 1AA",
                    Region                = "Essex",
                    SwedishIdentityNumber = "5302256218",
                },
                Scheme             = Scheme.Bacs,
                SessionToken       = Guid.NewGuid().ToString(),
                SuccessRedirectUrl = "https://localhost",
            };

            // when
            var redirectFlowsClient = new RedirectFlowsClient(_clientConfiguration);

            return((await redirectFlowsClient.CreateAsync(request)).Item);
        }
        public async Task CreatesAndReturnsRedirectFlow()
        {
            // given
            var creditor = await _resourceFactory.Creditor();

            var subject = new RedirectFlowsClient(_clientConfiguration);

            var createRequest = new CreateRedirectFlowRequest
            {
                Description = "First redirect flow",
                Links       = new CreateRedirectFlowLinks
                {
                    Creditor = creditor.Id
                },
                PrefilledCustomer = new PrefilledCustomer
                {
                    AddressLine1          = "Address Line 1",
                    AddressLine2          = "Address Line 2",
                    AddressLine3          = "Address Line 3",
                    City                  = "London",
                    CompanyName           = "Company Name",
                    CountryCode           = "NZ",
                    DanishIdentityNumber  = "2205506218",
                    Email                 = "*****@*****.**",
                    FamilyName            = "Family Name",
                    GivenName             = "Given Name",
                    Language              = "en",
                    PhoneNumber           = "+44 1234 567890",
                    PostalCode            = "SW1A 1AA",
                    Region                = "Essex",
                    SwedishIdentityNumber = "5302256218",
                },
                Scheme             = Scheme.BecsNz,
                SessionToken       = Guid.NewGuid().ToString(),
                SuccessRedirectUrl = "https://localhost",
            };

            // when
            var createResult = await subject.CreateAsync(createRequest);

            var result = await subject.ForIdAsync(createResult.Item.Id);

            // then
            Assert.That(createResult.Item.ConfirmationUrl, Is.Null);
            Assert.That(createResult.Item.CreatedAt, Is.Not.Null.And.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(createResult.Item.Description, Is.EqualTo(createRequest.Description));
            Assert.That(createResult.Item.Links, Is.Not.Null);
            Assert.That(createResult.Item.Links.Creditor, Is.EqualTo(createRequest.Links.Creditor));
            Assert.That(createResult.Item.Links.Customer, Is.Null);
            Assert.That(createResult.Item.Links.CustomerBankAccount, Is.Null);
            Assert.That(createResult.Item.RedirectUrl, Is.Not.Null);
            Assert.That(createResult.Item.Scheme, Is.EqualTo(createRequest.Scheme));
            Assert.That(createResult.Item.SessionToken, Is.EqualTo(createRequest.SessionToken));
            Assert.That(createResult.Item.SuccessRedirectUrl, Is.EqualTo(createRequest.SuccessRedirectUrl));

            Assert.That(result.Item, Is.Not.Null);
            Assert.That(result.Item.Id, Is.Not.Null.And.EqualTo(createResult.Item.Id));
            Assert.That(result.Item.ConfirmationUrl, Is.Null);
            Assert.That(result.Item.CreatedAt, Is.Not.Null.And.Not.EqualTo(createResult.Item.Id));
            Assert.That(result.Item.Description, Is.EqualTo(createResult.Item.Description));
            Assert.That(result.Item.Links, Is.Not.Null);
            Assert.That(result.Item.Links.Creditor, Is.EqualTo(createResult.Item.Links.Creditor));
            Assert.That(result.Item.Links.Customer, Is.Null);
            Assert.That(result.Item.Links.CustomerBankAccount, Is.Null);
            Assert.That(result.Item.Links.Mandate, Is.Null);
            Assert.That(result.Item.RedirectUrl, Is.Not.Null.And.EqualTo(createResult.Item.RedirectUrl));
            Assert.That(result.Item.Scheme, Is.EqualTo(createResult.Item.Scheme));
            Assert.That(result.Item.SessionToken, Is.EqualTo(createResult.Item.SessionToken));
            Assert.That(result.Item.SuccessRedirectUrl, Is.EqualTo(createResult.Item.SuccessRedirectUrl));
        }