-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
TransactionTests.cs
172 lines (132 loc) · 4.88 KB
/
TransactionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Coinbase.Models;
using FluentAssertions;
using NUnit.Framework;
using static Coinbase.Tests.Examples;
namespace Coinbase.Tests.Endpoints
{
public class TransactionTests : OAuthServerTest
{
[Test]
public async Task can_list()
{
SetupServerPagedResponse(PaginationJson, $"{Transaction2},{Transaction3},{Transaction4},{Transaction5}");
var r = await client.Transactions.ListTransactionsAsync("fff");
var truth = new PagedResponse<Transaction>
{
Pagination = PaginationModel,
Data = new[]
{
Transaction2Model,
Transaction3Model,
Transaction4Model,
Transaction5Model
}
};
truth.Should().BeEquivalentTo(r);
server.ShouldHaveExactCall("https://api.coinbase.com/v2/accounts/fff/transactions")
.WithVerb(HttpMethod.Get);
}
[Test]
public async Task can_get()
{
SetupServerSingleResponse(Transaction5);
var r = await client.Transactions.GetTransactionAsync("fff", "uuu");
var truth = new Response<Transaction>
{
Data = Transaction5Model
};
truth.Should().BeEquivalentTo(r);
server.ShouldHaveExactCall($"https://api.coinbase.com/v2/accounts/fff/transactions/uuu")
.WithVerb(HttpMethod.Get);
}
[Test]
public async Task can_send()
{
SetupServerSingleResponse(Transaction6);
var createTx = new CreateTransaction
{
Type = "send",
To = "1AUJ8z5RuHRTqD1eikyfUUetzGmdWLGkpT",
Amount = 0.1m,
Currency = "BTC",
Idem = "9316dd16-0c05"
};
var r = await client.Transactions.SendMoneyAsync("fff", createTx );
var truth = new Response<Transaction>
{
Data = Transaction6Model
};
truth.Should().BeEquivalentTo(r);
server.ShouldHaveRequestBody(
"{\"type\":\"send\",\"to\":\"1AUJ8z5RuHRTqD1eikyfUUetzGmdWLGkpT\",\"amount\":0.1,\"currency\":\"BTC\",\"skip_notifications\":false,\"idem\":\"9316dd16-0c05\",\"to_financial_institution\":false}");
server.ShouldHaveExactCall($"https://api.coinbase.com/v2/accounts/fff/transactions")
.WithVerb(HttpMethod.Post);
}
[Test]
public async Task can_transfer()
{
SetupServerSingleResponse(Transaction7);
var createTx = new CreateTransfer
{
Type = "send",
To = "1AUJ8z5RuHRTqD1eikyfUUetzGmdWLGkpT",
Amount = 0.1m,
Currency = "BTC"
};
var r = await client.Transactions.TransferMoneyAsync("fff", createTx);
var truth = new Response<Transaction>
{
Data = Transaction7Model
};
truth.Should().BeEquivalentTo(r);
server.ShouldHaveRequestBody(
@"{""type"":""send"",""to"":""1AUJ8z5RuHRTqD1eikyfUUetzGmdWLGkpT"",""amount"":0.1,""currency"":""BTC""}");
server.ShouldHaveExactCall($"https://api.coinbase.com/v2/accounts/fff/transactions")
.WithVerb(HttpMethod.Post);
}
[Test]
public async Task can_request()
{
SetupServerSingleResponse(Transaction7);
var create = new RequestMoney
{
Type = "request",
To = "email@example.com",
Amount = 0.1m,
Currency = "BTC"
};
var r = await client.Transactions.RequestMoneyAsync("fff", create);
var truth = new Response<Transaction>
{
Data = Transaction7Model
};
truth.Should().BeEquivalentTo(r);
server.ShouldHaveExactCall("https://api.coinbase.com/v2/accounts/fff/transactions")
.WithVerb(HttpMethod.Post);
}
[Test]
public async Task can_compelte()
{
var r = await client.Transactions.CompleteRequestMoneyAsync("fff", "uuu");
server.ShouldHaveExactCall("https://api.coinbase.com/v2/accounts/fff/transactions/uuu/complete")
.WithVerb(HttpMethod.Post);
}
[Test]
public async Task can_resend()
{
var r = await client.Transactions.ResendRequestMoneyAsync("fff", "uuu");
server.ShouldHaveExactCall("https://api.coinbase.com/v2/accounts/fff/transactions/uuu/resend")
.WithVerb(HttpMethod.Post);
}
[Test]
public async Task can_cancel()
{
var r = await client.Transactions.CancelRequestMoneyAsync("fff", "uuu");
server.ShouldHaveExactCall("https://api.coinbase.com/v2/accounts/fff/transactions/uuu")
.WithVerb(HttpMethod.Delete);
}
}
}