1
1
using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
+ using Moq ;
2
3
using Parse ;
4
+ using Parse . Abstractions . Infrastructure . Control ;
5
+ using Parse . Abstractions . Infrastructure . Data ;
6
+ using Parse . Abstractions . Infrastructure . Execution ;
7
+ using Parse . Abstractions . Infrastructure ;
8
+ using Parse . Abstractions . Platform . Objects ;
3
9
using Parse . Infrastructure ;
4
10
using Parse . Infrastructure . Data ;
11
+ using Parse . Infrastructure . Execution ;
5
12
using Parse . Platform . Objects ;
13
+ using System ;
6
14
using System . Collections . Generic ;
7
15
using System . Diagnostics ;
16
+ using System . Net . Http ;
17
+ using System . Net ;
18
+ using System . Threading . Tasks ;
19
+ using System . Threading ;
8
20
9
21
[ TestClass ]
10
22
public class ObjectCoderTests
@@ -14,7 +26,7 @@ public void TestACLCoding()
14
26
{
15
27
// Prepare the mock service hub
16
28
var serviceHub = new ServiceHub ( ) ; // Mock or actual implementation depending on your setup
17
-
29
+
18
30
// Decode the ACL from a dictionary
19
31
MutableObjectState state = ( MutableObjectState ) ParseObjectCoder . Instance . Decode ( new Dictionary < string , object >
20
32
{
@@ -46,4 +58,65 @@ public void TestACLCoding()
46
58
Assert . IsFalse ( resultACL . GetWriteAccess ( "*" ) ) ;
47
59
Assert . IsTrue ( resultACL . GetReadAccess ( "*" ) ) ;
48
60
}
61
+
62
+ public async Task FetchAsync_FetchesCorrectly ( ) // Mock difficulty: 3
63
+ {
64
+ //Arrange
65
+ var mockCommandRunner = new Mock < IParseCommandRunner > ( ) ;
66
+ var mockDecoder = new Mock < IParseDataDecoder > ( ) ;
67
+ var mockServiceHub = new Mock < IServiceHub > ( ) ;
68
+ var mockState = new Mock < IObjectState > ( ) ;
69
+ mockState . Setup ( x => x . ClassName ) . Returns ( "TestClass" ) ;
70
+ mockState . Setup ( x => x . ObjectId ) . Returns ( "testId" ) ;
71
+
72
+ mockDecoder . Setup ( x => x . Decode ( It . IsAny < IDictionary < string , object > > ( ) , It . IsAny < IServiceHub > ( ) ) ) . Returns ( mockState . Object ) ;
73
+ mockCommandRunner . Setup ( c => c . RunCommandAsync ( It . IsAny < ParseCommand > ( ) , null , null , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( new Tuple < HttpStatusCode , IDictionary < string , object > > ( System . Net . HttpStatusCode . OK , new Dictionary < string , object > ( ) ) ) ;
74
+
75
+ ParseObjectController controller = new ParseObjectController ( mockCommandRunner . Object , mockDecoder . Object , new ServerConnectionData ( ) ) ;
76
+ //Act
77
+ IObjectState response = await controller . FetchAsync ( mockState . Object , "session" , mockServiceHub . Object ) ;
78
+
79
+ //Assert
80
+ mockCommandRunner . Verify ( x => x . RunCommandAsync ( It . IsAny < ParseCommand > ( ) , null , null , It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
81
+ Assert . AreEqual ( response , mockState . Object ) ;
82
+ }
83
+
84
+ [ TestMethod ]
85
+ [ Description ( "Tests DeleteAsync correctly deletes a ParseObject." ) ]
86
+ public async Task DeleteAsync_DeletesCorrectly ( ) // Mock difficulty: 3
87
+ {
88
+ //Arrange
89
+ var mockCommandRunner = new Mock < IParseCommandRunner > ( ) ;
90
+ var mockDecoder = new Mock < IParseDataDecoder > ( ) ;
91
+ var mockServiceHub = new Mock < IServiceHub > ( ) ;
92
+ var mockState = new Mock < IObjectState > ( ) ;
93
+ mockState . Setup ( x => x . ClassName ) . Returns ( "test" ) ;
94
+ mockState . Setup ( x => x . ObjectId ) . Returns ( "testId" ) ;
95
+
96
+ mockCommandRunner . Setup ( c => c . RunCommandAsync ( It . IsAny < ParseCommand > ( ) , null , null , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( new Tuple < HttpStatusCode , IDictionary < string , object > > ( System . Net . HttpStatusCode . OK , new Dictionary < string , object > ( ) ) ) ;
97
+ ParseObjectController controller = new ParseObjectController ( mockCommandRunner . Object , mockDecoder . Object , new ServerConnectionData ( ) ) ;
98
+
99
+ //Act
100
+ await controller . DeleteAsync ( mockState . Object , "session" ) ;
101
+
102
+ //Assert
103
+ mockCommandRunner . Verify ( x => x . RunCommandAsync ( It . IsAny < ParseCommand > ( ) , null , null , It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
104
+
105
+ }
106
+
107
+ [ TestMethod ]
108
+ [ Description ( "Tests that ExecuteBatchRequests correctly handles empty list." ) ]
109
+ public void ExecuteBatchRequests_EmptyList ( )
110
+ {
111
+ var mockCommandRunner = new Mock < IParseCommandRunner > ( ) ;
112
+ var mockDecoder = new Mock < IParseDataDecoder > ( ) ;
113
+ var mockServiceHub = new Mock < IServiceHub > ( ) ;
114
+ ParseObjectController controller = new ParseObjectController ( mockCommandRunner . Object , mockDecoder . Object , new ServerConnectionData ( ) ) ;
115
+ IList < ParseCommand > emptyList = new List < ParseCommand > ( ) ;
116
+
117
+ var task = controller . ExecuteBatchRequests ( emptyList , "session" , CancellationToken . None ) ;
118
+
119
+ Assert . AreEqual ( 0 , task . Count ) ;
120
+
121
+ }
49
122
}
0 commit comments