public async Task CompletesRedirectFlow()
        {
            // given
            var creditor = await _resourceFactory.Creditor();

            var redirectFlow = await _resourceFactory.CreateRedirectFlowFor(creditor);

            var subject = new RedirectFlowsClient(_clientConfiguration);

            var request = new CompleteRedirectFlowRequest
            {
                Id           = redirectFlow.Id,
                SessionToken = redirectFlow.SessionToken
            };

            // when
            var completedResult = await subject.CompleteAsync(request);

            var actualCompleted = completedResult.Item;

            var result = await subject.ForIdAsync(redirectFlow.Id);

            var actual = result.Item;

            // then;
            Assert.That(actualCompleted, Is.Not.Null);
            Assert.That(actual, Is.Not.Null);

            Assert.That(actualCompleted.Id, Is.Not.Null.And.EqualTo(redirectFlow.Id));
            Assert.That(actualCompleted.ConfirmationUrl, Is.Not.Null.And.Contains(redirectFlow.RedirectUrl));
            Assert.That(actualCompleted.CreatedAt, Is.Not.Null.And.EqualTo(redirectFlow.CreatedAt));
            Assert.That(actualCompleted.Description, Is.EqualTo(redirectFlow.Description));
            Assert.That(actualCompleted.Links, Is.Not.Null);
            Assert.That(actualCompleted.Links.Creditor, Is.EqualTo(redirectFlow.Links.Creditor));
            Assert.That(actualCompleted.Links.Customer, Is.Not.Null);
            Assert.That(actualCompleted.Links.CustomerBankAccount, Is.Not.Null);
            Assert.That(actualCompleted.Links.Mandate, Is.Not.Null);
            Assert.That(actualCompleted.RedirectUrl, Is.Null);
            Assert.That(actualCompleted.Scheme, Is.EqualTo(redirectFlow.Scheme));
            Assert.That(actualCompleted.SessionToken, Is.EqualTo(redirectFlow.SessionToken));
            Assert.That(actualCompleted.SuccessRedirectUrl, Is.EqualTo(redirectFlow.SuccessRedirectUrl));

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null.And.EqualTo(actualCompleted.Id));
            Assert.That(actual.ConfirmationUrl, Is.EqualTo(actualCompleted.ConfirmationUrl));
            Assert.That(actual.CreatedAt, Is.Not.Null.And.EqualTo(actualCompleted.CreatedAt));
            Assert.That(actual.Description, Is.EqualTo(actualCompleted.Description));
            Assert.That(actual.Links, Is.Not.Null);
            Assert.That(actual.Links.Creditor, Is.EqualTo(actualCompleted.Links.Creditor));
            Assert.That(actual.Links.Customer, Is.EqualTo(actualCompleted.Links.Customer));
            Assert.That(actual.Links.CustomerBankAccount, Is.EqualTo(actualCompleted.Links.CustomerBankAccount));
            Assert.That(actual.Links.Mandate, Is.EqualTo(actualCompleted.Links.Mandate));
            Assert.That(actual.RedirectUrl, Is.Null);
            Assert.That(actual.Scheme, Is.EqualTo(actualCompleted.Scheme));
            Assert.That(actual.SessionToken, Is.EqualTo(actualCompleted.SessionToken));
            Assert.That(actual.SuccessRedirectUrl, Is.EqualTo(actualCompleted.SuccessRedirectUrl));
        }
        public void CompleteRedirectFlowRequestIsNullThrows()
        {
            // given
            var subject = new RedirectFlowsClient(_clientConfiguration);

            CompleteRedirectFlowRequest request = null;

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

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

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
        public async Task CallsCompleteRedirectFlowEndpointUsingRequest()
        {
            // given
            var subject = new RedirectFlowsClient(_clientConfiguration);

            var request = new CompleteRedirectFlowRequest
            {
                Id           = "RE12345678",
                SessionToken = "SE12345678"
            };

            // when
            await subject.CompleteAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/redirect_flows/RE12345678/actions/complete")
            .WithVerb(HttpMethod.Post);
        }