Skip to content

Commit c5bdcc6

Browse files
committed
chore: request unit test coverage
1 parent ee8a227 commit c5bdcc6

4 files changed

Lines changed: 562 additions & 2 deletions

File tree

StellarDotnetSdk.Tests/Requests/EffectsRequestBuilderTest.cs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Threading.Tasks;
34
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using StellarDotnetSdk.Assets;
6+
using StellarDotnetSdk.LiquidityPool;
47
using StellarDotnetSdk.Requests;
58
using StellarDotnetSdk.Responses.Effects;
69
using StellarDotnetSdk.Tests.Responses.Effects;
10+
using XDR = StellarDotnetSdk.Xdr;
711

812
namespace StellarDotnetSdk.Tests.Requests;
913

@@ -168,4 +172,80 @@ public async Task Stream_WithCursor_SetsLastEventIdAndCursorInUri()
168172
Assert.AreEqual(eventId, streamableTest.LastEventId);
169173
Assert.AreEqual("https://horizon-testnet.stellar.org/test?cursor=65571265847297-1", streamableTest.Uri);
170174
}
175+
176+
/// <summary>
177+
/// Verifies that EffectsRequestBuilder.ForAccount throws ArgumentNullException when account is null.
178+
/// </summary>
179+
[TestMethod]
180+
[ExpectedException(typeof(ArgumentNullException))]
181+
public void ForAccount_WithNullAccount_ThrowsArgumentNullException()
182+
{
183+
// Arrange
184+
using var server = new Server("https://horizon-testnet.stellar.org");
185+
186+
// Act & Assert
187+
_ = server.Effects.ForAccount(null!);
188+
}
189+
190+
/// <summary>
191+
/// Verifies that EffectsRequestBuilder.ForTransaction throws ArgumentNullException when transactionId is null.
192+
/// </summary>
193+
[TestMethod]
194+
[ExpectedException(typeof(ArgumentNullException))]
195+
public void ForTransaction_WithNullTransactionId_ThrowsArgumentNullException()
196+
{
197+
// Arrange
198+
using var server = new Server("https://horizon-testnet.stellar.org");
199+
200+
// Act & Assert
201+
_ = server.Effects.ForTransaction(null!);
202+
}
203+
204+
/// <summary>
205+
/// Verifies that EffectsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool effects with LiquidityPoolId.
206+
/// </summary>
207+
[TestMethod]
208+
public void ForLiquidityPool_WithLiquidityPoolId_BuildsCorrectUri()
209+
{
210+
// Arrange
211+
using var server = new Server("https://horizon-testnet.stellar.org");
212+
var assetA = Asset.Create("native");
213+
var assetB = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3");
214+
var liquidityPoolId = new LiquidityPoolId(
215+
XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB,
216+
LiquidityPoolParameters.Fee);
217+
218+
// Act
219+
var uri = server.Effects
220+
.ForLiquidityPool(liquidityPoolId)
221+
.BuildUri();
222+
223+
// Assert
224+
Assert.AreEqual(
225+
$"https://horizon-testnet.stellar.org/liquidity_pools/{liquidityPoolId}/effects",
226+
uri.ToString());
227+
}
228+
229+
/// <summary>
230+
/// Verifies that EffectsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool effects with string ID.
231+
/// </summary>
232+
[TestMethod]
233+
public void ForLiquidityPool_WithStringId_BuildsCorrectUri()
234+
{
235+
// Arrange
236+
using var server = new Server("https://horizon-testnet.stellar.org");
237+
const string poolId = "cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d";
238+
239+
// Act
240+
var uri = server.Effects
241+
.ForLiquidityPool(poolId)
242+
.Limit(50)
243+
.Order(OrderDirection.ASC)
244+
.BuildUri();
245+
246+
// Assert
247+
Assert.AreEqual(
248+
$"https://horizon-testnet.stellar.org/liquidity_pools/{poolId}/effects?limit=50&order=asc",
249+
uri.ToString());
250+
}
171251
}

