Skip to content

Commit fed62bb

Browse files
feat(client): add ToString and Equals methods
1 parent 3f5afb6 commit fed62bb

27 files changed

Lines changed: 342 additions & 1 deletion

src/Orb/Core/ClientOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Orb.Core;
77
/// <summary>
88
/// A class representing the SDK client configuration.
99
/// </summary>
10-
public struct ClientOptions()
10+
public record struct ClientOptions()
1111
{
1212
/// <summary>
1313
/// The default value used for <see cref="MaxRetries"/>.

src/Orb/Core/HttpRequest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,19 @@ public sealed class HttpRequest<P>
88
public required HttpMethod Method { get; init; }
99

1010
public required P Params { get; init; }
11+
12+
public override string ToString() =>
13+
string.Format("Method: {0}\n{1}", this.Method.ToString(), this.Params.ToString());
14+
15+
public override bool Equals(object? obj)
16+
{
17+
if (obj is not HttpRequest<P> other)
18+
{
19+
return false;
20+
}
21+
22+
return this.Method.Equals(other.Method) && this.Params.Equals(other.Params);
23+
}
24+
25+
public override int GetHashCode() => 0;
1126
}

src/Orb/Core/HttpResponse.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ public bool TryGetHeaderValues(
3939
[NotNullWhen(true)] out IEnumerable<string>? values
4040
) => RawMessage.Headers.TryGetValues(name, out values);
4141

42+
public sealed override string ToString() => this.RawMessage.ToString();
43+
44+
public override bool Equals(object? obj)
45+
{
46+
if (obj is not global::Orb.Core.HttpResponse other)
47+
{
48+
return false;
49+
}
50+
51+
return this.RawMessage.Equals(other.RawMessage);
52+
}
53+
54+
public override int GetHashCode() => this.RawMessage.GetHashCode();
55+
4256
public async Task<T> Deserialize<T>(Threading::CancellationToken cancellationToken = default)
4357
{
4458
using var cts = Threading::CancellationTokenSource.CreateLinkedTokenSource(

src/Orb/Models/Alerts/AlertListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -63,4 +64,16 @@ public void Validate()
6364

6465
public override string ToString() =>
6566
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
67+
68+
public override bool Equals(object? obj)
69+
{
70+
if (obj is not AlertListPage other)
71+
{
72+
return false;
73+
}
74+
75+
return Enumerable.SequenceEqual(this.Items, other.Items);
76+
}
77+
78+
public override int GetHashCode() => 0;
6679
}

src/Orb/Models/Coupons/CouponListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -63,4 +64,16 @@ public void Validate()
6364

6465
public override string ToString() =>
6566
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
67+
68+
public override bool Equals(object? obj)
69+
{
70+
if (obj is not CouponListPage other)
71+
{
72+
return false;
73+
}
74+
75+
return Enumerable.SequenceEqual(this.Items, other.Items);
76+
}
77+
78+
public override int GetHashCode() => 0;
6679
}

src/Orb/Models/Coupons/Subscriptions/SubscriptionListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -65,4 +66,16 @@ public void Validate()
6566

6667
public override string ToString() =>
6768
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
69+
70+
public override bool Equals(object? obj)
71+
{
72+
if (obj is not SubscriptionListPage other)
73+
{
74+
return false;
75+
}
76+
77+
return Enumerable.SequenceEqual(this.Items, other.Items);
78+
}
79+
80+
public override int GetHashCode() => 0;
6881
}

src/Orb/Models/CreditNotes/CreditNoteListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -64,4 +65,16 @@ public void Validate()
6465

6566
public override string ToString() =>
6667
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
68+
69+
public override bool Equals(object? obj)
70+
{
71+
if (obj is not CreditNoteListPage other)
72+
{
73+
return false;
74+
}
75+
76+
return Enumerable.SequenceEqual(this.Items, other.Items);
77+
}
78+
79+
public override int GetHashCode() => 0;
6780
}

src/Orb/Models/Customers/BalanceTransactions/BalanceTransactionListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -66,4 +67,16 @@ public void Validate()
6667

6768
public override string ToString() =>
6869
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
70+
71+
public override bool Equals(object? obj)
72+
{
73+
if (obj is not BalanceTransactionListPage other)
74+
{
75+
return false;
76+
}
77+
78+
return Enumerable.SequenceEqual(this.Items, other.Items);
79+
}
80+
81+
public override int GetHashCode() => 0;
6982
}

src/Orb/Models/Customers/Credits/CreditListByExternalIDPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -66,4 +67,16 @@ public void Validate()
6667

6768
public override string ToString() =>
6869
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
70+
71+
public override bool Equals(object? obj)
72+
{
73+
if (obj is not CreditListByExternalIDPage other)
74+
{
75+
return false;
76+
}
77+
78+
return Enumerable.SequenceEqual(this.Items, other.Items);
79+
}
80+
81+
public override int GetHashCode() => 0;
6982
}

src/Orb/Models/Customers/Credits/CreditListPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.Json;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -64,4 +65,16 @@ public void Validate()
6465

6566
public override string ToString() =>
6667
JsonSerializer.Serialize(this.Items, ModelBase.ToStringSerializerOptions);
68+
69+
public override bool Equals(object? obj)
70+
{
71+
if (obj is not CreditListPage other)
72+
{
73+
return false;
74+
}
75+
76+
return Enumerable.SequenceEqual(this.Items, other.Items);
77+
}
78+
79+
public override int GetHashCode() => 0;
6780
}

0 commit comments

Comments
 (0)