public async Task CanUpdateCustomer() { // If: We retrieve the customer list var response = await CustomerClient.GetCustomerListAsync(); if (response.Items.Count == 0) { Assert.Empty(response.Items); //No customers found. Unable to test deleting customers return; } // When: We update one of the customers in the list var customerIdToUpdate = response.Items.First().Id; var newCustomerName = DateTime.Now.ToShortTimeString(); var updateParameters = new CustomerRequest() { Name = newCustomerName }; var result = await CustomerClient.UpdateCustomerAsync(customerIdToUpdate, updateParameters); // Then: Make sure the new name is updated Assert.NotNull(result); Assert.Equal(newCustomerName, result.Name); }
public async Task CanRetrieveCustomerList() { // When: Retrieve customer list with default settings ListResponse <CustomerResponse> response = await CustomerClient.GetCustomerListAsync(); // Then Assert.IsNotNull(response); Assert.IsNotNull(response.Items); }
public async Task ListCustomersNeverReturnsMoreCustomersThenTheNumberOfRequestedCustomers() { // If: Number of customers requested is 5 int numberOfCustomers = 5; // When: Retrieve 5 customers ListResponse <CustomerResponse> response = await CustomerClient.GetCustomerListAsync(null, numberOfCustomers); // Then Assert.IsTrue(response.Items.Count <= numberOfCustomers); }
public async Task CanRetrieveMandateList() { // We can only test this if there are customers ListResponse <CustomerResponse> customers = await CustomerClient.GetCustomerListAsync(); if (customers.Count > 0) { // When: Retrieve mandate list with default settings ListResponse <MandateResponse> response = await MandateClient.GetMandateListAsync(customers.Items.First().Id); // Then Assert.IsNotNull(response); Assert.IsNotNull(response.Items); } }
public async Task <string> GetFirstCustomerWithValidMandate() { ListResponse <CustomerResponse> customers = await CustomerClient.GetCustomerListAsync(); foreach (CustomerResponse customer in customers.Items) { ListResponse <MandateResponse> mandates = await MandateClient.GetMandateListAsync(customer.Id); if (mandates.Items.Any(x => x.Status == MandateStatus.Valid)) { return(customer.Id); } } Assert.Inconclusive("No customers with valid mandate found. Unable to test subscription API"); return(null); }
public async Task ListMandatesNeverReturnsMoreCustomersThenTheNumberOfRequestedMandates() { // We can only test this if there are customers ListResponse <CustomerResponse> customers = await CustomerClient.GetCustomerListAsync(); if (customers.Count > 0) { // If: Number of customers requested is 5 int numberOfMandates = 5; // When: Retrieve 5 mandates ListResponse <MandateResponse> response = await MandateClient.GetMandateListAsync(customers.Items.First().Id, null, numberOfMandates); // Then Assert.IsTrue(response.Items.Count <= numberOfMandates); } }
/// <summary> /// Gets the first customer with valid mandate. /// </summary> /// <returns>System.String.</returns> /// <autogeneratedoc /> public async Task <string> GetFirstCustomerWithValidMandate() { var customers = await CustomerClient.GetCustomerListAsync(); foreach (var customer in customers.Items) { var mandates = await MandateClient.GetMandateListAsync(customer.Id); if (mandates.Items.Any(x => x.Status == MandateStatus.Valid)) { return(customer.Id); } } Assert.Empty(customers.Items); //No customers with valid mandate found. Unable to test subscription API return(null); }
public async Task CanDeleteCustomer() { // If: We retrieve the customer list ListResponse <CustomerResponse> response = await CustomerClient.GetCustomerListAsync(); if (response.Items.Count == 0) { Assert.Inconclusive("No customers found. Unable to test deleting customers"); } // When: We delete one of the customers in the list string customerIdToDelete = response.Items.First().Id; await CustomerClient.DeleteCustomerAsync(customerIdToDelete); // Then: Make sure its deleted AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() => CustomerClient.GetCustomerAsync(customerIdToDelete).Wait()); MollieApiException mollieApiException = aggregateException.InnerExceptions.FirstOrDefault(x => x.GetType() == typeof(MollieApiException)) as MollieApiException; Assert.AreEqual((int)HttpStatusCode.Gone, mollieApiException.Details.Status); }
public async Task CanDeleteCustomer() { // If: We retrieve the customer list var response = await CustomerClient.GetCustomerListAsync(); if (response.Items.Count == 0) { Assert.Empty(response.Items); //No customers found. Unable to test deleting customers return; } // When: We delete one of the customers in the list var customerIdToDelete = response.Items.First().Id; await CustomerClient.DeleteCustomerAsync(customerIdToDelete); // Then: Make sure its deleted var mollieApiException = await Assert.ThrowsAsync <MollieApiException>(() => CustomerClient.GetCustomerAsync(customerIdToDelete)); Assert.Equal((int)HttpStatusCode.Gone, mollieApiException.Details.Status); }
public async Task CanCreateMandate() { // We can only test this if there are customers ListResponse <CustomerResponse> customers = await CustomerClient.GetCustomerListAsync(); if (customers.Count > 0) { // If: We create a new mandate request MandateRequest mandateRequest = new MandateRequest() { ConsumerAccount = "NL26ABNA0516682814", ConsumerName = "John Doe" }; // When: We send the mandate request MandateResponse mandateResponse = await MandateClient.CreateMandateAsync(customers.Items.First().Id, mandateRequest); // Then: Make sure we created a new mandate Assert.AreEqual(mandateRequest.ConsumerAccount, mandateResponse.Details.ConsumerAccount); Assert.AreEqual(mandateRequest.ConsumerName, mandateResponse.Details.ConsumerName); } }
//[TestMethod] //public async Task PaymentWithDifferentHttpInstance() { // // If: We create a PaymentClient with our own HttpClient instance // HttpClient myHttpClientInstance = new HttpClient(); // PaymentClient paymentClient = new PaymentClient(new ClientService(ApiTestKey, myHttpClientInstance)); // PaymentRequest paymentRequest = new PaymentRequest() { // Amount = new Amount(Currency.EUR, "100.00"), // Description = "Description", // RedirectUrl = DefaultRedirectUrl // }; // // When: I create a new payment // PaymentResponse result = await paymentClient.CreatePaymentAsync(paymentRequest); // // Then: It should still work... lol // Assert.IsNotNull(result); // Assert.AreEqual(paymentRequest.Amount.Currency, result.Amount.Currency); // Assert.AreEqual(paymentRequest.Amount.Value, result.Amount.Value); // Assert.AreEqual(paymentRequest.Description, result.Description); // Assert.AreEqual(paymentRequest.RedirectUrl, result.RedirectUrl); //} private async Task <MandateResponse> GetFirstValidMandate() { ListResponse <CustomerResponse> customers = await CustomerClient.GetCustomerListAsync(); if (!customers.Items.Any()) { Assert.Inconclusive("No customers found. Unable to test recurring payment tests"); } foreach (CustomerResponse customer in customers.Items) { ListResponse <MandateResponse> customerMandates = await MandateClient.GetMandateListAsync(customer.Id); MandateResponse firstValidMandate = customerMandates.Items.FirstOrDefault(x => x.Status == MandateStatus.Valid); if (firstValidMandate != null) { return(firstValidMandate); } } Assert.Inconclusive("No mandates found. Unable to test recurring payments"); return(null); }
public async Task CanUpdateCustomer() { // If: We retrieve the customer list ListResponse <CustomerResponse> response = await CustomerClient.GetCustomerListAsync(); if (response.Items.Count == 0) { Assert.Inconclusive("No customers found. Unable to test updating customers"); } // When: We update one of the customers in the list string customerIdToUpdate = response.Items.First().Id; string newCustomerName = DateTime.Now.ToShortTimeString(); CustomerRequest updateParameters = new CustomerRequest() { Name = newCustomerName }; CustomerResponse result = await CustomerClient.UpdateCustomerAsync(customerIdToUpdate, updateParameters); // Then: Make sure the new name is updated Assert.IsNotNull(result); Assert.AreEqual(newCustomerName, result.Name); }
//[Fact] //public async Task PaymentWithDifferentHttpInstance() { // // If: We create a PaymentClient with our own HttpClient instance // HttpClient myHttpClientInstance = new HttpClient(); // PaymentClient paymentClient = new PaymentClient(new ClientService(ApiTestKey, myHttpClientInstance)); // PaymentRequest paymentRequest = new PaymentRequest() { // Amount = new Amount(Currency.EUR, "100.00"), // Description = "Description", // RedirectUrl = DefaultRedirectUrl // }; // // When: I create a new payment // PaymentResponse result = await paymentClient.CreatePaymentAsync(paymentRequest); // // Then: It should still work... lol // Assert.NotNull(result); // Assert.Equal(paymentRequest.Amount.Currency, result.Amount.Currency); // Assert.Equal(paymentRequest.Amount.Value, result.Amount.Value); // Assert.Equal(paymentRequest.Description, result.Description); // Assert.Equal(paymentRequest.RedirectUrl, result.RedirectUrl); //} /// <summary> /// Gets the first valid mandate. /// </summary> /// <returns>MandateResponse.</returns> /// <autogeneratedoc /> private async Task <MandateResponse> GetFirstValidMandate() { var customers = await CustomerClient.GetCustomerListAsync(); if (!customers.Items.Any()) { Assert.Empty(customers.Items); //No customers found. Unable to test recurring payment tests return(null); } foreach (var customer in customers.Items) { var customerMandates = await MandateClient.GetMandateListAsync(customer.Id); var firstValidMandate = customerMandates.Items.FirstOrDefault(x => x.Status == MandateStatus.Valid); if (firstValidMandate != null) { return(firstValidMandate); } } // No mandates found. Unable to test recurring payments return(null); }