Skip to content

Commit 0f4ed39

Browse files
committed
test: improve unit test based on issue #109
1 parent ac25651 commit 0f4ed39

File tree

12 files changed

+692
-7
lines changed

12 files changed

+692
-7
lines changed

PostgrestTests/ClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace PostgrestTests
1919
[TestClass]
2020
public class ClientTests
2121
{
22-
private const string BaseUrl = "http://localhost:3000";
22+
private const string BaseUrl = "http://localhost:54321/rest/v1";
2323

2424
[TestMethod("Initializes")]
2525
public void TestInitialization()

PostgrestTests/CoercionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace PostgrestTests;
1111
[TestClass]
1212
public class CoercionTests
1313
{
14-
private const string BaseUrl = "http://localhost:3000";
14+
private const string BaseUrl = "http://localhost:54321/rest/v1";
1515

1616
[TestMethod("Coercion: Can coerce primitive types")]
1717
public async Task CanCoercePrimitiveTypes()

PostgrestTests/Helpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ internal static Client GetHostedClient()
2525
internal static Client GetLocalClient()
2626
{
2727
var url = Environment.GetEnvironmentVariable("SUPABASE_URL");
28-
if (url == null) url = "http://localhost:3000";
28+
if (url == null) url = "http://localhost:54321";
2929
var publicKey = Environment.GetEnvironmentVariable("SUPABASE_PUBLIC_KEY");
30-
if (publicKey == null) publicKey = "reallyreallyreallyreallyverysafe";
30+
if (publicKey == null) publicKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0";
3131

3232
var client = new Client($"{url}/rest/v1", new ClientOptions
3333
{

PostgrestTests/LinqTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace PostgrestTests
1313
[TestClass]
1414
public class LinqTests
1515
{
16-
private const string BaseUrl = "http://localhost:3000";
16+
private const string BaseUrl = "http://localhost:54321/rest/v1";
1717

1818
[TestMethod("Linq: Select")]
1919
public async Task TestLinqSelect()
@@ -123,14 +123,17 @@ await client.Table<KitchenSink>()
123123
.Get();
124124

125125
await client.Table<KitchenSink>()
126+
.Where(x => x.DateTimeValue == null)
126127
.Set(x => x.BooleanValue!, true)
127128
.Update();
128129

129130
await client.Table<KitchenSink>()
131+
.Where(x => x.DateTimeValue == null)
130132
.Set(x => x.BooleanValue, true)
131133
.Update();
132134

133135
await client.Table<KitchenSink>()
136+
.Where(x => x.DateTimeValue == null)
134137
.Set(x => x.StringValue!, null)
135138
.Update();
136139
}

PostgrestTests/Models/Category.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using Supabase.Postgrest.Attributes;
3+
using Supabase.Postgrest.Models;
4+
5+
namespace PostgrestTests.Models;
6+
7+
[Table("category")]
8+
public class Category : BaseModel
9+
{
10+
[PrimaryKey("id")]
11+
public Guid Id { get; set; }
12+
13+
[Column("name")]
14+
public string? Name { get; set; }
15+
}

PostgrestTests/Models/Product.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using Supabase.Postgrest.Attributes;
3+
using Supabase.Postgrest.Models;
4+
5+
namespace PostgrestTests.Models;
6+
7+
[Table("product")]
8+
public class Product : BaseModel
9+
{
10+
11+
[PrimaryKey("id")]
12+
public Guid Id { get; set; }
13+
14+
[Column("name")]
15+
public string? Name { get; set; }
16+
17+
[Reference(typeof(Category))]
18+
public Category? Category { get; set; }
19+
}

PostgrestTests/ReferenceTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace PostgrestTests
1212
[TestClass]
1313
public class ReferenceTests
1414
{
15-
private const string BaseUrl = "http://localhost:3000";
15+
private const string BaseUrl = "http://localhost:54321/rest/v1";
1616

1717
[TestMethod("Reference: Returns linked models on a root model.")]
1818
public async Task TestReferenceReturnsLinkedModels()
@@ -36,13 +36,34 @@ public async Task TestReferenceReturnsLinkedModels()
3636
.Single();
3737

3838
Assert.IsNotNull(person2?.Profile);
39+
Assert.IsTrue(person2.Profile.Email!.Contains("bob"));
3940

4041
var byEmail = await client.Table<Person>()
4142
.Order(x => x.CreatedAt, Ordering.Ascending)
4243
.Filter("profile.email", Operator.Equals, "bob.saggett@supabase.io")
4344
.Single();
4445

4546
Assert.IsNotNull(byEmail);
47+
48+
var product = await client.Table<Product>()
49+
.Filter("id", Operator.Equals, "8b8e89a0-63c7-4917-8dc1-7797dc0285f1")
50+
.Single();
51+
52+
Assert.IsNotNull(product);
53+
Assert.AreEqual("product 1", product.Name);
54+
55+
Assert.IsNotNull(product.Category);
56+
Assert.AreEqual("999e4b26-91a8-4ea4-af2c-77a3540f7843", product.Category.Id.ToString());
57+
Assert.AreEqual("category 1", product.Category.Name);
58+
59+
var products = await client.Table<Product>()
60+
.Get();
61+
Assert.IsNotNull(products.Models);
62+
Assert.IsTrue(products.Models.Count == 3);
63+
64+
var productFiltered = products.Models.Find(x => x.Id.ToString() == "8b8e89a0-63c7-4917-8dc1-7797dc0285f1");
65+
Assert.AreEqual("999e4b26-91a8-4ea4-af2c-77a3540f7843", productFiltered?.Category?.Id.ToString());
66+
Assert.AreEqual("category 1", productFiltered?.Category?.Name);
4667
}
4768

4869
[TestMethod("Reference: Can create linked records.")]

PostgrestTests/TableWithCacheTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Task Empty()
6262
[TestClass]
6363
public class TableWithCacheTests
6464
{
65-
private const string BaseUrl = "http://localhost:3000";
65+
private const string BaseUrl = "http://localhost:54321/rest/v1";
6666

6767
[TestMethod("Table: Can construct with Caching Provider and raise events.")]
6868
public async Task TestCacheWorksWithGetRequests()

supabase/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Supabase
2+
.branches
3+
.temp
4+
5+
# dotenvx
6+
.env.keys
7+
.env.local
8+
.env.*.local

0 commit comments

Comments
 (0)