|
| 1 | +namespace StripeTests |
| 2 | +{ |
| 3 | + using System.Collections.Generic; |
| 4 | + using System.Net.Http; |
| 5 | + using System.Threading.Tasks; |
| 6 | + |
| 7 | + using Stripe; |
| 8 | + using Xunit; |
| 9 | + |
| 10 | + public class WebhookEndpointServiceTest : BaseStripeTest |
| 11 | + { |
| 12 | + private const string WebhookEndpointId = "we_123"; |
| 13 | + |
| 14 | + private WebhookEndpointService service; |
| 15 | + private WebhookEndpointCreateOptions createOptions; |
| 16 | + private WebhookEndpointUpdateOptions updateOptions; |
| 17 | + private WebhookEndpointListOptions listOptions; |
| 18 | + |
| 19 | + public WebhookEndpointServiceTest() |
| 20 | + { |
| 21 | + this.service = new WebhookEndpointService(); |
| 22 | + |
| 23 | + this.createOptions = new WebhookEndpointCreateOptions() |
| 24 | + { |
| 25 | + EnabledEvents = new string[] |
| 26 | + { |
| 27 | + "*", |
| 28 | + }, |
| 29 | + Url = "https://stripe.com", |
| 30 | + }; |
| 31 | + |
| 32 | + this.updateOptions = new WebhookEndpointUpdateOptions() |
| 33 | + { |
| 34 | + EnabledEvents = new string[] |
| 35 | + { |
| 36 | + "*", |
| 37 | + }, |
| 38 | + }; |
| 39 | + |
| 40 | + this.listOptions = new WebhookEndpointListOptions() |
| 41 | + { |
| 42 | + Limit = 1, |
| 43 | + }; |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void Create() |
| 48 | + { |
| 49 | + var endpoint = this.service.Create(this.createOptions); |
| 50 | + this.AssertRequest(HttpMethod.Post, "/v1/webhook_endpoints"); |
| 51 | + Assert.NotNull(endpoint); |
| 52 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + public async Task CreateAsync() |
| 57 | + { |
| 58 | + var endpoint = await this.service.CreateAsync(this.createOptions); |
| 59 | + this.AssertRequest(HttpMethod.Post, "/v1/webhook_endpoints"); |
| 60 | + Assert.NotNull(endpoint); |
| 61 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void Delete() |
| 66 | + { |
| 67 | + var deleted = this.service.Delete(WebhookEndpointId); |
| 68 | + this.AssertRequest(HttpMethod.Delete, "/v1/webhook_endpoints/we_123"); |
| 69 | + Assert.NotNull(deleted); |
| 70 | + } |
| 71 | + |
| 72 | + [Fact] |
| 73 | + public async Task DeleteAsync() |
| 74 | + { |
| 75 | + var deleted = await this.service.DeleteAsync(WebhookEndpointId); |
| 76 | + this.AssertRequest(HttpMethod.Delete, "/v1/webhook_endpoints/we_123"); |
| 77 | + Assert.NotNull(deleted); |
| 78 | + } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + public void Get() |
| 82 | + { |
| 83 | + var endpoint = this.service.Get(WebhookEndpointId); |
| 84 | + this.AssertRequest(HttpMethod.Get, "/v1/webhook_endpoints/we_123"); |
| 85 | + Assert.NotNull(endpoint); |
| 86 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 87 | + } |
| 88 | + |
| 89 | + [Fact] |
| 90 | + public async Task GetAsync() |
| 91 | + { |
| 92 | + var endpoint = await this.service.GetAsync(WebhookEndpointId); |
| 93 | + this.AssertRequest(HttpMethod.Get, "/v1/webhook_endpoints/we_123"); |
| 94 | + Assert.NotNull(endpoint); |
| 95 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 96 | + } |
| 97 | + |
| 98 | + [Fact] |
| 99 | + public void List() |
| 100 | + { |
| 101 | + var endpoints = this.service.List(this.listOptions); |
| 102 | + this.AssertRequest(HttpMethod.Get, "/v1/webhook_endpoints"); |
| 103 | + Assert.NotNull(endpoints); |
| 104 | + Assert.Equal("list", endpoints.Object); |
| 105 | + Assert.Single(endpoints.Data); |
| 106 | + Assert.Equal("webhook_endpoint", endpoints.Data[0].Object); |
| 107 | + } |
| 108 | + |
| 109 | + [Fact] |
| 110 | + public async Task ListAsync() |
| 111 | + { |
| 112 | + var endpoints = await this.service.ListAsync(this.listOptions); |
| 113 | + this.AssertRequest(HttpMethod.Get, "/v1/webhook_endpoints"); |
| 114 | + Assert.NotNull(endpoints); |
| 115 | + Assert.Equal("list", endpoints.Object); |
| 116 | + Assert.Single(endpoints.Data); |
| 117 | + Assert.Equal("webhook_endpoint", endpoints.Data[0].Object); |
| 118 | + } |
| 119 | + |
| 120 | + [Fact] |
| 121 | + public void Update() |
| 122 | + { |
| 123 | + var endpoint = this.service.Update(WebhookEndpointId, this.updateOptions); |
| 124 | + this.AssertRequest(HttpMethod.Post, "/v1/webhook_endpoints/we_123"); |
| 125 | + Assert.NotNull(endpoint); |
| 126 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 127 | + } |
| 128 | + |
| 129 | + [Fact] |
| 130 | + public async Task UpdateAsync() |
| 131 | + { |
| 132 | + var endpoint = await this.service.UpdateAsync(WebhookEndpointId, this.updateOptions); |
| 133 | + this.AssertRequest(HttpMethod.Post, "/v1/webhook_endpoints/we_123"); |
| 134 | + Assert.NotNull(endpoint); |
| 135 | + Assert.Equal("webhook_endpoint", endpoint.Object); |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments