internal async Task <Mandate> CreateMandateFor( Creditor creditor, Customer customer, CustomerBankAccount customerBankAccount) { var request = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = creditor.Id, CustomerBankAccount = customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Scheme = Scheme.Bacs }; var mandatesClient = new MandatesClient(_clientConfiguration); return((await mandatesClient.CreateAsync(request)).Item); }
public async Task CreatesConflictingMandate() { // given var request = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = _creditor.Id, CustomerBankAccount = _customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Scheme = Scheme.Bacs, }; var subject = new MandatesClient(_clientConfiguration); // when await subject.CreateAsync(request); var result = await subject.CreateAsync(request); // then Assert.That(result.Item, Is.Not.Null); Assert.That(result.Item.Id, Is.Not.Null); Assert.That(result.Item.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset))); Assert.That(result.Item.Links.Creditor, Is.EqualTo(_creditor.Id)); Assert.That(result.Item.Links.CustomerBankAccount, Is.EqualTo(_customerBankAccount.Id)); Assert.That(result.Item.Metadata, Is.EqualTo(request.Metadata)); Assert.That(result.Item.NextPossibleChargeDate, Is.Not.Null.And.Not.EqualTo(default(DateTime))); Assert.That(result.Item.Scheme, Is.EqualTo(request.Scheme)); Assert.That(result.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); }
public void CreateMandateRequestIsNullThrows() { // given var subject = new MandatesClient(_clientConfiguration); CreateMandateRequest request = null; // when AsyncTestDelegate test = () => subject.CreateAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentNullException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request))); }
public async Task CallsCreateMandateEndpoint() { // given var subject = new MandatesClient(_clientConfiguration); var request = new CreateMandateRequest { IdempotencyKey = Guid.NewGuid().ToString() }; // when await subject.CreateAsync(request); // then _httpTest .ShouldHaveCalled("https://api.gocardless.com/mandates") .WithHeader("Idempotency-Key") .WithVerb(HttpMethod.Post); }
public async Task CreatesCancelsAndReinstatesMandate() { // given var createRequest = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = _creditor.Id, CustomerBankAccount = _customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Reference = DateTime.Now.ToString("yyyyMMddhhmmss"), Scheme = Scheme.Bacs }; var subject = new MandatesClient(_clientConfiguration); // when var creationResult = await subject.CreateAsync(createRequest); var cancelRequest = new CancelMandateRequest { Id = creationResult.Item.Id, Metadata = new Dictionary <string, string> { ["Key4"] = "Value4", ["Key5"] = "Value5", ["Key6"] = "Value6", }, }; var cancellationResult = await subject.CancelAsync(cancelRequest); var reinstateRequest = new ReinstateMandateRequest { Id = creationResult.Item.Id, Metadata = new Dictionary <string, string> { ["Key7"] = "Value7", ["Key8"] = "Value8", ["Key9"] = "Value9", }, }; var reinstateResult = (await subject.ReinstateAsync(reinstateRequest)); // then Assert.That(creationResult.Item, Is.Not.Null); Assert.That(creationResult.Item.Id, Is.Not.Null); Assert.That(creationResult.Item.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset))); Assert.That(creationResult.Item.Links.Creditor, Is.EqualTo(_creditor.Id)); Assert.That(creationResult.Item.Links.CustomerBankAccount, Is.EqualTo(_customerBankAccount.Id)); Assert.That(creationResult.Item.Metadata, Is.EqualTo(createRequest.Metadata)); Assert.That(creationResult.Item.NextPossibleChargeDate, Is.Not.Null.And.Not.EqualTo(default(DateTime))); Assert.That(creationResult.Item.Reference, Is.Not.Null.And.EqualTo(createRequest.Reference)); Assert.That(creationResult.Item.Scheme, Is.EqualTo(createRequest.Scheme)); Assert.That(creationResult.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); Assert.That(cancellationResult.Item.Status, Is.EqualTo(MandateStatus.Cancelled)); Assert.That(reinstateResult.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); }