StellarDotnetSdk.Tests/Requests/OperationsRequestBuilderTest.cs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,193 @@ public async Task Stream_WithValidJson_StreamsOperationEvents()
208208
CreateAccountOperationResponseTest.AssertCreateAccountOperationData);
209209
await streamableTest.Run();
210210
}
211+
212+
/// <summary>
213+
/// Verifies that OperationsRequestBuilder.Operation correctly retrieves and deserializes operation data from URI.
214+
/// </summary>
215+
[TestMethod]
216+
public async Task Operation_WithValidUri_ReturnsDeserializedOperation()
217+
{
218+
// Arrange
219+
using var server = await Utils.CreateTestServerWithJson("Responses/Operations/createAccount.json");
220+
var uri = new Uri("https://horizon-testnet.stellar.org/operations/100000");
221+
222+
// Act
223+
var operation = await server.Operations.Operation(uri);
224+
225+
// Assert
226+
CreateAccountOperationResponseTest.AssertCreateAccountOperationData(operation);
227+
}
228+
229+
/// <summary>
230+
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentException when account ID is invalid.
231+
/// </summary>
232+
[TestMethod]
233+
[ExpectedException(typeof(ArgumentException))]
234+
public void ForAccount_WithInvalidAccountId_ThrowsArgumentException()
235+
{
236+
// Arrange
237+
using var server = Utils.CreateTestServerWithContent("");
238+
239+
// Act & Assert
240+
_ = server.Operations.ForAccount("INVALID_ACCOUNT_ID");
241+
}
242+
243+
/// <summary>
244+
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentException when account is null.
245+
/// </summary>
246+
[TestMethod]
247+
[ExpectedException(typeof(ArgumentNullException))]
248+
public void ForAccount_WithNullAccount_ThrowsArgumentException()
249+
{
250+
// Arrange
251+
using var server = Utils.CreateTestServerWithContent("");
252+
253+
// Act & Assert
254+
_ = server.Operations.ForAccount(null!);
255+
}
256+
257+
/// <summary>
258+
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentException when account is empty.
259+
/// </summary>
260+
[TestMethod]
261+
[ExpectedException(typeof(ArgumentException))]
262+
public void ForAccount_WithEmptyAccount_ThrowsArgumentException()
263+
{
264+
// Arrange
265+
using var server = Utils.CreateTestServerWithContent("");
266+
267+
// Act & Assert
268+
_ = server.Operations.ForAccount("");
269+
}
270+
271+
/// <summary>
272+
/// Verifies that OperationsRequestBuilder.ForClaimableBalance throws ArgumentException when balance ID is null.
273+
/// </summary>
274+
[TestMethod]
275+
[ExpectedException(typeof(ArgumentNullException))]
276+
public void ForClaimableBalance_WithNullBalanceId_ThrowsArgumentException()
277+
{
278+
// Arrange
279+
using var server = Utils.CreateTestServerWithContent("");
280+
281+
// Act & Assert
282+
_ = server.Operations.ForClaimableBalance(null!);
283+
}
284+
285+
/// <summary>
286+
/// Verifies that OperationsRequestBuilder.ForClaimableBalance throws ArgumentException when balance ID format is invalid.
287+
/// </summary>
288+
[TestMethod]
289+
[ExpectedException(typeof(ArgumentException))]
290+
public void ForClaimableBalance_WithInvalidFormat_ThrowsArgumentException()
291+
{
292+
// Arrange
293+
using var server = Utils.CreateTestServerWithContent("");
294+
295+
// Act & Assert
296+
_ = server.Operations.ForClaimableBalance("invalid_format");
297+
}
298+
299+
/// <summary>
300+
/// Verifies that OperationsRequestBuilder.ForTransaction throws ArgumentException when transaction ID is null.
301+
/// </summary>
302+
[TestMethod]
303+
[ExpectedException(typeof(ArgumentNullException))]
304+
public void ForTransaction_WithNullTransactionId_ThrowsArgumentException()
305+
{
306+
// Arrange
307+
using var server = Utils.CreateTestServerWithContent("");
308+
309+
// Act & Assert
310+
_ = server.Operations.ForTransaction(null!);
311+
}
312+
313+
/// <summary>
314+
/// Verifies that OperationsRequestBuilder.ForTransaction throws ArgumentException when transaction ID is empty.
315+
/// </summary>
316+
[TestMethod]
317+
[ExpectedException(typeof(ArgumentException))]
318+
public void ForTransaction_WithEmptyTransactionId_ThrowsArgumentException()
319+
{
320+
// Arrange
321+
using var server = Utils.CreateTestServerWithContent("");
322+
323+
// Act & Assert
324+
_ = server.Operations.ForTransaction("");
325+
}
326+
327+
/// <summary>
328+
/// Verifies that OperationsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool operations.
329+
/// </summary>
330+
[TestMethod]
331+
public void ForLiquidityPool_WithValidPoolId_BuildsCorrectUri()
332+
{
333+
// Arrange
334+
using var server = Utils.CreateTestServerWithContent("");
335+
const string poolId = "cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d";
336+
337+
// Act
338+
var uri = server.Operations
339+
.ForLiquidityPool(poolId)
340+
.Limit(50)
341+
.Order(OrderDirection.ASC)
342+
.BuildUri();
343+
344+
// Assert
345+
Assert.AreEqual(
346+
$"https://horizon-testnet.stellar.org/liquidity_pools/{poolId}/operations?limit=50&order=asc",
347+
uri.ToString());
348+
}
349+
350+
/// <summary>
351+
/// Verifies that OperationsRequestBuilder.ForLiquidityPool throws ArgumentException when pool ID is null.
352+
/// </summary>
353+
[TestMethod]
354+
[ExpectedException(typeof(ArgumentNullException))]
355+
public void ForLiquidityPool_WithNullPoolId_ThrowsArgumentException()
356+
{
357+
// Arrange
358+
using var server = Utils.CreateTestServerWithContent("");
359+
360+
// Act & Assert
361+
_ = server.Operations.ForLiquidityPool(null!);
362+
}
363+
364+
/// <summary>
365+
/// Verifies that OperationsRequestBuilder.ForLiquidityPool throws ArgumentException when pool ID is empty.
366+
/// </summary>
367+
[TestMethod]
368+
[ExpectedException(typeof(ArgumentException))]
369+
public void ForLiquidityPool_WithEmptyPoolId_ThrowsArgumentException()
370+
{
371+
// Arrange
372+
using var server = Utils.CreateTestServerWithContent("");
373+
374+
// Act & Assert
375+
_ = server.Operations.ForLiquidityPool("");
376+
}
377+
378+
/// <summary>
379+
/// Verifies that OperationsRequestBuilder.IncludeFailed correctly adds include_failed parameter with false value.
380+
/// </summary>
381+
[TestMethod]
382+
public void IncludeFailed_WithFalseValue_AddsIncludeFailedParameter()
383+
{
384+
// Arrange
385+
using var server = Utils.CreateTestServerWithContent("");
386+
387+
// Act
388+
var uri = server.Operations
389+
.ForLedger(200000000000L)
390+
.IncludeFailed(false)
391+
.Limit(50)
392+
.Order(OrderDirection.ASC)
393+
.BuildUri();
394+
395+
// Assert
396+
Assert.AreEqual(
397+
"https://horizon-testnet.stellar.org/ledgers/200000000000/operations?include_failed=false&limit=50&order=asc",
398+
uri.ToString());
399+
}
211400
}

0 commit comments

Comments
 (0)