Skip to content
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

feat: Missing Methods and Implementations after v4.0. #402

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
827bf53
All Set and done
YBTopaz8 Nov 28, 2024
72754d6
Update UI elements, add icons, and conditional compilation
YBTopaz8 Nov 28, 2024
dbb9ad1
Refactor and enhance UI and services
YBTopaz8 Nov 29, 2024
4bdec70
Refactor and update ParseLiveQueryClient and projects
YBTopaz8 Nov 30, 2024
ac325b2
Refactor and enhance FlowHub-MAUI and ParseLiveQuery
YBTopaz8 Nov 30, 2024
b13afac
Refactor methods to use block bodies for readability
YBTopaz8 Dec 1, 2024
b5057d4
save
YBTopaz8 Dec 1, 2024
1c29bc1
Finally Fixed for .net 9 and MAUI
YBTopaz8 Dec 2, 2024
5a71f08
Merge pull request #1 from YBTopaz8/Testt
YBTopaz8 Dec 2, 2024
12b6da1
Update README.md
YBTopaz8 Dec 2, 2024
bd47d51
Update CHANGELOG.md
YBTopaz8 Dec 3, 2024
4487e2d
Update CONTRIBUTING.md
YBTopaz8 Dec 3, 2024
3d6df63
Update README.md
YBTopaz8 Dec 3, 2024
6346a77
Refactor ParseInstallation and ParseObjectClassController
YBTopaz8 Dec 3, 2024
fe93551
Upgraded to .NET6+ & Updated UnitTests
YBTopaz8 Dec 8, 2024
838e2d8
Enhance .NET Compatibility & Complete TODOs
YBTopaz8 Dec 10, 2024
ece8084
Merge branch 'master' into Testt
mtrezza Dec 10, 2024
d3164c5
Update Parse/Infrastructure/CacheController.cs
YBTopaz8 Dec 11, 2024
ccf2807
Improved Locking Mechanism, now using SemaphoreLock and some minor ch…
YBTopaz8 Dec 11, 2024
e5bbeba
Fully Fixed Parse SDK
YBTopaz8 Dec 12, 2024
e478005
update CI
mtrezza Dec 13, 2024
9124596
Update ci.yml
mtrezza Dec 13, 2024
281130f
Update ci.yml
mtrezza Dec 13, 2024
4940f44
Simplify targets, update tests, and enhance error handling
YBTopaz8 Dec 13, 2024
60e9356
Merge branch 'Testt' of https://github.com/YBTopaz8/Parse-SDK-dotNET …
YBTopaz8 Dec 13, 2024
c35b893
Fixed compat issue brought by VS
YBTopaz8 Dec 13, 2024
8b2af66
Re-Added several .net target versions to now 6,7,8,9 instead of only 8
YBTopaz8 Dec 13, 2024
b0e6082
Reverted Proj changes not destined here
YBTopaz8 Dec 13, 2024
d28e03c
All set.
YBTopaz8 Dec 13, 2024
760e11e
Update ci.yml
mtrezza Dec 13, 2024
369a1a6
Update ci.yml
mtrezza Dec 13, 2024
848d6eb
Update ci.yml
mtrezza Dec 13, 2024
09965a5
Test in multiple NET frameworks
mtrezza Dec 13, 2024
50b8671
Update ci.yml
mtrezza Dec 13, 2024
5bcc989
add .NET badge to README
mtrezza Dec 13, 2024
513955c
add compat table to README
mtrezza Dec 13, 2024
5623f88
Fixed LogOut Issues in Parse SDK itself.
YBTopaz8 Dec 17, 2024
d68e0b1
Merge branch 'Testt' of https://github.com/YBTopaz8/Parse-SDK-dotNET …
YBTopaz8 Dec 17, 2024
c694198
Fixed Test TargetFramework
YBTopaz8 Dec 17, 2024
50dcce4
Big Fixes & more coverage.
YBTopaz8 Dec 21, 2024
58b1a12
Updated Cproj & Changelog
YBTopaz8 Dec 21, 2024
ec234eb
Fixed Conflicts
YBTopaz8 Dec 21, 2024
80bc14c
Merged Conflicts.
YBTopaz8 Dec 21, 2024
2d3b3f4
Properly cleaned up now too
YBTopaz8 Dec 22, 2024
d4c8ff1
Merge branch 'YvanBrunelOfficialBranch' into v4.0-hotfix
YBTopaz8 Dec 22, 2024
012636e
Cleared warnings
YBTopaz8 Dec 23, 2024
81d753a
Merge branch 'v4.0-hotfix' of https://github.com/YBTopaz8/Parse-SDK-d…
YBTopaz8 Dec 23, 2024
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## [3.0.2](https://github.com/parse-community/Parse-SDK-dotNET/compare/3.0.1...3.0.2) (2024-05-24)


