diff --git a/Parse.Tests/RelationTests.cs b/Parse.Tests/RelationTests.cs index c550e582..51ff4d0d 100644 --- a/Parse.Tests/RelationTests.cs +++ b/Parse.Tests/RelationTests.cs @@ -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(); var mockObjectController = new Mock(); @@ -52,7 +45,7 @@ public void SetUp() .Setup(controller => controller.SignUpAsync( It.IsAny(), It.IsAny>(), - It.IsAny(), + It.IsAny(), It.IsAny())) .ReturnsAsync(new MutableObjectState { ObjectId = "some0neTol4v4" }); // Predefined ObjectId for User @@ -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() diff --git a/Parse.Tests/UserTests.cs b/Parse.Tests/UserTests.cs index 21a8895b..fba42e1a 100644 --- a/Parse.Tests/UserTests.cs +++ b/Parse.Tests/UserTests.cs @@ -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(), It.IsAny())) - .CallBase(); // Use the actual LogOutAsync implementation + .Returns(Task.CompletedTask); // Mock SessionController for session revocation var mockSessionController = new Mock(); @@ -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);