-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathClient.cs
92 lines (76 loc) · 3.45 KB
/
Client.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
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Supabase.Postgrest;
using SupabaseTests.Stubs;
namespace SupabaseTests
{
[TestClass]
public class Client
{
private static readonly Random Random = new();
private Supabase.Client _instance;
private static string RandomString(int length)
{
const string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[Random.Next(s.Length)]).ToArray());
}
[TestInitialize]
public async Task InitializeTest()
{
_instance = new Supabase.Client("http://localhost", null, new Supabase.SupabaseOptions
{
AuthUrlFormat = "{0}:9999",
RealtimeUrlFormat = "ws://realtime-dev.localhost:4000/socket",
RestUrlFormat = "{0}:3000",
AutoConnectRealtime = false,
});
await _instance.InitializeAsync();
}
[TestMethod("Client: Initializes.")]
public void ClientInitializes()
{
Assert.IsNotNull(_instance.Realtime);
Assert.IsNotNull(_instance.Auth);
}
[TestMethod("SupabaseModel: Successfully Updates")]
public async Task SupabaseModelUpdates()
{
var model = new Models.Channel { Slug = Guid.NewGuid().ToString() };
var insertResult = await _instance.From<Models.Channel>().Insert(model);
var newChannel = insertResult.Models.FirstOrDefault();
var newSlug = $"Updated Slug @ {DateTime.Now.ToLocalTime()}";
newChannel.Slug = newSlug;
var updatedResult = await newChannel.Update<Models.Channel>();
Assert.AreEqual(newSlug, updatedResult.Models.First().Slug);
}
[TestMethod("SupabaseModel: Successfully Deletes")]
public async Task SupabaseModelDeletes()
{
var slug = Guid.NewGuid().ToString();
var model = new Models.Channel { Slug = slug };
var insertResult = await _instance.From<Models.Channel>().Insert(model);
var newChannel = insertResult.Models.FirstOrDefault();
await newChannel.Delete<Models.Channel>();
var result = await _instance.From<Models.Channel>()
.Filter("slug", Constants.Operator.Equals, slug).Get();
Assert.AreEqual(0, result.Models.Count);
}
[TestMethod("Supports Dependency Injection for clients via property")]
public void SupportsDIForClientsViaProperty()
{
_instance.Auth = new FakeAuthClient();
_instance.Functions = new FakeFunctionsClient();
_instance.Realtime = new FakeRealtimeClient();
_instance.Postgrest = new FakeRestClient();
_instance.Storage = new FakeStorageClient();
Assert.ThrowsExceptionAsync<NotImplementedException>(() => _instance.Auth.GetUser(""));
Assert.ThrowsExceptionAsync<NotImplementedException>(() => _instance.Functions.Invoke(""));
Assert.ThrowsExceptionAsync<NotImplementedException>(() => _instance.Realtime.ConnectAsync());
Assert.ThrowsExceptionAsync<NotImplementedException>(() => _instance.Postgrest.Rpc("", null));
Assert.ThrowsExceptionAsync<NotImplementedException>(() => _instance.Storage.ListBuckets());
}
}
}