FSTMockDatastore.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Remote/FSTDatastore.h"
  18. #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FSTMockDatastore : FSTDatastore
  21. /**
  22. * A count of the total number of requests sent to the watch stream since the beginning of the test
  23. * case.
  24. */
  25. @property(nonatomic) int watchStreamRequestCount;
  26. /**
  27. * A count of the total number of requests sent to the write stream since the beginning of the test
  28. * case.
  29. */
  30. @property(nonatomic) int writeStreamRequestCount;
  31. #pragma mark - Watch Stream manipulation.
  32. /** Injects an Added WatchChange containing the given targetIDs. */
  33. - (void)writeWatchTargetAddedWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs;
  34. /** Injects an Added WatchChange that marks the given targetIDs current. */
  35. - (void)writeWatchCurrentWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs
  36. snapshotVersion:
  37. (const firebase::firestore::model::SnapshotVersion &)snapshotVersion
  38. resumeToken:(NSData *)resumeToken;
  39. /** Injects a WatchChange as though it had come from the backend. */
  40. - (void)writeWatchChange:(FSTWatchChange *)change
  41. snapshotVersion:(const firebase::firestore::model::SnapshotVersion &)snap;
  42. /** Injects a stream failure as though it had come from the backend. */
  43. - (void)failWatchStreamWithError:(NSError *)error;
  44. /** Returns the set of active targets on the watch stream. */
  45. - (NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)activeTargets;
  46. /** Helper method to expose watch stream state to verify in tests. */
  47. - (BOOL)isWatchStreamOpen;
  48. #pragma mark - Write Stream manipulation.
  49. /**
  50. * Returns the next write that was "sent to the backend", failing if there are no queued sent
  51. */
  52. - (NSArray<FSTMutation *> *)nextSentWrite;
  53. /** Returns the number of writes that have been sent to the backend but not waited on yet. */
  54. - (int)writesSent;
  55. /** Injects a write ack as though it had come from the backend in response to a write. */
  56. - (void)ackWriteWithVersion:(const firebase::firestore::model::SnapshotVersion &)commitVersion
  57. mutationResults:(NSArray<FSTMutationResult *> *)results;
  58. /** Injects a stream failure as though it had come from the backend. */
  59. - (void)failWriteWithError:(NSError *_Nullable)error;
  60. @end
  61. NS_ASSUME_NONNULL_END