Skip to content

Commit c28a4ee

Browse files
authored
Merge branch 'master' into feat/remove-support-for-outdated-net
2 parents 6b35c0f + 1da9bc4 commit c28a4ee

31 files changed

+1251
-359
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [4.0.2](https://github.com/parse-community/Parse-SDK-dotNET/compare/4.0.1...4.0.2) (2025-02-02)
2+
3+
4+
### Bug Fixes
5+
6+
* `ParseObject` Relations not working ([#407](https://github.com/parse-community/Parse-SDK-dotNET/issues/407)) ([9af640a](https://github.com/parse-community/Parse-SDK-dotNET/commit/9af640adc69ea400f8f281e1134fcda776e641a2))
7+
8+
## [4.0.1](https://github.com/parse-community/Parse-SDK-dotNET/compare/4.0.0...4.0.1) (2024-12-24)
9+
10+
11+
### Bug Fixes
12+
13+
* `Parse.ParseUser.LogOutAsync` optimization ([#403](https://github.com/parse-community/Parse-SDK-dotNET/issues/403)) ([a0daac7](https://github.com/parse-community/Parse-SDK-dotNET/commit/a0daac7722311735ccbe59b33e0a8c3195d42433))
14+
115
# [4.0.0](https://github.com/parse-community/Parse-SDK-dotNET/compare/3.0.2...4.0.0) (2024-12-19)
216

317

Parse.Tests/AnalyticsTests.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,46 @@ namespace Parse.Tests;
1313
[TestClass]
1414
public class AnalyticsTests
1515
{
16-
#warning Skipped post-test-evaluation cleaning method may be needed.
1716

18-
// [TestCleanup]
19-
// public void TearDown() => (Client.Services as ServiceHub).Reset();
17+
private Mock<IParseAnalyticsController> _mockAnalyticsController;
18+
private Mock<IParseCurrentUserController> _mockCurrentUserController;
19+
private MutableServiceHub _hub;
20+
private ParseClient _client;
21+
22+
23+
[TestInitialize]
24+
public void Initialize()
25+
{
26+
_mockAnalyticsController = new Mock<IParseAnalyticsController>();
27+
_mockCurrentUserController = new Mock<IParseCurrentUserController>();
28+
29+
_mockCurrentUserController
30+
.Setup(controller => controller.GetCurrentSessionTokenAsync(It.IsAny<IServiceHub>(), It.IsAny<CancellationToken>()))
31+
.ReturnsAsync("sessionToken");
32+
33+
34+
_hub = new MutableServiceHub
35+
{
36+
AnalyticsController = _mockAnalyticsController.Object,
37+
CurrentUserController = _mockCurrentUserController.Object
38+
};
39+
_client = new ParseClient(new ServerConnectionData { Test = true }, _hub);
40+
}
41+
42+
[TestCleanup]
43+
public void Cleanup()
44+
{
45+
_mockAnalyticsController = null;
46+
_mockCurrentUserController = null;
47+
_hub = null;
48+
_client = null;
49+
}
50+
2051

2152
[TestMethod]
2253
public async Task TestTrackEvent()
2354
{
55+
2456
// Arrange
2557
var hub = new MutableServiceHub();
2658
var client = new ParseClient(new ServerConnectionData { Test = true }, hub);

Parse.Tests/CloudControllerTests.cs

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
using System;
23
using System.Collections.Generic;
34
using System.Net;
@@ -13,53 +14,75 @@
1314

1415
namespace Parse.Tests;
1516

16-
#warning Class refactoring requires completion.
17-
1817
[TestClass]
1918
public class CloudControllerTests
2019
{
21-
ParseClient Client { get; set; }
20+
private Mock<IParseCommandRunner> _mockRunner;
21+
private ParseCloudCodeController _cloudCodeController;
22+
private ParseClient Client { get; set; }
2223

2324
[TestInitialize]
24-
public void SetUp() => Client = new ParseClient(new ServerConnectionData { ApplicationID = "", Key = "", Test = true });
25+
public void SetUp()
26+
{
27+
Client = new ParseClient(new ServerConnectionData { ApplicationID = "", Key = "", Test = true });
28+
_mockRunner = new Mock<IParseCommandRunner>();
29+
}
30+
31+
[TestCleanup]
32+
public void Cleanup()
33+
{
34+
_mockRunner = null;
35+
_cloudCodeController = null;
36+
Client = null;
37+
}
38+
2539

2640
[TestMethod]
2741
public async Task TestEmptyCallFunction()
2842
{
29-
// Arrange: Create a mock runner that simulates a response with an accepted status but no data
30-
var mockRunner = CreateMockRunner(
31-
new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, null)
32-
);
43+
// Arrange: Setup mock runner and controller
44+
45+
_mockRunner.Setup(obj => obj.RunCommandAsync(
46+
It.IsAny<ParseCommand>(),
47+
It.IsAny<IProgress<IDataTransferLevel>>(),
48+
It.IsAny<IProgress<IDataTransferLevel>>(),
49+
It.IsAny<CancellationToken>()
50+
)).Returns(Task.FromResult(new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, null)));
51+
52+
_cloudCodeController = new ParseCloudCodeController(_mockRunner.Object, Client.Decoder);
3353

34-
var controller = new ParseCloudCodeController(mockRunner.Object, Client.Decoder);
3554

3655
// Act & Assert: Call the function and verify the task faults as expected
3756
try
3857
{
39-
await controller.CallFunctionAsync<string>("someFunction", null, null, Client, CancellationToken.None);
58+
await _cloudCodeController.CallFunctionAsync<string>("someFunction", null, null, Client, CancellationToken.None);
4059
Assert.Fail("Expected the task to fault, but it succeeded.");
4160
}
4261
catch (ParseFailureException ex)
4362
{
4463
Assert.AreEqual(ParseFailureException.ErrorCode.OtherCause, ex.Code);
4564
Assert.AreEqual("Cloud function returned no data.", ex.Message);
4665
}
47-
4866
}
4967

5068

5169
[TestMethod]
5270
public async Task TestCallFunction()
5371
{
54-
// Arrange: Create a mock runner with a predefined response
72+
// Arrange: Setup mock runner and controller with a response
5573
var responseDict = new Dictionary<string, object> { ["result"] = "gogo" };
56-
var response = new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, responseDict);
57-
var mockRunner = CreateMockRunner(response);
74+
_mockRunner.Setup(obj => obj.RunCommandAsync(
75+
It.IsAny<ParseCommand>(),
76+
It.IsAny<IProgress<IDataTransferLevel>>(),
77+
It.IsAny<IProgress<IDataTransferLevel>>(),
78+
It.IsAny<CancellationToken>()
79+
)).Returns(Task.FromResult(new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, responseDict)));
80+
81+
_cloudCodeController = new ParseCloudCodeController(_mockRunner.Object, Client.Decoder);
5882

59-
var cloudCodeController = new ParseCloudCodeController(mockRunner.Object, Client.Decoder);
6083

6184
// Act: Call the function and capture the result
62-
var result = await cloudCodeController.CallFunctionAsync<string>(
85+
var result = await _cloudCodeController.CallFunctionAsync<string>(
6386
"someFunction",
6487
parameters: null,
6588
sessionToken: null,
@@ -76,24 +99,29 @@ public async Task TestCallFunction()
7699
[TestMethod]
77100
public async Task TestCallFunctionWithComplexType()
78101
{
79-
// Arrange: Create a mock runner with a complex type response
102+
// Arrange: Setup mock runner and controller with a complex type response
80103
var complexResponse = new Dictionary<string, object>
81104
{
82105
{ "result", new Dictionary<string, object>
83-
{
84-
{ "fosco", "ben" },
85-
{ "list", new List<object> { 1, 2, 3 } }
86-
}
106+
{
107+
{ "fosco", "ben" },
108+
{ "list", new List<object> { 1, 2, 3 } }
109+
}
87110
}
88111
};
89-
var mockRunner = CreateMockRunner(
90-
new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, complexResponse)
91-
);
92112

93-
var cloudCodeController = new ParseCloudCodeController(mockRunner.Object, Client.Decoder);
113+
_mockRunner.Setup(obj => obj.RunCommandAsync(
114+
It.IsAny<ParseCommand>(),
115+
It.IsAny<IProgress<IDataTransferLevel>>(),
116+
It.IsAny<IProgress<IDataTransferLevel>>(),
117+
It.IsAny<CancellationToken>()
118+
)).Returns(Task.FromResult(new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, complexResponse)));
119+
120+
_cloudCodeController = new ParseCloudCodeController(_mockRunner.Object, Client.Decoder);
121+
94122

95123
// Act: Call the function with a complex return type
96-
var result = await cloudCodeController.CallFunctionAsync<IDictionary<string, object>>(
124+
var result = await _cloudCodeController.CallFunctionAsync<IDictionary<string, object>>(
97125
"someFunction",
98126
parameters: null,
99127
sessionToken: null,
@@ -107,25 +135,32 @@ public async Task TestCallFunctionWithComplexType()
107135
Assert.AreEqual("ben", result["fosco"]);
108136
Assert.IsInstanceOfType(result["list"], typeof(IList<object>));
109137
}
138+
110139
[TestMethod]
111140
public async Task TestCallFunctionWithWrongType()
112141
{
113142
// a mock runner with a response that doesn't match the expected type
143+
114144
var wrongTypeResponse = new Dictionary<string, object>
115-
{
116-
{ "result", "gogo" }
117-
};
118-
var mockRunner = CreateMockRunner(
119-
new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, wrongTypeResponse)
120-
);
145+
{
146+
{ "result", "gogo" }
147+
};
148+
149+
_mockRunner.Setup(obj => obj.RunCommandAsync(
150+
It.IsAny<ParseCommand>(),
151+
It.IsAny<IProgress<IDataTransferLevel>>(),
152+
It.IsAny<IProgress<IDataTransferLevel>>(),
153+
It.IsAny<CancellationToken>()
154+
)).Returns(Task.FromResult(new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, wrongTypeResponse)));
121155

122-
var cloudCodeController = new ParseCloudCodeController(mockRunner.Object, Client.Decoder);
156+
157+
_cloudCodeController = new ParseCloudCodeController(_mockRunner.Object, Client.Decoder);
123158

124159
// Act & Assert: Expect the call to fail with a ParseFailureException || This is fun!
125160

126161
await Assert.ThrowsExceptionAsync<ParseFailureException>(async () =>
127162
{
128-
await cloudCodeController.CallFunctionAsync<int>(
163+
await _cloudCodeController.CallFunctionAsync<int>(
129164
"someFunction",
130165
parameters: null,
131166
sessionToken: null,
@@ -134,20 +169,4 @@ await cloudCodeController.CallFunctionAsync<int>(
134169
);
135170
});
136171
}
137-
138-
139-
140-
private Mock<IParseCommandRunner> CreateMockRunner(Tuple<HttpStatusCode, IDictionary<string, object>> response)
141-
{
142-
var mockRunner = new Mock<IParseCommandRunner>();
143-
mockRunner.Setup(obj => obj.RunCommandAsync(
144-
It.IsAny<ParseCommand>(),
145-
It.IsAny<IProgress<IDataTransferLevel>>(),
146-
It.IsAny<IProgress<IDataTransferLevel>>(),
147-
It.IsAny<CancellationToken>()
148-
)).Returns(Task.FromResult(response));
149-
150-
return mockRunner;
151-
}
152-
153-
}
172+
}

0 commit comments

Comments
 (0)