### Bug Fixes
### Initial Release!

* Cannot access objects without user login ([#368](https://github.com/parse-community/Parse-SDK-dotNET/issues/368)) ([aa278df](https://github.com/parse-community/Parse-SDK-dotNET/commit/aa278df8147516a2ff8a95e1fa0f5f7972c63cc4))

Expand All @@ -34,4 +34,4 @@

### BREAKING CHANGES

* This changes the license to Apache 2.0. This release may contain breaking changes which are not listed here, so please make sure to test your app carefully when upgrading. ([6887aff](6887aff))
* This changes the license to Apache 2.0. This release may contain breaking changes which are not listed here, so please make sure to test your app carefully when upgrading. ([6887aff](6887aff))
12 changes: 3 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ We want to make contributing to this project as easy and transparent as possible

### Pull Requests

We actively welcome your pull requests. When we get one, we'll run some tests on it first. From here, we'll need to get a core member to sign off on the changes and then merge the pull request.
PRs are welcomed!

1. Fork the repo and create your branch from `master`.
2. Add unit tests for any new code you add.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
2. If you've changed APIs, update the documentation.

## Style Guide

We're still working on providing a more concise code style for your IDE and getting a linter on GitHub, but for now try to keep the following:
- Please ALWAYS unwrap your long methods to enhance readability. If your code is quickly readable, then we can quickly sketch out what it does, but if wrapped, it gets UNNECESSARILY longer to understand.

* We use [editorconfig](https://editorconfig.org) to manage basic editor settings, please install a compatible plugin for your preferred environment.
* Most importantly, match the existing code style as much as possible.
* Try to keep lines under 120 characters, if possible.

## License

By contributing to Parse .NET SDK, you agree that your contributions will be licensed under its license
174 changes: 161 additions & 13 deletions Parse.Tests/ACLTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 Moq;
using Parse.Abstractions.Infrastructure;
using Parse.Abstractions.Platform.Objects;

namespace Parse.Tests;
using Parse.Infrastructure;
using Parse.Platform.Objects;
using Parse;
using System.Collections.Generic;
using System;

[TestClass]
public class ACLTests
Expand Down Expand Up @@ -35,6 +35,7 @@ public void Initialize()
return user;
});


// Set up ParseClient with the mocked ServiceHub
Client = new ParseClient(new ServerConnectionData { Test = true })
{
Expand All @@ -47,13 +48,23 @@ public void Initialize()
// Add valid classes to the client
Client.AddValidClass<ParseUser>();
Client.AddValidClass<ParseSession>();
Client.AddValidClass<ParseRole>();
}

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

[TestMethod]
public void TestCheckPermissionsWithParseUserConstructor()
[Description("Tests if default ParseACL is created without errors.")]
public void TestParseACLDefaultConstructor() // Mock difficulty: 1
{
var acl = new ParseACL();
Assert.IsNotNull(acl);

}
[TestMethod]
[Description("Tests ACL creation using ParseUser constructor.")]
public void TestCheckPermissionsWithParseUserConstructor() // Mock difficulty: 1
{
// Arrange
ParseUser owner = GenerateUser("OwnerUser");
Expand All @@ -70,7 +81,8 @@ public void TestCheckPermissionsWithParseUserConstructor()
}

[TestMethod]
public void TestReadWriteMutationWithParseUserConstructor()
[Description("Tests that users permission change accordingly")]
public void TestReadWriteMutationWithParseUserConstructor()// Mock difficulty: 1
{
// Arrange
ParseUser owner = GenerateUser("OwnerUser");
Expand All @@ -93,7 +105,8 @@ public void TestReadWriteMutationWithParseUserConstructor()
}

[TestMethod]
public void TestParseACLCreationWithNullObjectIdParseUser()
[Description("Tests if throws if try to instantiate using a ParseUser without objectId.")]
public void TestParseACLCreationWithNullObjectIdParseUser() // Mock difficulty: 1
{
// Assert
Assert.ThrowsException<ArgumentException>(() => new ParseACL(GenerateUser(default)));
Expand All @@ -102,22 +115,25 @@ public void TestParseACLCreationWithNullObjectIdParseUser()
ParseUser GenerateUser(string objectID)
{
// Use the mock to simulate generating a ParseUser
var state = new MutableObjectState { ObjectId = objectID };
var state = new MutableObjectState { ObjectId = objectID, ClassName = "_User" };
return Client.GenerateObjectFromState<ParseUser>(state, "_User");

}

[TestMethod]
public void TestGenerateObjectFromState()
[Description("Tests to create a ParseUser via IParseClassController, that is set when calling Bind.")]
public void TestGenerateObjectFromState() // Mock difficulty: 1
{
// 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());
.Returns<string, IServiceHub>((className, hub) => new ParseUser());

// Act
var user = classControllerMock.Object.GenerateObjectFromState<ParseUser>(state, defaultClassName, serviceHubMock.Object);
Expand All @@ -126,5 +142,137 @@ public void TestGenerateObjectFromState()
Assert.IsNotNull(user);
Assert.AreEqual(defaultClassName, user.ClassName);
}
[TestMethod]
[Description("Tests for public read and write access values.")]
public void TestPublicReadWriteAccessValues() // Mock difficulty: 1
{
var acl = new ParseACL();
Assert.IsFalse(acl.PublicReadAccess);
Assert.IsFalse(acl.PublicWriteAccess);

acl.PublicReadAccess = true;
acl.PublicWriteAccess = true;
Assert.IsTrue(acl.PublicReadAccess);
Assert.IsTrue(acl.PublicWriteAccess);
}

[TestMethod]
[Description("Tests that sets and gets properly for string UserIds.")]
public void TestSetGetAccessWithStringId() // Mock difficulty: 1
{
var acl = new ParseACL();
var testUser = GenerateUser("test");
acl.SetReadAccess(testUser.ObjectId, true);
acl.SetWriteAccess(testUser.ObjectId, true);

Assert.IsTrue(acl.GetReadAccess(testUser.ObjectId));
Assert.IsTrue(acl.GetWriteAccess(testUser.ObjectId));

acl.SetReadAccess(testUser.ObjectId, false);
acl.SetWriteAccess(testUser.ObjectId, false);

Assert.IsFalse(acl.GetReadAccess(testUser.ObjectId));
Assert.IsFalse(acl.GetWriteAccess(testUser.ObjectId));
}

[TestMethod]
[Description("Tests that methods thow exceptions if user id is null.")]
public void SetGetAccessThrowsForNull() // Mock difficulty: 1
{
var acl = new ParseACL();

Assert.ThrowsException<ArgumentException>(() => acl.SetReadAccess(userId:null, false));
Assert.ThrowsException<ArgumentException>(() => acl.SetWriteAccess(userId: null, false));
Assert.ThrowsException<ArgumentException>(() => acl.GetReadAccess(userId:null));
Assert.ThrowsException<ArgumentException>(() => acl.GetWriteAccess(userId:null));

}
[TestMethod]
[Description("Tests that a Get access using a ParseUser is correct.")]
public void TestSetGetAccessWithParseUser() // Mock difficulty: 1
{
var acl = new ParseACL();
ParseUser test = GenerateUser("test");

acl.SetReadAccess(test, true);
acl.SetWriteAccess(test, true);
Assert.IsTrue(acl.GetReadAccess(test));
Assert.IsTrue(acl.GetWriteAccess(test));

acl.SetReadAccess(test, false);
acl.SetWriteAccess(test, false);

Assert.IsFalse(acl.GetReadAccess(test));
Assert.IsFalse(acl.GetWriteAccess(test));

}

[TestMethod]
[Description("Tests that the default ParseACL returns correct roles for read/write")]
public void TestDefaultRolesForReadAndWriteAccess() // Mock difficulty: 1
{
var acl = new ParseACL();
Assert.IsFalse(acl.GetRoleReadAccess("role"));
Assert.IsFalse(acl.GetRoleWriteAccess("role"));

}

}
[TestMethod]
[Description("Tests role read/write access with role names correctly and get methods.")]
public void TestSetGetRoleReadWriteAccessWithRoleName() // Mock difficulty: 1
{
var acl = new ParseACL();
acl.SetRoleReadAccess("test", true);
acl.SetRoleWriteAccess("test", true);
Assert.IsTrue(acl.GetRoleReadAccess("test"));
Assert.IsTrue(acl.GetRoleWriteAccess("test"));

acl.SetRoleReadAccess("test", false);
acl.SetRoleWriteAccess("test", false);
Assert.IsFalse(acl.GetRoleReadAccess("test"));
Assert.IsFalse(acl.GetRoleWriteAccess("test"));
}

[TestMethod]
[Description("Tests ACL can use and correctly convert to JSON object via ConvertToJSON.")]
public void TestConvertToJSON() // Mock difficulty: 3
{
var acl = new ParseACL();
ParseUser user = GenerateUser("test");

acl.SetReadAccess(user, true);
acl.SetWriteAccess(user, false);
acl.SetRoleReadAccess("test", true);
var json = (acl as IJsonConvertible).ConvertToJSON();
Assert.IsInstanceOfType(json, typeof(IDictionary<string, object>));

var jsonObject = json as IDictionary<string, object>;
Assert.IsTrue(jsonObject.ContainsKey(user.ObjectId));
Assert.IsTrue(jsonObject.ContainsKey("role:test"));
var test = jsonObject[user.ObjectId] as Dictionary<string, object>;
Assert.AreEqual(1, test.Count);
}


[TestMethod]
[Description("Tests that ProcessAclData can handle invalid values for public key.")]
public void TestProcessAclData_HandlesInvalidDataForPublic() // Mock difficulty: 1
{
var aclData = new Dictionary<string, object> { { "*", 123 } };
var acl = new ParseACL(aclData);
Assert.IsFalse(acl.PublicReadAccess);
Assert.IsFalse(acl.PublicWriteAccess);
}
[TestMethod]
[Description("Tests if ACL skips keys that don't represent valid JSON data dictionaries")]
public void TestProcessAclData_SkipsInvalidKeys() // Mock difficulty: 1
{
var aclData = new Dictionary<string, object> {
{"userId", 123 }
};
var acl = new ParseACL(aclData);

Assert.IsFalse(acl.GetReadAccess("userId"));
Assert.IsFalse(acl.GetWriteAccess("userId"));
}
}
38 changes: 35 additions & 3 deletions Parse.Tests/AnalyticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,46 @@ namespace Parse.Tests;
[TestClass]
public class AnalyticsTests
{
#warning Skipped post-test-evaluation cleaning method may be needed.

// [TestCleanup]
// public void TearDown() => (Client.Services as ServiceHub).Reset();
private Mock<IParseAnalyticsController> _mockAnalyticsController;
private Mock<IParseCurrentUserController> _mockCurrentUserController;
private MutableServiceHub _hub;
private ParseClient _client;


[TestInitialize]
public void Initialize()
{
_mockAnalyticsController = new Mock<IParseAnalyticsController>();
_mockCurrentUserController = new Mock<IParseCurrentUserController>();

_mockCurrentUserController
.Setup(controller => controller.GetCurrentSessionTokenAsync(It.IsAny<IServiceHub>(), It.IsAny<CancellationToken>()))
.ReturnsAsync("sessionToken");


_hub = new MutableServiceHub
{
AnalyticsController = _mockAnalyticsController.Object,
CurrentUserController = _mockCurrentUserController.Object
};
_client = new ParseClient(new ServerConnectionData { Test = true }, _hub);
}

[TestCleanup]
public void Cleanup()
{
_mockAnalyticsController = null;
_mockCurrentUserController = null;
_hub = null;
_client = null;
}


[TestMethod]
public async Task TestTrackEvent()
{

// Arrange
var hub = new MutableServiceHub();
var client = new ParseClient(new ServerConnectionData { Test = true }, hub);
Expand Down
61 changes: 61 additions & 0 deletions Parse.Tests/AttributeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Parse.Infrastructure.Control;
using Parse.Infrastructure.Utilities;

namespace Parse.Tests;


[TestClass]
public class AttributeTests
{
[TestMethod]
[Description("Tests that PreserveAttribute can set its boolean properties correctly.")]
public void PreserveAttribute_SetPropertiesCorrectly()
{
var preserve = new PreserveAttribute { AllMembers = true, Conditional = true };
Assert.IsTrue(preserve.AllMembers);
Assert.IsTrue(preserve.Conditional);
preserve.AllMembers = false;
preserve.Conditional = false;
Assert.IsFalse(preserve.AllMembers);
Assert.IsFalse(preserve.Conditional);
}
[TestMethod]
[Description("Test LinkerSafe attribute and ensures there is not exceptions on constructor.")]
public void LinkerSafeAttribute_CanBeCreatedWithoutErrors()
{
var safe = new LinkerSafeAttribute();
Assert.IsNotNull(safe);
}
[TestMethod]
[Description("Tests that the PreserveWrapperTypes class has the Preserve attribute")]
public void PreserveWrapperTypes_HasPreserveAttribute()
{
var attribute = typeof(PreserveWrapperTypes).GetTypeInfo().GetCustomAttribute<PreserveAttribute>(true);
Assert.IsNotNull(attribute);
Assert.IsTrue(attribute.AllMembers);
}

[TestMethod]
[Description("Test that types exists in the AOTPreservations List with correct types.")]
public void PreserveWrapperTypes_HasCorrectlyAOTTypesRegistered()// Mock difficulty: 1
{
var property = typeof(PreserveWrapperTypes).GetTypeInfo().GetDeclaredProperty("AOTPreservations");
var list = property.GetValue(null) as List<object>;

Assert.IsNotNull(list);
Assert.IsTrue(list.Any(p => p.Equals(typeof(FlexibleListWrapper<object, object>))));
Assert.IsTrue(list.Any(p => p.Equals(typeof(FlexibleListWrapper<float, float>))));

Assert.IsTrue(list.Any(p => p.Equals(typeof(FlexibleDictionaryWrapper<object, object>))));
Assert.IsTrue(list.Any(p => p.Equals(typeof(FlexibleDictionaryWrapper<double, float>))));
}


}
Loading
Loading