-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Upgrade target framework from NET Standard 2.0 to .NET 6.0 (#393)
BREAKING CHANGE: This release requires .NET 6.0 or later and removes compatibility with NET Standard 2.0; Xamarin developers should migrate to .NET MAUI to use this version of the Parse SDK; Unity developers should use the previous SDK version until Unity supports .NET.
- Loading branch information
Showing
186 changed files
with
15,511 additions
and
12,834 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,58 +1,130 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; // Add Moq for mocking if not already added | ||
using Parse.Infrastructure; | ||
using Parse.Platform.Objects; | ||
using Parse.Abstractions.Infrastructure; | ||
using Parse.Abstractions.Platform.Objects; | ||
|
||
namespace Parse.Tests | ||
namespace Parse.Tests; | ||
|
||
[TestClass] | ||
public class ACLTests | ||
{ | ||
[TestClass] | ||
public class ACLTests | ||
ParseClient Client { get; set; } | ||
|
||
Mock<IServiceHub> ServiceHubMock { get; set; } | ||
Mock<IParseObjectClassController> ClassControllerMock { get; set; } | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
ParseClient Client { get; set; } = new ParseClient(new ServerConnectionData { Test = true }); | ||
// Mock ServiceHub | ||
ServiceHubMock = new Mock<IServiceHub>(); | ||
ClassControllerMock = new Mock<IParseObjectClassController>(); | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
Client.AddValidClass<ParseUser>(); | ||
Client.AddValidClass<ParseSession>(); | ||
} | ||
// Mock ClassController behavior | ||
ServiceHubMock.Setup(hub => hub.ClassController).Returns(ClassControllerMock.Object); | ||
|
||
[TestCleanup] | ||
public void Clean() => (Client.Services as ServiceHub).Reset(); | ||
// Mock ClassController.Instantiate behavior | ||
ClassControllerMock.Setup(controller => controller.Instantiate(It.IsAny<string>(), It.IsAny<IServiceHub>())) | ||
.Returns<string, IServiceHub>((className, hub) => | ||
{ | ||
var user = new ParseUser(); | ||
user.Bind(hub); // Ensure the object is bound to the service hub | ||
return user; | ||
}); | ||
|
||
[TestMethod] | ||
public void TestCheckPermissionsWithParseUserConstructor() | ||
// Set up ParseClient with the mocked ServiceHub | ||
Client = new ParseClient(new ServerConnectionData { Test = true }) | ||
{ | ||
ParseUser owner = GenerateUser("OwnerUser"); | ||
ParseUser user = GenerateUser("OtherUser"); | ||
ParseACL acl = new ParseACL(owner); | ||
Assert.IsTrue(acl.GetReadAccess(owner.ObjectId)); | ||
Assert.IsTrue(acl.GetWriteAccess(owner.ObjectId)); | ||
Assert.IsTrue(acl.GetReadAccess(owner)); | ||
Assert.IsTrue(acl.GetWriteAccess(owner)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestReadWriteMutationWithParseUserConstructor() | ||
{ | ||
ParseUser owner = GenerateUser("OwnerUser"); | ||
ParseUser otherUser = GenerateUser("OtherUser"); | ||
ParseACL acl = new ParseACL(owner); | ||
acl.SetReadAccess(otherUser, true); | ||
acl.SetWriteAccess(otherUser, true); | ||
acl.SetReadAccess(owner.ObjectId, false); | ||
acl.SetWriteAccess(owner.ObjectId, false); | ||
Assert.IsTrue(acl.GetReadAccess(otherUser.ObjectId)); | ||
Assert.IsTrue(acl.GetWriteAccess(otherUser.ObjectId)); | ||
Assert.IsTrue(acl.GetReadAccess(otherUser)); | ||
Assert.IsTrue(acl.GetWriteAccess(otherUser)); | ||
Assert.IsFalse(acl.GetReadAccess(owner)); | ||
Assert.IsFalse(acl.GetWriteAccess(owner)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestParseACLCreationWithNullObjectIdParseUser() => Assert.ThrowsException<ArgumentException>(() => new ParseACL(GenerateUser(default))); | ||
|
||
ParseUser GenerateUser(string objectID) => Client.GenerateObjectFromState<ParseUser>(new MutableObjectState { ObjectId = objectID }, "_User"); | ||
Services = ServiceHubMock.Object | ||
}; | ||
|
||
// Publicize the client to set ParseClient.Instance | ||
Client.Publicize(); | ||
|
||
// Add valid classes to the client | ||
Client.AddValidClass<ParseUser>(); | ||
Client.AddValidClass<ParseSession>(); | ||
} | ||
|
||
[TestCleanup] | ||
public void Clean() => (Client.Services as ServiceHub)?.Reset(); | ||
|
||
[TestMethod] | ||
public void TestCheckPermissionsWithParseUserConstructor() | ||
{ | ||
// Arrange | ||
ParseUser owner = GenerateUser("OwnerUser"); | ||
ParseUser user = GenerateUser("OtherUser"); | ||
|
||
// Act | ||
ParseACL acl = new ParseACL(owner); | ||
|
||
// Assert | ||
Assert.IsTrue(acl.GetReadAccess(owner.ObjectId)); | ||
Assert.IsTrue(acl.GetWriteAccess(owner.ObjectId)); | ||
Assert.IsTrue(acl.GetReadAccess(owner)); | ||
Assert.IsTrue(acl.GetWriteAccess(owner)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestReadWriteMutationWithParseUserConstructor() | ||
{ | ||
// Arrange | ||
ParseUser owner = GenerateUser("OwnerUser"); | ||
ParseUser otherUser = GenerateUser("OtherUser"); | ||
|
||
// Act | ||
ParseACL acl = new ParseACL(owner); | ||
acl.SetReadAccess(otherUser, true); | ||
acl.SetWriteAccess(otherUser, true); | ||
acl.SetReadAccess(owner.ObjectId, false); | ||
acl.SetWriteAccess(owner.ObjectId, false); | ||
|
||
// Assert | ||
Assert.IsTrue(acl.GetReadAccess(otherUser.ObjectId)); | ||
Assert.IsTrue(acl.GetWriteAccess(otherUser.ObjectId)); | ||
Assert.IsTrue(acl.GetReadAccess(otherUser)); | ||
Assert.IsTrue(acl.GetWriteAccess(otherUser)); | ||
Assert.IsFalse(acl.GetReadAccess(owner)); | ||
Assert.IsFalse(acl.GetWriteAccess(owner)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestParseACLCreationWithNullObjectIdParseUser() | ||
{ | ||
// Assert | ||
Assert.ThrowsException<ArgumentException>(() => new ParseACL(GenerateUser(default))); | ||
} | ||
|
||
ParseUser GenerateUser(string objectID) | ||
{ | ||
// Use the mock to simulate generating a ParseUser | ||
var state = new MutableObjectState { ObjectId = objectID }; | ||
return Client.GenerateObjectFromState<ParseUser>(state, "_User"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGenerateObjectFromState() | ||
{ | ||
// Arrange | ||
var state = new MutableObjectState { ObjectId = "123", ClassName = null }; | ||
var defaultClassName = "_User"; | ||
|
||
var serviceHubMock = new Mock<IServiceHub>(); | ||
var classControllerMock = new Mock<IParseObjectClassController>(); | ||
|
||
classControllerMock.Setup(controller => controller.Instantiate(It.IsAny<string>(), It.IsAny<IServiceHub>())) | ||
.Returns<string, IServiceHub>((className, hub) => new ParseUser()); | ||
|
||
// Act | ||
var user = classControllerMock.Object.GenerateObjectFromState<ParseUser>(state, defaultClassName, serviceHubMock.Object); | ||
|
||
// Assert | ||
Assert.IsNotNull(user); | ||
Assert.AreEqual(defaultClassName, user.ClassName); | ||
} | ||
|
||
} |
Oops, something went wrong.