Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 16 additions & 14 deletions Parse.Tests/RelationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ private class Friend : ParseObject { }
[TestInitialize]
public void SetUp()
{
// Initialize the client and ensure the instance is set
Client = new ParseClient(new ServerConnectionData { Test = true });
Client.Publicize();

// Register the test classes
Client.RegisterSubclass(typeof(TestObject));
Client.RegisterSubclass(typeof(Friend));
Client.RegisterSubclass(typeof(ParseUser));
Client.RegisterSubclass(typeof(ParseSession));
Client.RegisterSubclass(typeof(ParseUser));

// **--- Mocking Setup ---**
// Build a service hub with mocked controllers so the tests never make real
// network requests (previously the mock hub was created but never wired into
// the client, so calls such as SignUpAsync hit the dead https://api.parse.com
// default server and failed on the CI runner).
var hub = new MutableServiceHub(); // Use MutableServiceHub for mocking
var mockUserController = new Mock<IParseUserController>();
var mockObjectController = new Mock<IParseObjectController>();
Expand All @@ -52,7 +45,7 @@ public void SetUp()
.Setup(controller => controller.SignUpAsync(
It.IsAny<IObjectState>(),
It.IsAny<IDictionary<string, IParseFieldOperation>>(),
It.IsAny<IServiceHub>(),
It.IsAny<IServiceHub>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(new MutableObjectState { ObjectId = "some0neTol4v4" }); // Predefined ObjectId for User

Expand All @@ -74,10 +67,19 @@ public void SetUp()
hub.UserController = mockUserController.Object;
hub.ObjectController = mockObjectController.Object;

// Initialize the client with the mocked hub and ensure the instance is set.
Client = new ParseClient(new ServerConnectionData { Test = true }, hub);
Client.Publicize();

// Register the test classes
Client.RegisterSubclass(typeof(TestObject));
Client.RegisterSubclass(typeof(Friend));
Client.RegisterSubclass(typeof(ParseUser));
Client.RegisterSubclass(typeof(ParseSession));
}

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

[TestMethod]
public void TestRelationQuery()
Expand Down
9 changes: 7 additions & 2 deletions Parse.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ public async Task TestLogOut()
.Setup(obj => obj.ClearFromDiskAsync())
.Returns(Task.CompletedTask);

// Mock LogOutAsync to ensure it can execute its logic
// Mock LogOutAsync to complete successfully. (CallBase() cannot be used here because
// IParseCurrentUserController is an interface and has no base implementation to proceed to.)
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 @@ -183,6 +184,10 @@ public async Task TestLogOut()
// Inject mocks into ParseClient
var client = new ParseClient(new ServerConnectionData { Test = true }, hub);

// Bind the user to the mocked client so session revocation during logout uses the
// mocked SessionController instead of making a real network request.
user.Bind(client);

// Act: Perform logout
await client.LogOutAsync(CancellationToken.None);

Expand Down
Loading