-
-
Notifications
You must be signed in to change notification settings - Fork 261
feat: Add livequery support #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theSlyest
wants to merge
42
commits into
parse-community:master
Choose a base branch
from
theSlyest:livequery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 d7c8c71
Added ParseLiveQuerySubscription and refactored accordingly
theSlyest 0932e35
Added EventArgs
theSlyest 8740db2
ParseLiveQueryController initialization
theSlyest 542e3cb
Subscription bug fixes
theSlyest 40044a2
Updated event argument types
theSlyest 0f737a0
Added DualParseLiveQueryEventArgs
theSlyest 98e295a
Live query server error management
theSlyest c0a6bec
Renamed DualParseLiveQueryEventArgs to ParseLiveQueryDualEventArgs
theSlyest a267f63
Code quality
theSlyest 4b83d23
Improve code quality
theSlyest 65c73e4
Add null safety for the "where" clause extraction
theSlyest 340f6fb
Improve code quality
theSlyest 7e66bb6
Improvements
theSlyest 84f7060
Null checks
theSlyest 834ff89
Move TimeOut and BufferSize to new LiveQueryServerConnectionData and …
theSlyest bd36b7d
Minor improvements
theSlyest e9c6bcc
Improve message parsing
theSlyest 8938a4d
Improve the retrieval of data objects from a message
theSlyest b65e230
Null safety and small changes
theSlyest cc5168c
Improve controller disposal
theSlyest e70789e
Fix race conditions
theSlyest 2cfef04
Websocket exception handling
theSlyest 97313bf
Small clean up
theSlyest f3374f6
Fix test error
theSlyest 62e81fb
Fix RelationTests
theSlyest a76014f
Fix UserTests
theSlyest fbe273a
Fix RelationTests for net9.0
theSlyest c59316b
Add live query and live query event arg tests
theSlyest d9ec311
Live query event args test corrections
theSlyest e3b5df9
Code quality improvement
theSlyest 70e587a
Fix tests
theSlyest 6a50ce4
Tests code quality
theSlyest 871f015
Replaced "int TimeOut" by "TimeSpan Timeout" and other improvements
theSlyest 5444d5d
Improve code quality
theSlyest 96b20f6
Code rabbits improvements
theSlyest 854beaa
Refactor and add tests
theSlyest a13c7ab
Moved responsibilities from ParseLiveQueryController to 2 new classes
theSlyest b86a45a
Fine tuning some tests
theSlyest ea60936
Added TextWebSocketClientTests
theSlyest 8341e12
CodeRabbit required changes
theSlyest a608262
CodeRabbit requested changes
theSlyest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'."); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.