@@ -37,14 +37,6 @@ public LiveQueryMessageBuilderTests()
3737 Client . Publicize ( ) ;
3838 }
3939
40- [ TestMethod ]
41- public void TestConstructor ( )
42- {
43- ParseLiveQueryMessageBuilder builder = new ParseLiveQueryMessageBuilder ( ) ;
44-
45- Assert . IsNotNull ( builder , "Builder should not be null after construction." ) ;
46- }
47-
4840 [ TestMethod ]
4941 public async Task TestBuildConnectMessage ( )
5042 {
@@ -80,24 +72,13 @@ public void TestBuildUnsubscribeMessage()
8072 Assert . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => builder . BuildUnsubscribeMessage ( 0 ) ) ;
8173 }
8274
83- [ TestMethod ]
84- public async Task TestBuildSubscribeMessage ( )
75+ private void ValidateSubscriptionMessage ( IDictionary < string , object > message , string expectedOp , int requestId )
8576 {
86- int requestId = 2 ;
87- ParseLiveQuery < ParseObject > liveQuery = new ParseLiveQuery < ParseObject > (
88- Client . Services ,
89- "DummyClass" ,
90- new Dictionary < string , object > { { "foo" , "bar" } } ,
91- [ "foo" ] ,
92- [ "foo" ] ) ;
93- ParseLiveQueryMessageBuilder builder = new ParseLiveQueryMessageBuilder ( ) ;
94- IDictionary < string , object > message = await builder . BuildSubscribeMessage < ParseObject > ( requestId , liveQuery ) ;
95-
9677 Assert . IsNotNull ( message ) ;
9778 Assert . HasCount ( 4 , message ) ;
9879
9980 Assert . IsTrue ( message . ContainsKey ( "op" ) ) ;
100- Assert . AreEqual ( "subscribe" , message [ "op" ] ) ;
81+ Assert . AreEqual ( expectedOp , message [ "op" ] ) ;
10182
10283 Assert . IsTrue ( message . ContainsKey ( "requestId" ) ) ;
10384 Assert . AreEqual ( requestId , message [ "requestId" ] ) ;
@@ -127,6 +108,23 @@ public async Task TestBuildSubscribeMessage()
127108 Assert . HasCount ( 1 , ( string [ ] ) query [ "watch" ] , "The 'watch' array should contain exactly one element." ) ;
128109 Assert . AreEqual ( "foo" , ( ( string [ ] ) query [ "watch" ] ) [ 0 ] , "The 'watch' parameter should contain 'foo'." ) ;
129110
111+ }
112+
113+ [ TestMethod ]
114+ public async Task TestBuildSubscribeMessage ( )
115+ {
116+ int requestId = 2 ;
117+ ParseLiveQuery < ParseObject > liveQuery = new ParseLiveQuery < ParseObject > (
118+ Client . Services ,
119+ "DummyClass" ,
120+ new Dictionary < string , object > { { "foo" , "bar" } } ,
121+ [ "foo" ] ,
122+ [ "foo" ] ) ;
123+ ParseLiveQueryMessageBuilder builder = new ParseLiveQueryMessageBuilder ( ) ;
124+ IDictionary < string , object > message = await builder . BuildSubscribeMessage < ParseObject > ( requestId , liveQuery ) ;
125+
126+ ValidateSubscriptionMessage ( message , "subscribe" , requestId ) ;
127+
130128 await Assert . ThrowsExactlyAsync < ArgumentOutOfRangeException > ( async ( ) => await builder . BuildSubscribeMessage < ParseObject > ( 0 , liveQuery ) ) ;
131129 await Assert . ThrowsExactlyAsync < ArgumentNullException > ( async ( ) => await builder . BuildSubscribeMessage < ParseObject > ( requestId , null ) ) ;
132130 }
@@ -144,39 +142,7 @@ public async Task TestBuildUpdateSubscriptionMessage()
144142 ParseLiveQueryMessageBuilder builder = new ParseLiveQueryMessageBuilder ( ) ;
145143 IDictionary < string , object > message = await builder . BuildUpdateSubscriptionMessage < ParseObject > ( requestId , liveQuery ) ;
146144
147- Assert . IsNotNull ( message ) ;
148- Assert . HasCount ( 4 , message ) ;
149-
150- Assert . IsTrue ( message . ContainsKey ( "op" ) ) ;
151- Assert . AreEqual ( "update" , message [ "op" ] ) ;
152-
153- Assert . IsTrue ( message . ContainsKey ( "requestId" ) ) ;
154- Assert . AreEqual ( requestId , message [ "requestId" ] ) ;
155-
156- Assert . IsTrue ( message . ContainsKey ( "query" ) ) ;
157- Assert . IsInstanceOfType < IDictionary < string , object > > ( message [ "query" ] , "The 'query' value should be a Dictionary<string, object>." ) ;
158- Assert . HasCount ( 4 , ( IDictionary < string , object > ) message [ "query" ] ) ;
159- IDictionary < string , object > query = message [ "query" ] as IDictionary < string , object > ;
160-
161- Assert . IsTrue ( query . ContainsKey ( "className" ) , "The 'query' dictionary should contain the 'className' key." ) ;
162- Assert . AreEqual ( "DummyClass" , query [ "className" ] , "The 'className' property should be 'DummyClass'." ) ;
163-
164- Assert . IsTrue ( query . ContainsKey ( "where" ) , "The 'query' dictionary should contain the 'where' key." ) ;
165- Assert . IsInstanceOfType < IDictionary < string , object > > ( query [ "where" ] , "The 'where' property should be a Dictionary<string, object>." ) ;
166- IDictionary < string , object > where = ( IDictionary < string , object > ) query [ "where" ] ;
167- Assert . HasCount ( 1 , where , "The 'where' dictionary should contain exactly one key-value pair." ) ;
168- Assert . IsTrue ( where . ContainsKey ( "foo" ) , "The 'where' dictionary should contain the 'foo' key." ) ;
169- Assert . AreEqual ( "bar" , where [ "foo" ] , "The 'foo' property in 'where' should be 'bar'." ) ;
170-
171- Assert . IsTrue ( query . ContainsKey ( "keys" ) , "The 'query' dictionary should contain the 'keys' key." ) ;
172- Assert . IsInstanceOfType < string [ ] > ( query [ "keys" ] , "The 'keys' property should be a string array." ) ;
173- Assert . HasCount ( 1 , ( string [ ] ) query [ "keys" ] , "The 'keys' array should contain exactly one element." ) ;
174- Assert . AreEqual ( "foo" , ( ( string [ ] ) query [ "keys" ] ) [ 0 ] , "The 'keys' parameter should contain 'foo'." ) ;
175-
176- Assert . IsTrue ( query . ContainsKey ( "watch" ) , "The 'query' dictionary should contain the 'watch' key." ) ;
177- Assert . IsInstanceOfType < string [ ] > ( query [ "watch" ] , "The 'watch' property should be a string array." ) ;
178- Assert . HasCount ( 1 , ( string [ ] ) query [ "watch" ] , "The 'watch' array should contain exactly one element." ) ;
179- Assert . AreEqual ( "foo" , ( ( string [ ] ) query [ "watch" ] ) [ 0 ] , "The 'watch' parameter should contain 'foo'." ) ;
145+ ValidateSubscriptionMessage ( message , "update" , requestId ) ;
180146
181147 await Assert . ThrowsExactlyAsync < ArgumentOutOfRangeException > ( async ( ) => await builder . BuildUpdateSubscriptionMessage < ParseObject > ( 0 , liveQuery ) ) ;
182148 await Assert . ThrowsExactlyAsync < ArgumentNullException > ( async ( ) => await builder . BuildUpdateSubscriptionMessage < ParseObject > ( requestId , null ) ) ;
0 commit comments