FSTMockDatastore.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "Firestore/core/src/firebase/firestore/model/types.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FSTMockDatastore : FSTDatastore
  22. /**
  23. * A count of the total number of requests sent to the watch stream since the beginning of the test
  24. * case.
  25. */
  26. @property(nonatomic) int watchStreamRequestCount;
  27. /**
  28. * A count of the total number of requests sent to the write stream since the beginning of the test
  29. * case.
  30. */
  31. @property(nonatomic) int writeStreamRequestCount;
  32. #pragma mark - Watch Stream manipulation.
  33. /** Injects an Added WatchChange containing the given targetIDs. */
  34. - (void)writeWatchTargetAddedWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs;
  35. /** Injects an Added WatchChange that marks the given targetIDs current. */
  36. - (void)writeWatchCurrentWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs
  37. snapshotVersion:
  38. (const firebase::firestore::model::SnapshotVersion &)snapshotVersion
  39. resumeToken:(NSData *)resumeToken;
  40. /** Injects a WatchChange as though it had come from the backend. */
  41. - (void)writeWatchChange:(FSTWatchChange *)change
  42. snapshotVersion:(const firebase::firestore::model::SnapshotVersion &)snap;
  43. /** Injects a stream failure as though it had come from the backend. */
  44. - (void)failWatchStreamWithError:(NSError *)error;
  45. /** Returns the set of active targets on the watch stream. */
  46. - (NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)activeTargets;
  47. /** Helper method to expose watch stream state to verify in tests. */
  48. - (BOOL)isWatchStreamOpen;
  49. #pragma mark - Write Stream manipulation.
  50. /**
  51. * Returns the next write that was "sent to the backend", failing if there are no queued sent
  52. */
  53. - (NSArray<FSTMutation *> *)nextSentWrite;
  54. /** Returns the number of writes that have been sent to the backend but not waited on yet. */
  55. - (int)writesSent;
  56. /** Injects a write ack as though it had come from the backend in response to a write. */
  57. - (void)ackWriteWithVersion:(const firebase::firestore::model::SnapshotVersion &)commitVersion
  58. mutationResults:(NSArray<FSTMutationResult *> *)results;
  59. /** Injects a stream failure as though it had come from the backend. */
  60. - (void)failWriteWithError:(NSError *_Nullable)error;
  61. @end
  62. NS_ASSUME_NONNULL_END