示例#1
0
        public void CreateRefundRequestIsNullThrows()
        {
            // given
            var subject = new RefundsClient(_clientConfiguration);

            CreateRefundRequest request = null;

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

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

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
示例#2
0
        public async Task CallsCreateRefundEndpoint()
        {
            // given
            var subject = new RefundsClient(_clientConfiguration);

            var request = new CreateRefundRequest
            {
                IdempotencyKey = Guid.NewGuid().ToString()
            };

            // when
            await subject.CreateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/refunds")
            .WithHeader("Idempotency-Key")
            .WithVerb(HttpMethod.Post);
        }
        public async Task CreatesRefund()
        {
            // given
            var payment = await _resourceFactory.CreatePaymentFor(_mandate);

            var request = new CreateRefundRequest
            {
                Amount = 100,
                Links  = new CreateRefundLinks {
                    Payment = payment.Id
                },
                Metadata = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                Reference = "RF123456",
                TotalAmountConfirmation = 100
            };

            var subject = new RefundsClient(_clientConfiguration);

            // when
            var result = await subject.CreateAsync(request);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null);
            Assert.That(actual.Amount, Is.EqualTo(request.Amount));
            Assert.That(actual.CreatedAt, Is.Not.Null.And.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(actual.Currency, Is.EqualTo(payment.Currency));
            Assert.That(actual.Links, Is.Not.Null);
            Assert.That(actual.Links.Payment, Is.EqualTo(request.Links.Payment));
            Assert.That(actual.Metadata, Is.EqualTo(request.Metadata));
            Assert.That(actual.Reference, Is.EqualTo(request.Reference));
        }
        public async Task CreateRefundRequestIsInvalidThrows()
        {
            // given
            var payment = await _resourceFactory.CreatePaymentFor(_mandate);

            var request = new CreateRefundRequest
            {
                Amount         = 100,
                IdempotencyKey = Guid.NewGuid().ToString(),
                Links          = new CreateRefundLinks {
                    Payment = payment.Id
                },
                Metadata = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                TotalAmountConfirmation = 100
            };

            var subject = new RefundsClient(_clientConfiguration);

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

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

            Assert.That(ex.Code, Is.EqualTo((int)HttpStatusCode.UnprocessableEntity));
            Assert.That(ex.DocumentationUrl, Is.Not.Null);
            Assert.That(ex.Errors?.Any(), Is.True);
            Assert.That(ex.Message, Is.Not.Null.And.Not.Empty);
            Assert.That(ex.RawResponse, Is.Not.Null.And.Not.Empty);
            Assert.That(ex.RequestId, Is.Not.Null.And.Not.Empty);
        }