Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e0d63ab
Add ParseLiveQuery and dependencies
theSlyest Jun 19, 2025
d7c8c71
Added ParseLiveQuerySubscription and refactored accordingly
theSlyest Jun 20, 2025
0932e35
Added EventArgs
theSlyest Jun 21, 2025
8740db2
ParseLiveQueryController initialization
theSlyest Jun 22, 2025
542e3cb
Subscription bug fixes
theSlyest Jun 23, 2025
40044a2
Updated event argument types
theSlyest Jun 23, 2025
0f737a0
Added DualParseLiveQueryEventArgs
theSlyest Jun 23, 2025
98e295a
Live query server error management
theSlyest Jun 23, 2025
c0a6bec
Renamed DualParseLiveQueryEventArgs to ParseLiveQueryDualEventArgs
theSlyest Jun 24, 2025
a267f63
Code quality
theSlyest Jun 25, 2025
4b83d23
Improve code quality
theSlyest Jun 25, 2025
65c73e4
Add null safety for the "where" clause extraction
theSlyest Jun 25, 2025
340f6fb
Improve code quality
theSlyest Jun 25, 2025
7e66bb6
Improvements
theSlyest Jun 25, 2025
84f7060
Null checks
theSlyest Jun 25, 2025
834ff89
Move TimeOut and BufferSize to new LiveQueryServerConnectionData and …
theSlyest Jun 27, 2025
bd36b7d
Minor improvements
theSlyest Jun 28, 2025
e9c6bcc
Improve message parsing
theSlyest Jun 30, 2025
8938a4d
Improve the retrieval of data objects from a message
theSlyest Jun 30, 2025
b65e230
Null safety and small changes
theSlyest Jun 30, 2025
cc5168c
Improve controller disposal
theSlyest Jun 30, 2025
e70789e
Fix race conditions
theSlyest Jun 30, 2025
2cfef04
Websocket exception handling
theSlyest Jun 30, 2025
97313bf
Small clean up
theSlyest Jun 30, 2025
f3374f6
Fix test error
theSlyest Jul 9, 2025
62e81fb
Fix RelationTests
theSlyest Jul 10, 2025
a76014f
Fix UserTests
theSlyest Jul 10, 2025
fbe273a
Fix RelationTests for net9.0
theSlyest Jul 10, 2025
c59316b
Add live query and live query event arg tests
theSlyest Jul 26, 2025
d9ec311
Live query event args test corrections
theSlyest Jul 26, 2025
e3b5df9
Code quality improvement
theSlyest Jul 26, 2025
70e587a
Fix tests
theSlyest Aug 11, 2025
6a50ce4
Tests code quality
theSlyest Aug 29, 2025
871f015
Replaced "int TimeOut" by "TimeSpan Timeout" and other improvements
theSlyest Aug 29, 2025
5444d5d
Improve code quality
theSlyest Aug 29, 2025
96b20f6
Code rabbits improvements
theSlyest Aug 29, 2025
854beaa
Refactor and add tests
theSlyest Sep 8, 2025
a13c7ab
Moved responsibilities from ParseLiveQueryController to 2 new classes
theSlyest Sep 10, 2025
b86a45a
Fine tuning some tests
theSlyest Sep 11, 2025
ea60936
Added TextWebSocketClientTests
theSlyest Sep 16, 2025
8341e12
CodeRabbit required changes
theSlyest Sep 16, 2025
a608262
CodeRabbit requested changes
theSlyest Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Parse.Tests/DecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class DecoderTests
{
ParseClient Client { get; } = new ParseClient(new ServerConnectionData { Test = true });

[TestInitialize]
public void SetUp()
{
Client.Publicize();
}

[TestMethod]
public void TestParseDate()
{
Expand Down
6 changes: 6 additions & 0 deletions Parse.Tests/EncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class ParseEncoderTestClass : ParseDataEncoder
protected override IDictionary<string, object> EncodeObject(ParseObject value) => null;
}

[TestInitialize]
public void SetUp()
{
Client.Publicize();
}

[TestMethod]
public void TestIsValidType()
{
Expand Down
51 changes: 51 additions & 0 deletions Parse.Tests/LiveQueryDualEventArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Abstractions.Platform.Objects;
using Parse.Infrastructure;
using Parse.Platform.LiveQueries;
using Parse.Platform.Objects;

namespace Parse.Tests;

[TestClass]
public class LiveQueryDualEventArgsTests
{
private ParseClient Client { get; set; }

[TestInitialize]
public void SetUp()
{
// Initialize the client and ensure the instance is set
Client = new ParseClient(new ServerConnectionData { Test = true });
Client.Publicize();
}

[TestCleanup]
public void TearDown() => (Client.Services as ServiceHub).Reset();

[TestMethod]
public void TestParseLiveQueryDualEventArgsConstructor()
{
IObjectState state = new MutableObjectState
{
ObjectId = "waGiManPutr4Pet1r",
ClassName = "Pagi",
CreatedAt = new DateTime { },
ServerData = new Dictionary<string, object>
{
["username"] = "kevin",
["sessionToken"] = "se551onT0k3n"
}
};

ParseObject obj = Client.GenerateObjectFromState<ParseObject>(state, "Corgi");
obj.Set("test", "after");
ParseObject objOrig = Client.GenerateObjectFromState<ParseObject>(state, "Corgi");
objOrig.Set("test", "before");
ParseLiveQueryDualEventArgs args = new ParseLiveQueryDualEventArgs(obj, objOrig);

Assert.AreEqual(obj, args.Object);
Assert.AreEqual(objOrig, args.Original);
}
}
34 changes: 34 additions & 0 deletions Parse.Tests/LiveQueryErrorEventArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Platform.LiveQueries;

namespace Parse.Tests;

[TestClass]
public class LiveQueryErrorEventArgsTests
{
[TestMethod]
public void TestParseLiveQueryErrorEventArgsConstructor()
{
InvalidOperationException exception = new InvalidOperationException("Test exception");
ParseLiveQueryErrorEventArgs args = new ParseLiveQueryErrorEventArgs(42, "Test error", false, exception);

// Assert
Assert.AreEqual(42, args.Code);
Assert.AreEqual("Test error", args.Error);
Assert.AreEqual(false, args.Reconnect);
Assert.AreEqual(exception, args.LocalException);
}

[TestMethod]
public void TestParseLiveQueryErrorEventArgsConstructorWithoutException()
{
ParseLiveQueryErrorEventArgs args = new ParseLiveQueryErrorEventArgs(42, "Test error", true);

// Assert
Assert.AreEqual(42, args.Code);
Assert.AreEqual("Test error", args.Error);
Assert.AreEqual(true, args.Reconnect);
Assert.AreEqual(null, args.LocalException);
}
}
48 changes: 48 additions & 0 deletions Parse.Tests/LiveQueryEventArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Abstractions.Platform.Objects;
using Parse.Infrastructure;
using Parse.Platform.LiveQueries;
using Parse.Platform.Objects;

namespace Parse.Tests;

[TestClass]
public class LiveQueryEventArgsTests
{
private ParseClient Client { get; set; }

[TestInitialize]
public void SetUp()
{
// Initialize the client and ensure the instance is set
Client = new ParseClient(new ServerConnectionData { Test = true });
Client.Publicize();
}

[TestCleanup]
public void TearDown() => (Client.Services as ServiceHub).Reset();

[TestMethod]
public void TestParseLiveQueryEventArgsConstructor()
{
IObjectState state = new MutableObjectState
{
ObjectId = "waGiManPutr4Pet1r",
ClassName = "Pagi",
CreatedAt = new DateTime { },
ServerData = new Dictionary<string, object>
{
["username"] = "kevin",
["sessionToken"] = "se551onT0k3n"
}
};

ParseObject obj = Client.GenerateObjectFromState<ParseObject>(state, "Corgi");
ParseLiveQueryEventArgs args = new ParseLiveQueryEventArgs(obj);

// Assert
Assert.AreEqual(obj, args.Object);
}
}
73 changes: 73 additions & 0 deletions Parse.Tests/LiveQueryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Infrastructure;

namespace Parse.Tests;

[TestClass]
public class LiveQueryTests
{
public class DummyParseObject : ParseObject { }

private ParseClient Client { get; set; }

[TestInitialize]
public void SetUp()
{
// Initialize the client and ensure the instance is set
Client = new ParseClient(new ServerConnectionData { Test = true }, new LiveQueryServerConnectionData { Test = true });
Client.Publicize();
}

[TestCleanup]
public void TearDown() => (Client.Services as ServiceHub).Reset();

[TestMethod]
public void TestConstructor()
{
ParseLiveQuery<ParseObject> liveQuery = new ParseLiveQuery<ParseObject>(
Client.Services,
"DummyClass",
new Dictionary<string, object> { { "foo", "bar" } },
["foo"]);

// Assert
Assert.AreEqual("DummyClass", liveQuery.ClassName, "The ClassName property of liveQuery should be 'DummyClass'.");
IDictionary<string, object> buildParameters = liveQuery.BuildParameters();
Assert.AreEqual("DummyClass", buildParameters["className"], "The ClassName property of liveQuery should be 'DummyClass'.");
Assert.IsTrue(buildParameters.ContainsKey("where"), "The 'where' key should be present in the build parameters.");
Assert.IsTrue(buildParameters.ContainsKey("keys"), "The 'keys' key should be present in the build parameters.");
Assert.IsInstanceOfType<Dictionary<string, object>>(buildParameters["where"], "The 'where' parameter should be a Dictionary<string, object>.");
Assert.IsInstanceOfType<string[]>(buildParameters["keys"], "The 'keys' parameter should be a string array.");
Assert.AreEqual("bar", ((Dictionary<string, object>)buildParameters["where"])["foo"], "The 'where' clause should match the query condition.");
Assert.AreEqual("foo", ((string[])buildParameters["keys"]).First(), "The 'keys' parameter should contain 'foo'.");
}

[TestMethod]
public void TestGetLive()
{
// Arrange
ParseQuery<ParseObject> query = Client.GetQuery("DummyClass")
.WhereEqualTo("foo", "bar")
.Select("foo");

// Act
ParseLiveQuery<ParseObject> liveQuery = query.GetLive()
.Watch("foo");

// Assert
Assert.AreEqual("DummyClass", liveQuery.ClassName, "The ClassName property of liveQuery should be 'DummyClass'.");
IDictionary<string, object> buildParameters = liveQuery.BuildParameters();
Assert.AreEqual("DummyClass", buildParameters["className"], "The ClassName property of liveQuery should be 'DummyClass'.");
Assert.IsTrue(buildParameters.ContainsKey("where"), "The 'where' key should be present in the build parameters.");
Assert.IsTrue(buildParameters.ContainsKey("keys"), "The 'keys' key should be present in the build parameters.");
Assert.IsTrue(buildParameters.ContainsKey("watch"), "The 'watch' key should be present in the build parameters.");
Assert.IsInstanceOfType<Dictionary<string, object>>(buildParameters["where"], "The 'where' parameter should be a Dictionary<string, object>.");
Assert.IsInstanceOfType<string[]>(buildParameters["keys"], "The 'keys' parameter should be a string array.");
Assert.IsInstanceOfType<string[]>(buildParameters["watch"], "The 'watch' parameter should be a string array.");
Assert.AreEqual("bar", ((Dictionary<string, object>)buildParameters["where"])["foo"], "The 'where' clause should match the query condition.");
Assert.AreEqual("foo", ((string[])buildParameters["keys"]).First(), "The 'keys' parameter should contain 'foo'.");
Assert.AreEqual("foo", ((string[])buildParameters["watch"]).First(), "The 'watch' parameter should contain 'foo'.");
}
}
2 changes: 2 additions & 0 deletions Parse.Tests/ObjectCoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Collections.Generic;
using System.Diagnostics;

namespace Parse.Tests;

[TestClass]
public class ObjectCoderTests
{
Expand Down
8 changes: 2 additions & 6 deletions Parse.Tests/RelationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task AddRelationToUserAsync_ThrowsException_WhenUserIsNull()
public async Task AddRelationToUserAsync_ThrowsException_WhenRelationFieldIsNull()
{
var user = new ParseUser() { Username = "TestUser", Password = "TestPass", Services = Client.Services };
await user.SignUpAsync();

var relatedObjects = new List<ParseObject>
{
new ParseObject("Friend", Client.Services) { ["name"] = "Friend1" }
Expand Down Expand Up @@ -143,7 +143,6 @@ public async Task UpdateUserRelationAsync_ThrowsException_WhenUserIsNull()
public async Task UpdateUserRelationAsync_ThrowsException_WhenRelationFieldIsNull()
{
var user = new ParseUser() { Username = "TestUser", Password = "TestPass", Services = Client.Services };
await user.SignUpAsync();

var relatedObjectsToAdd = new List<ParseObject>
{
Expand All @@ -168,8 +167,6 @@ public async Task DeleteUserRelationAsync_ThrowsException_WhenUserIsNull()
public async Task DeleteUserRelationAsync_ThrowsException_WhenRelationFieldIsNull()
{
var user = new ParseUser() { Username = "TestUser", Password = "TestPass", Services = Client.Services };
await user.SignUpAsync();

await Assert.ThrowsExceptionAsync<ArgumentException>(() => UserManagement.DeleteUserRelationAsync(user, null));
}
[TestMethod]
Expand All @@ -183,7 +180,6 @@ public async Task GetUserRelationsAsync_ThrowsException_WhenUserIsNull()
public async Task GetUserRelationsAsync_ThrowsException_WhenRelationFieldIsNull()
{
var user = new ParseUser() { Username = "TestUser", Password = "TestPass", Services = Client.Services };
await user.SignUpAsync();

await Assert.ThrowsExceptionAsync<ArgumentException>(() => UserManagement.GetUserRelationsAsync(user, null));
}
Expand All @@ -196,7 +192,6 @@ public async Task AddRelationToUserAsync_ThrowsException_WhenRelatedObjectIsUnsa
{
// Arrange: Create and sign up a test user.
var user = new ParseUser() { Username = "TestUser", Password = "TestPass", Services = Client.Services };
await user.SignUpAsync();

// Create an unsaved Friend object (do NOT call SaveAsync).
var unsavedFriend = new ParseObject("Friend", Client.Services) { ["name"] = "UnsavedFriend" };
Expand All @@ -205,6 +200,7 @@ public async Task AddRelationToUserAsync_ThrowsException_WhenRelatedObjectIsUnsa
// Act & Assert: Expect an exception when trying to add an unsaved object.
await Assert.ThrowsExceptionAsync<ArgumentException>(() =>
UserManagement.AddRelationToUserAsync(user, "friends", relatedObjects));

}


Expand Down
2 changes: 2 additions & 0 deletions Parse.Tests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Parse.Platform.Objects;
using Parse.Abstractions.Platform.Users;

namespace Parse.Tests;

[TestClass]
public class SessionTests
{
Expand Down
3 changes: 2 additions & 1 deletion Parse.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task TestLogOut()
// Mock LogOutAsync to ensure it can execute its logic
mockCurrentUserController
.Setup(obj => obj.LogOutAsync(It.IsAny<IServiceHub>(), It.IsAny<CancellationToken>()))
.CallBase(); // Use the actual LogOutAsync implementation
.Returns(Task.CompletedTask);

// Mock SessionController for session revocation
var mockSessionController = new Mock<IParseSessionController>();
Expand All @@ -182,6 +182,7 @@ public async Task TestLogOut()

// Inject mocks into ParseClient
var client = new ParseClient(new ServerConnectionData { Test = true }, hub);
user.Bind(client);

// Act: Perform logout
await client.LogOutAsync(CancellationToken.None);
Expand Down
7 changes: 7 additions & 0 deletions Parse/Abstractions/Infrastructure/CustomServiceHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Parse.Abstractions.Platform.Configuration;
using Parse.Abstractions.Platform.Files;
using Parse.Abstractions.Platform.Installations;
using Parse.Abstractions.Platform.LiveQueries;
using Parse.Abstractions.Platform.Objects;
using Parse.Abstractions.Platform.Push;
using Parse.Abstractions.Platform.Queries;
Expand All @@ -31,6 +32,8 @@ public abstract class CustomServiceHub : ICustomServiceHub

public virtual IParseCommandRunner CommandRunner => Services.CommandRunner;

public virtual IWebSocketClient WebSocketClient => Services.WebSocketClient;

public virtual IParseCloudCodeController CloudCodeController => Services.CloudCodeController;

public virtual IParseConfigurationController ConfigurationController => Services.ConfigurationController;
Expand All @@ -41,6 +44,8 @@ public abstract class CustomServiceHub : ICustomServiceHub

public virtual IParseQueryController QueryController => Services.QueryController;

public virtual IParseLiveQueryController LiveQueryController => Services.LiveQueryController;

public virtual IParseSessionController SessionController => Services.SessionController;

public virtual IParseUserController UserController => Services.UserController;
Expand All @@ -59,6 +64,8 @@ public abstract class CustomServiceHub : ICustomServiceHub

public virtual IServerConnectionData ServerConnectionData => Services.ServerConnectionData;

public virtual ILiveQueryServerConnectionData LiveQueryServerConnectionData => Services.LiveQueryServerConnectionData;

public virtual IParseDataDecoder Decoder => Services.Decoder;

public virtual IParseInstallationDataFinalizer InstallationDataFinalizer => Services.InstallationDataFinalizer;
Expand Down
Loading